Submission #653574

# Submission time Handle Problem Language Result Execution time Memory
653574 2022-10-27T10:30:01 Z amukkalir Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
444 ms 220632 KB
#include <bits/stdc++.h> 
using namespace std; 
 
const int nax = 1e9; 

struct node {
    node *l_child, *r_child; 
    int val; 
    node () {
        l_child=r_child=nullptr; 
        val=0; 
    }    
}; 
node *tree, *lazy; 

int m; 

void verif(node* &u) {
    if(!u) u=new node; 
}

void cek (node* &tr, node* &lz, int l, int r) {
    verif(tr); verif(lz); 
    if(lz->val==0)return;
    tr->val=r-l+1;
    if(l!=r) {
        verif(lz->l_child); lz->l_child->val = 1;
        verif(lz->r_child); lz->r_child->val = 1; 
    }
    lz->val=2; 
}
 
void upd (int fr, int to, node* &now=tree, node* &now_lazy=lazy, int l = 1, int r = nax) {    
    cek(now, now_lazy, l, r); 
    if(now_lazy->val==2)return; 
    
    if (fr <= l && r <= to) {
        now_lazy->val = 1; 
        cek(now, now_lazy, l, r); 
    } else if (r < fr || l > to) {
        return; 
    } else {
        int m = (l+r)>>1; 
        upd(fr, to, now->l_child, now_lazy->l_child, l, m); 
        upd(fr, to, now->r_child, now_lazy->r_child, m+1,r); 
        now->val = now->l_child->val + now->r_child->val; 
    }
}
 
int get (int fr, int to, node* &now=tree, node* &now_lazy=lazy, int l = 1, int r = nax) {
    cek(now, now_lazy, l, r);     
 
    if (fr <= l && r <= to) return now->val; 
    else if (r < fr || l > to) return 0; 
    else {
        int m = (l+r)>>1; 
        return get(fr, to, now->l_child, now_lazy->l_child, l, m) + get(fr, to, now->r_child, now_lazy->r_child, m+1, r); 
    }
}
 
signed main() {    
    verif(tree); verif(lazy); 
    
    scanf("%d", &m); 
    int c = 0; 
    while (m--) {
        int d, x, y; 
        scanf("%d %d %d", &d, &x, &y); 
        x += c; y += c; 
 
        if (d == 1) {            
            int ans = get(x, y);
            c = ans;  
            printf("%d\n",ans);
        } else {
            upd(x,y); 
        }        
    }
}
 
/*
*/

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
apple.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d %d %d", &d, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 21 ms 5324 KB Output is correct
5 Correct 18 ms 6512 KB Output is correct
6 Correct 18 ms 6116 KB Output is correct
7 Correct 17 ms 6484 KB Output is correct
8 Correct 132 ms 49428 KB Output is correct
9 Correct 248 ms 85884 KB Output is correct
10 Correct 289 ms 94196 KB Output is correct
11 Correct 282 ms 100760 KB Output is correct
12 Correct 276 ms 103560 KB Output is correct
13 Correct 274 ms 115112 KB Output is correct
14 Correct 256 ms 114520 KB Output is correct
15 Correct 429 ms 213356 KB Output is correct
16 Correct 385 ms 215532 KB Output is correct
17 Correct 276 ms 120268 KB Output is correct
18 Correct 253 ms 120364 KB Output is correct
19 Correct 420 ms 220596 KB Output is correct
20 Correct 444 ms 220632 KB Output is correct