Advertisement
Guest User

Untitled

a guest
Nov 26th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.17 KB | None | 0 0
  1. import std.stdio, std.string, std.conv;
  2. import std.algorithm, std.array, std.bigint, std.math, std.range;
  3. import core.thread;
  4.  
  5. //  Input
  6. string[] tokens;
  7. int tokenId = 0;
  8. string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }
  9.  
  10. int readInt() { return to!int(readToken); }
  11. long readLong() { return to!long(readToken); }
  12. real readReal() { return to!real(readToken); }
  13.  
  14. //  chmin/chmax
  15. void chmin(T)(ref T t, T f) { if (t > f) t = f; }
  16. void chmax(T)(ref T t, T f) { if (t < f) t = f; }
  17.  
  18. immutable int MAXN = 100005;
  19.  
  20. int M;
  21. string S;
  22.  
  23. int[100005][5] dp;
  24.  
  25. void main () {
  26.     S = readToken();
  27.     M = readInt();
  28.  
  29.     int A, B;
  30.  
  31.     foreach(int i; 0 .. to!int(S.length)) {
  32.         dp[to!int(S[i] - 'x')][i + 1] += 1;
  33.  
  34.         foreach(int j; 0 .. 3) {
  35.             dp[j][i +    1] += dp[j][i];
  36.         }
  37.     }
  38.  
  39.     foreach (int i; 0 .. M) {
  40.         A = readInt();
  41.         B = readInt();
  42.  
  43.         if (B - A < 2) {
  44.             writeln("YES");
  45.         } else {
  46.             int[3] buff;
  47.  
  48.             foreach(int j; 0 .. 3) {               
  49.                 buff[j] = dp[j][B] - dp[j][A - 1];
  50.             }
  51.  
  52.             buff.sort;
  53.  
  54.             if (buff[2] <= buff[0] + 1) {
  55.                 writeln("YES");
  56.             } else {
  57.                 writeln("NO");
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement