Submission #106559

# Submission time Handle Problem Language Result Execution time Memory
106559 2019-04-19T04:41:03 Z Hideo Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
250 ms 51576 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 2e5 + 7;
const int INF = 1e9;

int n, c, x;

struct ST{
    int l, r, s, val;
    ST(){
        l = r = s = val = 0;
    }
};
ST t[8 * N];

void push (int v, int l, int r){
    if (l != r){
        if (!t[v].l)
            t[v].l = ++c;
        if (!t[v].r)
            t[v].r = ++c;
    }
    if (t[v].val){
        t[v].s = r - l + 1;
        t[t[v].l].val = t[t[v].r].val = 1;
    }
}

void upd (int v, int l, int r, int ql, int qr){
    push(v, l, r);
    if (ql <= l && r <= qr){
        t[v].val = 1;
        push(v, l, r);
        return;
    }
    if (r < ql || l > qr)
        return;
    int mid = (l + r) >> 1;
    upd(t[v].l, l, mid, ql, qr);
    upd(t[v].r, mid + 1, r, ql, qr);
    t[v].s = t[t[v].l].s + t[t[v].r].s;
}

int get (int v, int l, int r, int ql, int qr){
    push(v, l, r);
    if (ql <= l && r <= qr)
        return t[v].s;
    if (r < ql || l > qr)
        return 0;
    int mid = (l + r) >> 1;
    return get(t[v].l, l, mid, ql, qr) + get(t[v].r, mid + 1, r, ql, qr);
}
main(){
    c = 1;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int t, l, r;
        scanf("%d%d%d", &t, &l, &r);
        if (t == 1){
            x = get(1, 1, INF, l + x, r + x);
            printf("%d\n", x);
        }
        else
            upd(1, 1, INF, l + x, r + x);
    }
}

Compilation message

apple.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
apple.cpp: In function 'int main()':
apple.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &t, &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25336 KB Output is correct
2 Correct 26 ms 25316 KB Output is correct
3 Correct 25 ms 25316 KB Output is correct
4 Correct 36 ms 25592 KB Output is correct
5 Correct 42 ms 25592 KB Output is correct
6 Correct 45 ms 25592 KB Output is correct
7 Correct 38 ms 25600 KB Output is correct
8 Runtime error 250 ms 51576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -