Submission #991605

# Submission time Handle Problem Language Result Execution time Memory
991605 2024-06-02T15:40:15 Z yusuf12360 Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
314 ms 262144 KB
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi> 
#define pb push_back
#define fi first
#define se second
#define TII tuple<int, int, int>
#define ts to_string
#pragma gcc optimize("O3");
using namespace std;
const int INF=1e9;
struct node{
    int l, r, sum=0, lazy=0;
    node *left=nullptr, *right=nullptr;
    node(int l, int r) : l(l), r(r) {}

    void extend() {
        if(l==r) return;
        int mid=l+r>>1;
        if(!left) left=new node(l, mid);
        if(!right) right=new node(mid+1, r);
    }
    void push() {
        if(l==r) return;
        extend();
        if(lazy) {
            left->lazy=1;
            left->sum=left->r-left->l+1;
            right->lazy=1;
            right->sum=right->r-right->l+1;
            lazy=0;
        }
    }
    void update(int ql, int qr) {
        if(max(l, ql)>min(r, qr)) return;
        if(ql<=l && r<=qr) {lazy=1; sum=r-l+1; return;}
        push();
        left->update(ql, qr);
        right->update(ql, qr);
        sum=left->sum+right->sum;
    }
    int get(int ql, int qr) {
        if(max(l, ql)>min(r, qr)) return 0;
        if(ql<=l && r<=qr) return sum;
        push();
        return left->get(ql, qr)+right->get(ql, qr);
    }
};
signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int m, c=0; cin >> m;
    node *root = new node(1, INF);
    while(m--) {
        int type, ql, qr;
        cin >> type >> ql >> qr;
        if(type==1) c=root->get(ql+c, qr+c), cout << c << '\n';
        else root->update(ql+c, qr+c);
    }
    return 0;
}

Compilation message

apple.cpp:12: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
   12 | #pragma gcc optimize("O3");
      | 
apple.cpp: In member function 'void node::extend()':
apple.cpp:22:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         int mid=l+r>>1;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 6492 KB Output is correct
5 Correct 11 ms 7772 KB Output is correct
6 Correct 11 ms 7380 KB Output is correct
7 Correct 11 ms 7828 KB Output is correct
8 Correct 90 ms 58288 KB Output is correct
9 Correct 191 ms 100656 KB Output is correct
10 Correct 231 ms 111444 KB Output is correct
11 Correct 196 ms 119636 KB Output is correct
12 Correct 228 ms 123364 KB Output is correct
13 Correct 189 ms 143580 KB Output is correct
14 Correct 179 ms 145040 KB Output is correct
15 Runtime error 314 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -