Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <string>
- #include <string.h>
- #include <vector>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- using namespace std;
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pb push_back
- #define mp make_pair
- #define y0 isdnfviu
- #define y1 asinhiv
- #define fst first
- #define snd second
- #define count sdifnsugh
- const int maxn = 100003;
- int nxt[maxn], pos[maxn];
- bool used[maxn];
- stack < pair < char, int > > st;
- vector < int > v[maxn];
- int main()
- {
- string s;
- cin >> s;
- int n = s.length();
- for (int i = 0; i < n; i++)
- {
- if (!st.empty())
- {
- if (st.top().fst - 'A' == s[i] - 'a')
- {
- nxt[st.top().snd] = i + 1;
- st.pop();
- continue;
- }
- }
- st.push(mp(s[i], i + 1));
- }
- int kol = 0;
- for (int i = 1; i <= n; i++)
- if (!used[i] && nxt[i] != 0)
- {
- kol++;
- int pr = i;
- while (nxt[pr] != 0)
- {
- used[pr] = true;
- pos[pr] = kol;
- v[kol].pb(nxt[pr]);
- pr = nxt[pr] + 1;
- }
- }
- int m;
- cin >> m;
- while (m--)
- {
- int l, r;
- cin >> l >> r;
- if (binary_search(v[pos[l]].begin(), v[pos[l]].end(), r))
- cout << 1;
- else
- cout << 0;
- }
- //cin >> n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement