#include <bits/stdc++.h>
using namespace std;
struct node{
node* l;
node* r;
int val;
int lz;
node():l(NULL),r(NULL),val(0),lz(-1){}
};
void push(node* v,int s,int e){
if(v->lz!=-1){
v->val = (e-s+1)*(v->lz);
if(s!=e){
if(v->l == NULL){
v->l = new node();
v->r = new node();
}
v->l->lz = v->lz;
v->r->lz = v->lz;
}
}
v->lz = -1;
}
void update(node* v,int s,int e,int l,int r,int val){
push(v,s,e);
if(l>r) return;
if(s == l && e == r){
v->lz = val;
return;
}
int m = (s+e)/2;
if(v->l == NULL){
v->l = new node();
v->r = new node();
}
update(v->l,s,m,l,min(m,r),val);
update(v->r,m+1,e,max(l,m+1),r,val);
push(v->l,s,m);
push(v->r,m+1,e);
v->val = v->l->val+v->r->val;
}
int get(node* v,int s,int e,int l,int r){
if(v == NULL) return 0;
push(v,s,e);
if(l>r) return 0;
if(s == l && e == r) return v->val;
int m = (s+e)/2;
return get(v->l,s,m,l,min(m,r))+
get(v->r,m+1,e,max(l,m+1),r);
}
int main(){
node* root;
root = new node();
int m;
scanf("%d",&m);
int C = 0;
while(m--){
int d,x,y;
scanf("%d%d%d",&d,&x,&y);
if(d == 1){
int ans = get(root,1,1000*1000*1000,x+C,y+C);
C = ans;
printf("%d\n",ans);
}
else{
update(root,1,1000*1000*1000,x+C,y+C,1);
}
}
return 0;
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&m);
~~~~~^~~~~~~~~
apple.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&d,&x,&y);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
528 KB |
Output is correct |
4 |
Correct |
109 ms |
5996 KB |
Output is correct |
5 |
Correct |
32 ms |
7196 KB |
Output is correct |
6 |
Correct |
32 ms |
7196 KB |
Output is correct |
7 |
Correct |
29 ms |
7256 KB |
Output is correct |
8 |
Correct |
259 ms |
51836 KB |
Output is correct |
9 |
Correct |
620 ms |
87800 KB |
Output is correct |
10 |
Correct |
524 ms |
98456 KB |
Output is correct |
11 |
Correct |
577 ms |
106828 KB |
Output is correct |
12 |
Correct |
618 ms |
110668 KB |
Output is correct |
13 |
Correct |
559 ms |
137612 KB |
Output is correct |
14 |
Correct |
562 ms |
138680 KB |
Output is correct |
15 |
Correct |
939 ms |
252716 KB |
Output is correct |
16 |
Correct |
927 ms |
254812 KB |
Output is correct |
17 |
Correct |
587 ms |
254812 KB |
Output is correct |
18 |
Correct |
572 ms |
254812 KB |
Output is correct |
19 |
Runtime error |
973 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
20 |
Halted |
0 ms |
0 KB |
- |