답안 #871807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871807 2023-11-11T15:54:00 Z vjudge1 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
742 ms 121684 KB
#include <bits/stdc++.h>
using namespace std;

const int64_t inf = 1e11;

class state_t {
       public:
        bool fucked;
        int64_t dick, cock, penis, gay;
        state_t(int64_t dick = -inf, int64_t cock = +inf) : fucked(0), dick(dick), cock(cock), gay(0) {}

        int64_t shit(int64_t& nigga) const {
                int64_t res = 0;
                if (!fucked) {
                        if (nigga > cock) {
                                res = nigga - cock;
                                nigga = cock;
                        } else {
                                res = 0;
                                nigga = max(nigga, dick);
                        }
                } else {
                        res = max<int64_t>(0, nigga - cock) + gay;
                        nigga = penis;
                }
                return res;
        }

        state_t operator+(const state_t& other) const {
                state_t res;
                if (!fucked && !other.fucked) {
                        if (dick > other.cock) {
                                res.fucked = 1;
                                res.dick = res.cock = res.penis = dick;
                                res.gay = other.shit(res.penis);
                        } else if (cock < other.dick) {
                                res.fucked = 1;
                                res.dick = res.cock = res.penis = cock;
                                res.gay = other.shit(res.penis);
                        } else {
                                res = state_t(max(dick, other.dick), min(cock, other.cock));
                        }
                } else if (fucked) {
                        res = *this;
                        res.gay += other.shit(res.penis);
                } else if (other.fucked) {
                        res = other;
                        if (dick > other.cock) {
                                res.dick = res.cock = res.penis = dick;
                                res.gay = other.shit(res.penis);
                        } else if (cock < other.dick) {
                                res.cock = res.dick = res.penis = cock;
                                res.gay = other.shit(res.penis);
                        }
                }
                return res;
        }
};

class segtree_t {
       public:
        segtree_t *left, *right;
        int l, r, m;
        state_t vagina;

        segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1) {
                if (l == r) return;
                left = new segtree_t(l, m);
                right = new segtree_t(m + 1, r);
        }

        void Update(int i, const state_t& x) {
                if (l == r) {
                        vagina = x;
                        return;
                }
                if (i <= m) {
                        left->Update(i, x);
                } else {
                        right->Update(i, x);
                }
                vagina = left->vagina + right->vagina;
        }

        int64_t Get(int s, int t, int64_t& pussy) {
                if (l > t || r < s) return 0;
                if (s <= l && r <= t) {
                        int64_t res = vagina.shit(pussy);
                        return res;
                }
                int64_t res = 0;
                res += left->Get(s, t, pussy);
                res += right->Get(s, t, pussy);
                return res;
        }
};

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n, q;
        cin >> n >> q;
        vector<int> l(n - 1), r(n - 1);
        vector<int> la(n - 1), ra(n - 1);
        vector<int> lb(n - 1), rb(n - 1);
        for (int i = 0; i < n - 1; i++) cin >> l[i] >> r[i], r[i]--;
        for (int i = 0; i < n - 1; i++) la[i] = l[i] - i, ra[i] = r[i] - i;
        for (int i = 0; i < n - 1; i++) lb[i] = l[i] + i, rb[i] = r[i] + i;

        segtree_t* treeL = new segtree_t(0, n);
        segtree_t* treeR = new segtree_t(0, n);

        for (int i = 0; i < n - 1; i++) {
                treeL->Update(i, state_t(la[i], ra[i]));
                treeR->Update(n - i, state_t(lb[i], rb[i]));
        }

        while (q--) {
                int _;
                cin >> _;
                if (_ == 1) {
                        int i;
                        cin >> i;
                        i--;
                        int s, t;
                        cin >> s >> t;
                        t--;
                        treeL->Update(i, state_t(s - i, t - i));
                        treeR->Update(n - i, state_t(s + i, t + i));
                } else {
                        int64_t a, b, c, d;
                        cin >> a >> b >> c >> d;
                        a--, c--;
                        if (a == c) {
                                cout << max<int64_t>(0, b - d) << '\n';
                        } else if (a < c) {
                                b -= a, d -= c;
                                int64_t res = treeL->Get(a, c - 1, b);
                                cout << res + max<int64_t>(0, b - d) << '\n';
                        } else {
                                b += a - 1, d += c - 1;
                                a = n - a, c = n - c;
                                int64_t res = treeR->Get(a + 1, c, b);
                                cout << res + max<int64_t>(0, b - d) << '\n';
                        }
                }
        }
}

Compilation message

timeleap.cpp: In constructor 'segtree_t::segtree_t(int, int)':
timeleap.cpp:66:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |         segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1) {
      |                                                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 500 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 936 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 784 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 720 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 800 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 736 ms 112468 KB Output is correct
2 Correct 723 ms 106956 KB Output is correct
3 Correct 703 ms 108184 KB Output is correct
4 Correct 699 ms 104844 KB Output is correct
5 Correct 723 ms 112212 KB Output is correct
6 Correct 742 ms 110756 KB Output is correct
7 Correct 703 ms 113732 KB Output is correct
8 Correct 706 ms 118356 KB Output is correct
9 Correct 664 ms 105728 KB Output is correct
10 Correct 665 ms 113416 KB Output is correct
11 Correct 663 ms 112468 KB Output is correct
12 Correct 682 ms 119892 KB Output is correct
13 Correct 691 ms 121684 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 500 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 936 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 784 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 720 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 800 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 0 ms 600 KB Output is correct
42 Correct 736 ms 112468 KB Output is correct
43 Correct 723 ms 106956 KB Output is correct
44 Correct 703 ms 108184 KB Output is correct
45 Correct 699 ms 104844 KB Output is correct
46 Correct 723 ms 112212 KB Output is correct
47 Correct 742 ms 110756 KB Output is correct
48 Correct 703 ms 113732 KB Output is correct
49 Correct 706 ms 118356 KB Output is correct
50 Correct 664 ms 105728 KB Output is correct
51 Correct 665 ms 113416 KB Output is correct
52 Correct 663 ms 112468 KB Output is correct
53 Correct 682 ms 119892 KB Output is correct
54 Correct 691 ms 121684 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 672 ms 108048 KB Output is correct
57 Correct 650 ms 101144 KB Output is correct
58 Correct 684 ms 111036 KB Output is correct
59 Correct 692 ms 111872 KB Output is correct
60 Correct 664 ms 104204 KB Output is correct
61 Correct 689 ms 115224 KB Output is correct
62 Correct 695 ms 114788 KB Output is correct
63 Correct 695 ms 114260 KB Output is correct
64 Correct 689 ms 115296 KB Output is correct
65 Correct 657 ms 109536 KB Output is correct
66 Correct 669 ms 110264 KB Output is correct
67 Correct 691 ms 114600 KB Output is correct
68 Correct 678 ms 105652 KB Output is correct
69 Correct 716 ms 118420 KB Output is correct
70 Correct 680 ms 104900 KB Output is correct
71 Correct 652 ms 100980 KB Output is correct
72 Correct 663 ms 105048 KB Output is correct
73 Correct 708 ms 115540 KB Output is correct
74 Correct 728 ms 116140 KB Output is correct
75 Correct 731 ms 117836 KB Output is correct
76 Correct 701 ms 118452 KB Output is correct
77 Correct 0 ms 348 KB Output is correct