Submission #1088794

# Submission time Handle Problem Language Result Execution time Memory
1088794 2024-09-15T05:53:44 Z rayan_bd Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
409 ms 262144 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroint-loops")
#pragma GCC optimization("Ofast")
 

const int mxN = 1e9+100;
 
struct Node {
    int val = 0, lazy = 0;
    Node* left = NULL;
    Node* right = NULL;
};
 
typedef Node* root;
root R = new Node;
 
void push(root& nd, int l, int r) {
    if (!nd){
        nd=new Node;
    }
    if(nd->lazy==0) return;


    nd->val = (r - l + 1) * nd->lazy;
    if (r - l >= 1) {
        if (nd->left == NULL) nd->left = new Node;
        if (nd->right == NULL) nd->right = new Node;
        nd->left->lazy = nd->lazy;
        nd->right->lazy = nd->lazy;
    }
    nd->lazy = 0; 
}
 
void update(root& nd, int start, int end, int l, int r) {
    push(nd, start, end);
    if (start > r || end < l) return;
    if (start >= l && end <= r) {
        nd->lazy = 1; 
        push(nd, start, end); 
        return;
    }
    int mid = start + (end - start) / 2;
    update(nd->left, start, mid, l, r);
    update(nd->right, mid + 1, end, l, r);
    nd->val = (nd->left ? nd->left->val : 0) + (nd->right ? nd->right->val : 0);
}
 
int qry(root& nd, int start, int end, int l, int r) {
    push(nd, start, end);
    if (start > r || end < l) return 0;
    if (start >= l && end <= r) return nd->val;
    int mid = start + (end - start) / 2;
    return qry(nd->left, start, mid, l, r) + qry(nd->right, mid + 1, end, l, r);
}
 

signed main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
 
    int n,prev=0,p2=1,e,l,r;cin>>n;

    while(n--){
        cin>>e>>l>>r;
        l+=prev;
        r+=prev;
        if(e==1){
            prev=qry(R,1,mxN,l,r);
            cout<<prev<<'\n';
        }else if(e==2){
            update(R,1,mxN,l,r);
        }
    }
 
    return 0;
}

Compilation message

apple.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("O3")
      | 
apple.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    7 | #pragma GCC optimization ("unroint-loops")
      | 
apple.cpp:8: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    8 | #pragma GCC optimization("Ofast")
      | 
apple.cpp: In function 'int main()':
apple.cpp:68:18: warning: unused variable 'p2' [-Wunused-variable]
   68 |     int n,prev=0,p2=1,e,l,r;cin>>n;
      |                  ^~
# 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 0 ms 348 KB Output is correct
4 Correct 11 ms 5980 KB Output is correct
5 Correct 15 ms 7004 KB Output is correct
6 Correct 15 ms 6748 KB Output is correct
7 Correct 14 ms 7092 KB Output is correct
8 Correct 106 ms 51440 KB Output is correct
9 Correct 230 ms 87644 KB Output is correct
10 Correct 222 ms 98212 KB Output is correct
11 Correct 233 ms 106580 KB Output is correct
12 Correct 260 ms 110192 KB Output is correct
13 Correct 258 ms 136964 KB Output is correct
14 Correct 234 ms 138452 KB Output is correct
15 Correct 385 ms 254724 KB Output is correct
16 Correct 392 ms 256752 KB Output is correct
17 Correct 245 ms 145488 KB Output is correct
18 Correct 242 ms 145604 KB Output is correct
19 Correct 398 ms 262144 KB Output is correct
20 Correct 409 ms 262144 KB Output is correct