Submission #89364

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

using namespace std;
int lazy[40000001];
int tree[50000001];
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);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -