Submission #971748

# Submission time Handle Problem Language Result Execution time Memory
971748 2024-04-29T08:51:56 Z NoLove Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
1 ms 992 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 29-04-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;

struct Data {
    int cnt = 0, l = -1, r;
    int red = false;
};
vector<Data> st(2);

int n, type, x, y;

void cre(Data& v) {
    if (v.l != -1) return;
    v.l = si(st);
    st.pb(Data());
    v.r = si(st);
    st.pb(Data());
}

void push(Data& v, int l, int r) {
    if (v.red) {
        v.cnt = v.red*(r - l + 1);
        if (l < r) {
            cre(v);
            st[v.l].red |= v.red; 
            st[v.r].red |= v.red;
        }
    }
}
void upd(int v = 1, int l = 1, int r = 1e9) {
    push(st[v], l, r);
    if (l > y or x > r) return;
    if (x <= l && r <= y) {
        // db(v, l, r)
        st[v].red = true;
    } else {
        int mid = (l + r) / 2;
        cre(st[v]);
        upd(st[v].l, l, mid);
        upd(st[v].r, mid + 1, r);
        push(st[st[v].l], l, mid);
        push(st[st[v].r], mid + 1, r);
        st[v].cnt = st[st[v].l].cnt + st[st[v].r].cnt;
        if (st[v].cnt > 0)
        db(v, l, r, st[v].cnt)
    }
}
int get(int v = 1, int l = 1, int r = 1e9) {
    push(st[v], l, r);
    // db(st[v].cnt, l, r)
    if (l > y or x > r) return 0;
    if (x <= l && r <= y) {
        return st[v].cnt;
    } else {
        int mid = (l + r) / 2;
        cre(st[v]);
        return get(st[v].l, l, mid) + 
                get(st[v].r, mid + 1, r);
    }
}
int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    } 

    cin >> n;    
    int c = 0;
    while (cin >> type >> x >> y) {
        x += c; y += c;
        if (type == 2) upd();
        else {
            c = get();
            cout << c << "\n";
        }
    }
}

Compilation message

apple.cpp: In function 'int32_t main()':
apple.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 1 ms 992 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -