Submission #89365

# Submission time Handle Problem Language Result Execution time Memory
89365 2018-12-12T10:31:13 Z Badral Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
2 ms 376 KB
#include<bits/stdc++.h>

using namespace std;
map<int, int> lazy;
map<int, int> tree;
void nemeh(int node, int L, int R, int l, int r) {
	if(lazy[node]) {
		tree[node] += (R-L+1)*lazy[node];
		if(L != R) {
			lazy[node<<1|1]++;
			lazy[node<<1]++;
		}
		lazy[node] = 0;
	}
	if(l > R || r < L || L > R) {
		return;
	}
	if(L >= l && r >= R) {
		tree[node] += (R-L+1);
		if (L != R) {
            lazy[node*2 + 1]++; 
            lazy[node*2 + 2]++; 
        }
        return; 
	}
	int mid = (L+R)>>1;
	nemeh(node<<1, L, mid, l, r);
	nemeh(node<<1|1, mid+1, R, l, r);
	tree[node] = tree[node<<1] + tree[node<<1|1];
}
int ol(int node, int L, int R, int l, int r) {
	if(lazy[node]) {
		tree[node] += (R-L+1)*lazy[node];
		if(L != R) {
			lazy[node<<1|1]++;
			lazy[node<<1]++;
		}
		lazy[node] = 0;
	}
	if(l > R || r < L || L > R) {
		return 0;
	}
	if(L <= l && R >= r) {
		return tree[node];
	}
	int mid = (L+R)>>1;
	return ol(node<<1, L, mid, l, r) + ol(node<<1|1, mid+1, R, l, r);
}
int main() {
	int n = 10000000;
	int t;
	cin >>t;
	while(t--) {
		int x, l, r;
		cin >>x >>l >>r;
		if(x == 2) {
			nemeh(1, 1, n, l, r);
		}
		else {
			cout<<ol(1, 1, n, l, r)<<"\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -