#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
apple.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main(){
| ^~~~
apple.cpp: In function 'int main()':
apple.cpp:84:12: warning: unused variable 'v' [-Wunused-variable]
84 | int l,r,v;
| ^
apple.cpp:78:6: warning: unused variable 'a' [-Wunused-variable]
78 | int a[n+1];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
62908 KB |
Output is correct |
2 |
Correct |
28 ms |
62924 KB |
Output is correct |
3 |
Correct |
25 ms |
62788 KB |
Output is correct |
4 |
Correct |
39 ms |
63072 KB |
Output is correct |
5 |
Correct |
37 ms |
63044 KB |
Output is correct |
6 |
Correct |
36 ms |
63044 KB |
Output is correct |
7 |
Correct |
36 ms |
63020 KB |
Output is correct |
8 |
Incorrect |
53 ms |
63880 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |