Submission #885949

# Submission time Handle Problem Language Result Execution time Memory
885949 2023-12-11T07:51:22 Z dosts Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
85 ms 1012 KB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
//#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define pb push_back
const int N = 2e5+1;
 
struct Node {
	Node* c[2];
	int sum = 0,l,r;
	bool lazy = 0;
	inline Node(int a,int b) {
		c[0] = c[1] = NULL;
		l = a;
		r = b;
	}
	inline void apply() {
		if (lazy) sum = r-l+1;
	}
	inline void push() {
		if ((l^r)&&!c[0]) {
			int m = (l+r) >> 1;
			c[0] = new Node(l,m);
			c[1] = new Node(m+1,r);
		}
	}
 
	inline void upd(int L,int R) {
		apply();
		if (lazy) return;
		if (l > R ||  r < L) return;
		if (l >= L && r <= R) {
			lazy = 1;
			apply();
			return;
		}
		push();
		c[0]->upd(L,R),c[1]->upd(L,R);
		sum = c[0]->sum+c[1]->sum;
	}
 
	inline int query(int L,int R) {
		apply();
		if (l > R || r < L) return 0;
		if (l >= L && r <= R) return sum;
		if(lazy){
			if (L >= l && R <= r) return R-L+1;
			if (L <= l) return R-l+1;
			return r-L+1;
		}
		push();
		return c[0]->query(L,R)+c[1]->query(L,R);
	}
 
};
 
void solve() {
	int q;
	cin >> q;
	int c = 0;
	Node* root = new Node(1,1e9);
	while (q--) {
		int t,l,r;
		cin >> t >> l >> r;
		if (t == 1) {
			c = root->query(l+c,r+c);
			cout << c << endl;
		}
		else root->upd(l+c,r+c);
	}
}
    
                  
                             
signed main() { 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Local
  freopen("in","r",stdin);
  freopen("out","w",stdout); 
  #endif
  int t = 1;
  //cin >> t;
	F(i,t) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 508 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 9 ms 348 KB Output is correct
7 Correct 9 ms 348 KB Output is correct
8 Correct 42 ms 580 KB Output is correct
9 Correct 84 ms 744 KB Output is correct
10 Correct 83 ms 756 KB Output is correct
11 Correct 83 ms 848 KB Output is correct
12 Correct 83 ms 820 KB Output is correct
13 Correct 85 ms 848 KB Output is correct
14 Correct 83 ms 852 KB Output is correct
15 Correct 81 ms 852 KB Output is correct
16 Correct 82 ms 852 KB Output is correct
17 Correct 76 ms 848 KB Output is correct
18 Correct 78 ms 872 KB Output is correct
19 Correct 81 ms 1012 KB Output is correct
20 Correct 85 ms 832 KB Output is correct