# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
523454 | tmn2005 | Monkey and Apple-trees (IZhO12_apple) | C++17 | 378 ms | 262148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define vec vector
#define ret return
#define ins insert
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
const int N = 1e7+12, INF = 1e9, mod = 1e9+7;
int lz[N*4], sum[N*4];
void push(int p, int len) {
if (lz[p] != -1) {
sum[p] = len * lz[p];
if (len > 1) {
lz[2 * p] = lz[2 * p + 1] = lz[p];
}
lz[p] = -1;
}
}
void update(int p, int l, int r, int x, int y) {
push(p, r - l + 1);
if (l > y || r < x) return;
if (l >= x && r <= y) {
lz[p] = 1;
push(p, r - l + 1);
return;
}
int m = (l + r) / 2;
update(2 * p, l, m, x, y);
update(2 * p + 1, m + 1, r, x, y);
sum[p] = sum[2 * p] + sum[2 * p + 1];
}
int get(int p, int l, int r, int x, int y) {
push(p, r - l + 1);
if (l > y || r < x) return 0;
if (l >= x && r <= y) {
return sum[p];
}
int m = (l + r) / 2;
return get(2 * p, l, m, x, y) + get(2 * p + 1, m + 1, r, x, y);
}
main(){
int n;
cin>>n;
memset(lz, -1, sizeof lz);
int c = 0;
for(int i=1; i<=n; i++){
int z, x, y;
cin>>z>>x>>y;
if(z == 2){
update(1, 1, 10000000, x + c, y + c);
}
else{
int ans = get(1, 1, 10000000, x + c, y + c);
cout<<ans<<"\n";
c = ans;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |