#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;
struct node{
int l, r;
int sum;
int pus;
node *bala1, *bala2;
node(int L, int R){
bala1 = bala2 = NULL;
sum=0;
pus=-INF;
l = L;
r = R;
}
};
void push(node *root){
if (root->pus == -INF)ret;
if (root->bala1 != NULL) root->bala1->pus = root->pus;
if (root->bala2 != NULL) root->bala2->pus = root->pus;
root->sum = (root->r - root->l + 1)*root->pus;
root->pus=-INF;
}
void update(node *root, int ql, int qr, int x){
int mid = (root->l + root->r)>>1;
if(root->bala1 == NULL)root->bala1 = new node(root->l,mid);
if(root->bala2 == NULL)root->bala2 = new node(mid+1,root->r);
push(root);
if(root->l > qr || root->r < ql)return;
if(root->l >= ql && root->r <= qr){
root->pus = x;
push(root);
return;
}
update(root->bala1,ql,qr,x);
update(root->bala2,ql,qr,x);
root-> sum = root->bala1->sum + root->bala2->sum;
}
int get_ans(node *root,int ql,int qr){
if (ql > root->r || qr < root->l)ret 0;
int mid = (root->l + root->r)>>1;
if(root->bala1 == NULL)root->bala1 = new node(root->l,mid);
if(root->bala2 == NULL)root->bala2 = new node(mid+1,root->r);
push(root);
if (qr >= root->r && root->l >= ql)ret root->sum;
ret get_ans(root->bala1,ql,qr) + get_ans(root->bala2,ql,qr);
}
main(){
int n,m,i,ans=0;
scan1(m)
node *root = new node(1, 1e9+1);
while (m--){
int l, r;
char c;
cin>>c>>l>>r;
if (c == '2'){
update(root,l+ans,r+ans,1);
}
else {
ans = get_ans(root,l+ans,r+ans);
cout <<ans<<"\n";
}
}
}
Compilation message
apple.cpp:73:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main(){
| ^
apple.cpp: In function 'int main()':
apple.cpp:74:9: warning: unused variable 'n' [-Wunused-variable]
74 | int n,m,i,ans=0;
| ^
apple.cpp:74:13: warning: unused variable 'i' [-Wunused-variable]
74 | int n,m,i,ans=0;
| ^
apple.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
apple.cpp:75:5: note: in expansion of macro 'scan1'
75 | scan1(m)
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
38 ms |
11244 KB |
Output is correct |
5 |
Correct |
45 ms |
13548 KB |
Output is correct |
6 |
Correct |
45 ms |
13036 KB |
Output is correct |
7 |
Correct |
45 ms |
13420 KB |
Output is correct |
8 |
Correct |
321 ms |
103020 KB |
Output is correct |
9 |
Correct |
637 ms |
178540 KB |
Output is correct |
10 |
Correct |
665 ms |
197484 KB |
Output is correct |
11 |
Correct |
696 ms |
212124 KB |
Output is correct |
12 |
Correct |
686 ms |
218388 KB |
Output is correct |
13 |
Correct |
647 ms |
252908 KB |
Output is correct |
14 |
Correct |
654 ms |
255784 KB |
Output is correct |
15 |
Runtime error |
521 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Halted |
0 ms |
0 KB |
- |