Submission #1077315

# Submission time Handle Problem Language Result Execution time Memory
1077315 2024-08-27T05:13:02 Z vjudge1 Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
33 ms 3164 KB
#include<bits/stdc++.h>
using namespace std;
#define N 1<<23
int sz[N],cnt[N],ch[N][2],CC,RT;
int newnode(int s){
    return sz[++CC]=s,CC;
}
void setripe(int &i,int l,int r,int ll,int rr){
    if(!i) i=newnode(r-l+1);
    if(ll>r||l>rr) return;
    if(cnt[i]==sz[i])return;
    if(ll<=l&&r<=rr)
        return void(cnt[i]=sz[i]);
    setripe(ch[i][0],l,l+r>>1,ll,rr);
    setripe(ch[i][1],l+r+2>>1,r,ll,rr);
    cnt[i]=cnt[ch[i][0]]+cnt[ch[i][1]];
}
int qry(int i,int l,int r,int ll,int rr){
    if(!i) return 0;
    if(ll>r||l>rr) return 0;
    if(ll<=l&&r<=rr) return cnt[i];
    if(cnt[i]==sz[i]) return(min(r,rr)-max(l,ll)+1);
    return qry(ch[i][0],l,l+r>>1,ll,rr)+
        qry(ch[i][1],l+r+2>>1,r,ll,rr);
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int q,la=0;
    cin>>q;
    while(q--){
        int a,b,c;
        cin>>a>>b>>c;
        b+=la,c+=la;
        if(a==2)
            setripe(RT,1,1e9,b,c);
        else cout<<(la=qry(RT,1,1e9,b,c))<<'\n';
    }
}

Compilation message

apple.cpp: In function 'void setripe(int&, int, int, int, int)':
apple.cpp:14:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |     setripe(ch[i][0],l,l+r>>1,ll,rr);
      |                        ~^~
apple.cpp:15:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |     setripe(ch[i][1],l+r+2>>1,r,ll,rr);
      |                      ~~~^~
apple.cpp: In function 'int qry(int, int, int, int, int)':
apple.cpp:23:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |     return qry(ch[i][0],l,l+r>>1,ll,rr)+
      |                           ~^~
apple.cpp:24:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         qry(ch[i][1],l+r+2>>1,r,ll,rr);
      |                      ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 14 ms 1376 KB Output is correct
9 Correct 27 ms 2584 KB Output is correct
10 Correct 31 ms 2384 KB Output is correct
11 Correct 27 ms 2640 KB Output is correct
12 Correct 28 ms 2500 KB Output is correct
13 Correct 33 ms 2948 KB Output is correct
14 Correct 31 ms 2900 KB Output is correct
15 Correct 25 ms 2968 KB Output is correct
16 Correct 28 ms 3164 KB Output is correct
17 Correct 29 ms 2904 KB Output is correct
18 Correct 25 ms 2904 KB Output is correct
19 Correct 26 ms 3152 KB Output is correct
20 Correct 26 ms 2896 KB Output is correct