Submission #472375

# Submission time Handle Problem Language Result Execution time Memory
472375 2021-09-13T12:38:27 Z ITO Bitaro, who Leaps through Time (JOI19_timeleap) C++11
100 / 100
2301 ms 86260 KB
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
struct tcio {
    bool t;
    ll c, i, o;
} mx[1048576], mx2[1048576], ab;
tcio merge(tcio a1, tcio a2) {
    if (a1.t == 0) {
        if (a2.t == 0) {
            if (a1.i > a2.o) return {1, a1.i - a2.o, a1.i, a2.o};
            if (a1.o < a2.i)  return {1, 0ll, a1.o, a2.i};
            return {0, 0ll, max(a1.i, a2.i), min(a1.o, a2.o)};
        }
        if (a2.i < a1.i) return {1, a1.i - a2.i + a2.c, a1.i, a2.o};
        if (a2.i > a1.o) return {1, a2.c, a1.o, a2.o};
        return a2;
    }
    if (a2.t == 0) {
        if (a1.o < a2.i) return {1, a1.c, a1.i, a2.i};
        if (a1.o > a2.o) return {1, a1.o - a2.o + a1.c, a1.i, a2.o};
        return {1, a1.c, a1.i, a1.o};
    }
    return {1, max(a1.o - a2.i, 0ll) + a1.c + a2.c, a1.i, a2.o};
}
void upd(pair<ll, ll> v, int id, int no, int ql, int qr) {
    if (id < ql || id > qr) {
        return;
    }
    if (ql == qr) {
        mx[no] = {0, 0, v.first, v.second};
        return;
    }
    int m = (ql + qr) / 2;
    upd(v, id, no * 2, ql, m);
    upd(v, id, no * 2 + 1, m + 1, qr);
    mx[no] = merge(mx[no * 2], mx[no * 2 + 1]);
    return;
}
void upd2(pair<ll, ll> v, int id, int no, int ql, int qr) {
    if (id < ql || id > qr) {
        return;
    }
    if (ql == qr) {
        mx2[no] = {0, 0, v.first, v.second};
        return;
    }
    int m = (ql + qr) / 2;
    upd2(v, id, no * 2, ql, m);
    upd2(v, id, no * 2 + 1, m + 1, qr);
    mx2[no] = merge(mx2[no * 2], mx2[no * 2 + 1]);
    return;
}
tcio qry(int l, int r, int no, int ql, int qr) {
    if (l > qr || r < ql) {
        return {0, 0, -1000000001, 1000000001};
    }
    if (ql >= l && qr <= r) {
        return mx[no];
    }
    int m = (ql + qr) / 2;
    return merge(qry(l, r, no * 2, ql, m), qry(l, r, no * 2 + 1, m + 1, qr));
}
tcio qry2(int l, int r, int no, int ql, int qr) {
    if (l > qr || r < ql) {
        return {0, 0, -1000000001, 1000000001};
    }
    if (ql >= l && qr <= r) {
        return mx2[no];
    }
    int m = (ql + qr) / 2;
    return merge(qry2(l, r, no * 2, ql, m), qry2(l, r, no * 2 + 1, m + 1, qr));
}
int main(){
    int n, q, j, la, ra, t, p, s, e, ca, ta, cb, tb;
    cin >> n >> q;
    n--;
    for (int i = 0; i < n; i++) {
        cin >> la >> ra;
        ra--;
        j = n - i - 1;
        upd(mp(la - i, ra - i), i, 1, 0, n - 1);
        upd2(mp(la - j, ra - j), j, 1, 0, n - 1);
    }
    for (int i = 0; i < q; i++) {
        cin >> t;
        if (t == 1) {
            cin >> p >> s >> e;
            p--, e--, j = n - p - 1;
            upd(mp(s - p, e - p), p, 1, 0, n - 1);
            upd2(mp(s - j, e - j), j, 1, 0, n - 1);
        } else {
            cin >> ca >> ta >> cb >> tb;
            ca--, cb--, tb--;
            if (ca <= cb) {
                cb--, ta -= ca, tb -= cb;
                ab = merge(merge({0, 0, ta, ta}, qry(ca, cb, 1, 0, n - 1)), {0, 0, tb, tb});
            } else {
                ca = n - ca, cb = n - cb, cb--, ta -= ca, tb -= cb;
                ab = merge(merge({0, 0, ta, ta}, qry2(ca, cb, 1, 0, n - 1)), {0, 0, tb, tb});
            }
            cout << ab.c << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 5 ms 436 KB Output is correct
13 Correct 5 ms 460 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
15 Correct 5 ms 488 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 5 ms 460 KB Output is correct
18 Correct 5 ms 492 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 5 ms 448 KB Output is correct
21 Correct 5 ms 460 KB Output is correct
22 Correct 6 ms 460 KB Output is correct
23 Correct 5 ms 460 KB Output is correct
24 Correct 5 ms 460 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 5 ms 460 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 5 ms 460 KB Output is correct
30 Correct 5 ms 460 KB Output is correct
31 Correct 5 ms 460 KB Output is correct
32 Correct 5 ms 460 KB Output is correct
33 Correct 5 ms 460 KB Output is correct
34 Correct 5 ms 468 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 5 ms 460 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 5 ms 480 KB Output is correct
39 Correct 5 ms 460 KB Output is correct
40 Correct 5 ms 460 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2062 ms 70188 KB Output is correct
2 Correct 2017 ms 52568 KB Output is correct
3 Correct 2051 ms 52668 KB Output is correct
4 Correct 2031 ms 52468 KB Output is correct
5 Correct 2108 ms 85724 KB Output is correct
6 Correct 2128 ms 85624 KB Output is correct
7 Correct 2144 ms 85652 KB Output is correct
8 Correct 2301 ms 86260 KB Output is correct
9 Correct 2157 ms 52744 KB Output is correct
10 Correct 2180 ms 85860 KB Output is correct
11 Correct 2063 ms 85732 KB Output is correct
12 Correct 2190 ms 86132 KB Output is correct
13 Correct 2264 ms 86164 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 5 ms 436 KB Output is correct
13 Correct 5 ms 460 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
15 Correct 5 ms 488 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 5 ms 460 KB Output is correct
18 Correct 5 ms 492 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 5 ms 448 KB Output is correct
21 Correct 5 ms 460 KB Output is correct
22 Correct 6 ms 460 KB Output is correct
23 Correct 5 ms 460 KB Output is correct
24 Correct 5 ms 460 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 5 ms 460 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 5 ms 460 KB Output is correct
30 Correct 5 ms 460 KB Output is correct
31 Correct 5 ms 460 KB Output is correct
32 Correct 5 ms 460 KB Output is correct
33 Correct 5 ms 460 KB Output is correct
34 Correct 5 ms 468 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 5 ms 460 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 5 ms 480 KB Output is correct
39 Correct 5 ms 460 KB Output is correct
40 Correct 5 ms 460 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 2062 ms 70188 KB Output is correct
43 Correct 2017 ms 52568 KB Output is correct
44 Correct 2051 ms 52668 KB Output is correct
45 Correct 2031 ms 52468 KB Output is correct
46 Correct 2108 ms 85724 KB Output is correct
47 Correct 2128 ms 85624 KB Output is correct
48 Correct 2144 ms 85652 KB Output is correct
49 Correct 2301 ms 86260 KB Output is correct
50 Correct 2157 ms 52744 KB Output is correct
51 Correct 2180 ms 85860 KB Output is correct
52 Correct 2063 ms 85732 KB Output is correct
53 Correct 2190 ms 86132 KB Output is correct
54 Correct 2264 ms 86164 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1822 ms 82496 KB Output is correct
57 Correct 1753 ms 49364 KB Output is correct
58 Correct 1998 ms 82656 KB Output is correct
59 Correct 1817 ms 82960 KB Output is correct
60 Correct 1730 ms 49424 KB Output is correct
61 Correct 1846 ms 82968 KB Output is correct
62 Correct 1889 ms 82940 KB Output is correct
63 Correct 1875 ms 82984 KB Output is correct
64 Correct 1864 ms 82900 KB Output is correct
65 Correct 1840 ms 82664 KB Output is correct
66 Correct 1811 ms 82664 KB Output is correct
67 Correct 1933 ms 83000 KB Output is correct
68 Correct 1752 ms 68272 KB Output is correct
69 Correct 1964 ms 82872 KB Output is correct
70 Correct 1781 ms 49648 KB Output is correct
71 Correct 1784 ms 48704 KB Output is correct
72 Correct 1851 ms 60004 KB Output is correct
73 Correct 2005 ms 82408 KB Output is correct
74 Correct 1960 ms 82452 KB Output is correct
75 Correct 1970 ms 82476 KB Output is correct
76 Correct 1928 ms 83076 KB Output is correct
77 Correct 1 ms 204 KB Output is correct