Submission #1018426

# Submission time Handle Problem Language Result Execution time Memory
1018426 2024-07-10T03:50:45 Z aufan Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
304 ms 262144 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int inf = 1e9;

struct node {
        int val, lz;
        int st, en, len;
        node *left, *right;

        void build(int start, int end) {
                st = start;
                en = end;
                len = en - st + 1;
                lz = 0;
        }

        void lazy() {
                if (left == NULL) {
                        int md = (st + en) / 2;
                        left = new node();
                        right = new node();
                        
                        left->build(st, md);
                        right->build(md + 1, en);
                }

                if (lz == 1) {
                        left->val = lz * left->len;
                        left->lz = lz;

                        right->val = lz * right->len;
                        right->lz = lz;
                }
        }

        int query(int lf, int rg) {
                if (st > rg || en < lf) return 0ll;
                if (lf <= st && en <= rg) return val;
                lazy();
                return left->query(lf, rg) + right->query(lf, rg);
        }

        void update(int lf, int rg) {
                if (st > rg || en < lf) return;
                if (lf <= st && en <= rg) {
                        val = 1 * len;
                        lz = 1;
                        return;
                }

                lazy();
                left->update(lf, rg);
                right->update(lf, rg);

                val = left->val + right->val;
        }
} sg;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int q;
        cin >> q;

        int c = 0;
        sg.build(1, inf);
        for (int i = 0; i < q; i++) {
                int t, x, y;
                cin >> t >> x >> y;

                if (t == 1) {
                        int ans = sg.query(x + c, y + c);
                        cout << ans << '\n';
                        c = ans;
                } else if (t == 2) {
                        sg.update(x + c, y + c);
                }
        }
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 9 ms 6568 KB Output is correct
5 Correct 12 ms 8024 KB Output is correct
6 Correct 11 ms 7772 KB Output is correct
7 Correct 11 ms 7800 KB Output is correct
8 Correct 86 ms 59080 KB Output is correct
9 Correct 194 ms 102228 KB Output is correct
10 Correct 196 ms 113116 KB Output is correct
11 Correct 195 ms 121428 KB Output is correct
12 Correct 203 ms 125268 KB Output is correct
13 Correct 183 ms 145656 KB Output is correct
14 Correct 176 ms 147232 KB Output is correct
15 Runtime error 304 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -