Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <string.h>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12.  
  13. using namespace std;
  14.  
  15. #define ll long long
  16. #define ld long double
  17. #define ull unsigned long long
  18. #define pb push_back
  19. #define mp make_pair
  20. #define y0 isdnfviu
  21. #define y1 asinhiv
  22. #define fst first
  23. #define snd second
  24. #define count sdifnsugh
  25.  
  26. const int maxn = 100003;
  27. int nxt[maxn], pos[maxn];
  28. bool used[maxn];
  29.  
  30. stack < pair < char, int > > st;
  31. vector < int > v[maxn];
  32.  
  33. int main()
  34. {
  35.     string s;
  36.     cin >> s;
  37.     int n = s.length();
  38.     for (int i = 0; i < n; i++)
  39.     {
  40.         if (!st.empty())
  41.         {
  42.             if (st.top().fst - 'A' == s[i] - 'a')
  43.             {
  44.                 nxt[st.top().snd] = i + 1;
  45.                 st.pop();
  46.                 continue;
  47.             }
  48.         }
  49.         st.push(mp(s[i], i + 1));
  50.     }
  51.     int kol = 0;
  52.     for (int i = 1; i <= n; i++)
  53.         if (!used[i] && nxt[i] != 0)
  54.         {
  55.             kol++;
  56.             int pr = i;
  57.             while (nxt[pr] != 0)
  58.             {
  59.                 used[pr] = true;
  60.                 pos[pr] = kol;
  61.                 v[kol].pb(nxt[pr]);
  62.                 pr = nxt[pr] + 1;
  63.             }
  64.         }
  65.     int m;
  66.     cin >> m;
  67.     while (m--)
  68.     {
  69.         int l, r;
  70.         cin >> l >> r;
  71.         if (binary_search(v[pos[l]].begin(), v[pos[l]].end(), r))
  72.             cout << 1;
  73.         else
  74.             cout << 0;
  75.     }
  76.     //cin >> n;
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement