Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <set>
- #include <map>
- #define NMAX 100005
- using namespace std;
- struct qu{
- int st, dr, where;
- }q[NMAX];
- int Arb[4 * NMAX + 5], lazy[4 * NMAX + 5], stop[NMAX], T[NMAX], D[NMAX];
- set<int> s;
- map<int, int> mp;
- void propag(int nod){
- if(lazy[nod] != 0){
- Arb[2 * nod] += lazy[nod];
- Arb[2 * nod + 1] += lazy[nod];
- lazy[2 * nod] += lazy[nod];
- lazy[2 * nod + 1] += lazy[nod];
- lazy[nod] = 0;
- }
- }
- void Update(int st, int dr, int a, int b, int val, int nod){
- if(a <= st && dr <= b){
- Arb[nod] += lazy[nod];
- lazy[nod] += val;
- return;
- }
- propag(nod);
- int mij = (st + dr) / 2;
- if(a <= mij) Update(st, mij, a, b, val, 2 * nod);
- if(b > mij) Update(mij + 1, dr, a, b, val, 2 * nod + 1);
- Arb[nod] = min(Arb[2 * nod], Arb[2 * nod + 1]);
- }
- int Query(int st, int dr, int a, int b, int nod){
- if(a <= st && dr <= b)
- return Arb[nod];
- propag(nod);
- int rez1 = (1 << 30), rez2 = (1 << 30);
- int mij = (st + dr) / 2;
- if(a <= mij) rez1 = Query(st, mij, a, b, 2 * nod);
- if(b > mij) rez2 = Query(mij + 1, dr, a, b, 2 * nod + 1);
- return min(rez1, rez2);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, m;
- cin >> n >> m;
- int pw2 = log2(n) + 1;
- int N = (1 << pw2);
- for(int i = 1; i <= n; ++i){
- cin >> T[i] >> D[i];
- s.insert(D[i]);
- }
- int nr = 0;
- for(auto it: s)
- mp[it] = ++nr;
- for(int i = 1; i <= n; ++i)
- Arb[N + i - 1] = mp[D[i]];
- for(int i = N - 1; i >= 1; --i)
- Arb[i] = min(Arb[2 * i], Arb[2 * i + 1]);
- for(int i = 1; i <= m; ++i)
- cin >> q[i].st >> q[i].dr;
- int j = 1;
- for(int i = 1; i <= n; ++i){
- while(j <= n){
- Update(1, N, mp[D[j]], N, -T[j], 1);
- if(Query(1, N, 1, N, 1) <= 0)
- break;
- ++j;
- }
- stop[i] = j - 1;
- Update(1, N, mp[D[i]], N, T[i], 1);
- }
- for(int i = 1; i <= m; ++i){
- if(stop[q[i].st] >= q[i].dr)
- cout << 1 << '\n';
- else cout << 0 << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement