Submission #989617

# Submission time Handle Problem Language Result Execution time Memory
989617 2024-05-28T12:17:35 Z AliHasanli Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
446 ms 262144 KB
#include <iostream>
using namespace std;
long long seg[10000000],L[10000000],R[10000000],lazy[10000000],ind=1;
void create(long long n,long long l,long long r)
{
    if(l<r && !L[n])L[n]=++ind;
    if(l<r && !R[n])R[n]=++ind;
}
void push(long long n,long long l,long long r)
{
    create(n,l,r);
    if(lazy[n])
    {
        seg[n]=r-l+1;
        if(l!=r){
        lazy[L[n]]=1;
        lazy[R[n]]=1;}
    }
    lazy[n]=0;
}
void update(long long n,long long l,long long r,long long ql,long long qr)
{
    push(n,l,r);
    if(l>r || ql>qr || ql>r || l>qr)return;
    if(ql<=l && r<=qr)
    {
        lazy[n]=1;
        push(n,l,r);
        return ;
    }
    if(L[n])update(L[n],l,(l+r)/2,ql,qr);if(R[n])update(R[n],(l+r)/2+1,r,ql,qr);
    seg[n]=seg[L[n]]+seg[R[n]];
}
long long query(long long n,long long l,long long r,long long ql,long long qr)
{
    long long ans=0;
    push(n,l,r);
    if(l>r || ql>qr || ql>r || l>qr)return 0;
    if(ql<=l && r<=qr)
        return seg[n];
    if(L[n])ans+=query(L[n],l,(l+r)/2,ql,qr);
    if(R[n])ans+=query(R[n],(l+r)/2+1,r,ql,qr);
    return ans;
}
int main()
{
    int m;
    cin>>m;
    long long ans=0;
    while(m--)
    {
        long long t,l,r;
        cin>>t>>l>>r;
        l+=ans;
        r+=ans;
        if(t==2) update(1,1,1e9,l,r);
        else cout<<query(1,1,1e9,l,r)<<endl,ans=query(1,1,1e9,l,r);
    }
    return 0;
}

Compilation message

apple.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
apple.cpp:31:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   31 |     if(L[n])update(L[n],l,(l+r)/2,ql,qr);if(R[n])update(R[n],(l+r)/2+1,r,ql,qr);
      |     ^~
apple.cpp:31:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   31 |     if(L[n])update(L[n],l,(l+r)/2,ql,qr);if(R[n])update(R[n],(l+r)/2+1,r,ql,qr);
      |                                          ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 20 ms 6012 KB Output is correct
5 Correct 24 ms 7252 KB Output is correct
6 Correct 24 ms 6996 KB Output is correct
7 Correct 24 ms 7144 KB Output is correct
8 Correct 158 ms 52444 KB Output is correct
9 Correct 371 ms 89124 KB Output is correct
10 Correct 330 ms 99924 KB Output is correct
11 Correct 326 ms 108372 KB Output is correct
12 Correct 346 ms 111952 KB Output is correct
13 Correct 328 ms 139072 KB Output is correct
14 Correct 334 ms 140628 KB Output is correct
15 Correct 429 ms 254548 KB Output is correct
16 Correct 418 ms 256904 KB Output is correct
17 Correct 327 ms 145432 KB Output is correct
18 Correct 386 ms 145488 KB Output is correct
19 Correct 423 ms 262144 KB Output is correct
20 Correct 446 ms 262144 KB Output is correct