Submission #919214

# Submission time Handle Problem Language Result Execution time Memory
919214 2024-01-31T13:04:23 Z ibrahim001 Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
421 ms 193104 KB
#include "bits/stdc++.h"
#define intt long long
using namespace std;
const intt inf = 1e18;
const int sz = 1e5+5;
int st[sz*60], lz[sz*60], L[sz*60], R[sz*60];
int last=1;
void check(int in){
    if ( !L[in] )   L[in] = ++last;
    if ( !R[in] )   R[in] = ++last;
}
void relax(int l, int r, int in){
    if ( !lz[in] )  return;
    st[in] = (r-l+1);
    if ( l == r ){
        lz[in]=0;
        return;
    }
    check(in);
    lz[L[in]] += lz[in];
    lz[R[in]] += lz[in];
    lz[in]=0;
}
void update(int a, int b, int l, int r, int in){
    relax(l, r, in);
    if ( l > b or r < a )   return;
    if ( a <= l and r <= b ){
        lz[in]++;
        relax(l, r, in);
        return;
    }
    check(in);
    int mid = (l+r)>>1;
    update(a, b, l, mid, L[in]);
    update(a, b, mid+1, r, R[in]);
    st[in] = st[L[in]]+st[R[in]];
}
int getans(int a, int b, int l, int r, int in){
    relax(l, r, in);
    if ( l > b or r < a )   return 0;
    if ( a <= l and r <= b )    return st[in];
    check(in);
    int mid = (l+r)>>1;
    return getans(a, b, l, mid, L[in])+getans(a, b, mid+1, r, R[in]);
}
int i,j;
signed main(){
    int n=1e9, q;
    cin >> q;
    int c = 0;
    while(q--){
        int t;
        cin >> t;
        int x, y;
        cin >> x >> y;
        x += c;
        y += c;
        if ( t == 1 ){
            int res = getans(x , y, 1, n, 1);
            c = res;
            cout << res << endl;
        }
        else{
            update(x, y, 1, n, 1);
        }
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 19 ms 4952 KB Output is correct
5 Correct 28 ms 6496 KB Output is correct
6 Correct 24 ms 6488 KB Output is correct
7 Correct 23 ms 6488 KB Output is correct
8 Correct 169 ms 27920 KB Output is correct
9 Correct 349 ms 47320 KB Output is correct
10 Correct 358 ms 53796 KB Output is correct
11 Correct 410 ms 57496 KB Output is correct
12 Correct 348 ms 58964 KB Output is correct
13 Correct 360 ms 73764 KB Output is correct
14 Correct 372 ms 74708 KB Output is correct
15 Runtime error 421 ms 193104 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -