# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
524868 | Aktan | Monkey and Apple-trees (IZhO12_apple) | C++14 | 53 ms | 63880 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;
struct node {
int sum;
node(int x=0) : sum(x){ }
};
node operator + (node a,node b){
node c=(a.sum+b.sum);
return c;
}
const int N=1e6;
node t[N*4];
int lz[4*N];
void push(int p,int len){
if (lz[p] == -1) return;
t[p].sum=len*lz[p];
if(len>1){
lz[p*2]=lz[p];
lz[p*2+1]=lz[p];
}
lz[p]=-1;
}
void modify(int p,int l,int r,int x,node v){
push(p,r-l+1);
if(l==r){
t[p]=v;
return;
}
int m=(l+r)/2;
if(x<=m){
modify(p*2,l,m,x,v);
}
else{
modify(p*2+1,m+1,r,x,v);
}
t[p]=t[p*2]+t[p*2+1];
}
void update(int p,int l,int r,int x,int y,int v){
push(p,r-l+1);
if(x>r || y<l){
return;
}
if(x<=l && y>=r){
lz[p]=v;
push(p,r-l+1);
return;
}
int m=(l+r)/2;
update(p*2,l,m,x,y,v);
update(p*2+1,m+1,r,x,y,v);
t[p]= t[p*2]+t[p*2+1];
}
node query(int p,int l,int r,int x,int y){
push(p,r-l+1);
if(x>r || y<l){
return node();
}
if(x<=l && y>=r){
return t[p];
}
int m=(r+l)/2;
return query(p*2,l,m,x,y) + query(p*2+1,m+1,r,x,y);
}
main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
memset(lz, -1, sizeof lz);
int n,q;
cin >> q;
int a[n+1];
int c=0;
while(q--){
int type;
cin >> type;
if(type==2){
int l,r,v;
cin >> l >> r;
update(1,1,1e6,l+c,r+c,1);
}
else{
int l,r;
cin >> l >> r;
c=query(1,1,1e6,l+c,r+c).sum;
cout << c << "\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |