답안 #712794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712794 2023-03-20T02:51:25 Z PixelCat Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
558 ms 86336 KB
/* nya */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma")

#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
#define INF (int)(1e18)
#define MOD (int)(1000000007)
// #define MOD (int)(998244353)
using namespace std;
using LL = long long;
// using LLL = __int128_t;
using pii = pair<int, int>;
 
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
    cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#endif

struct Nyacho {
    int typ, l, r, cost;
};
ostream& operator<<(ostream& os, const Nyacho nya) {
    if(nya.typ) cout << nya.l << "->" << nya.r << " (" << nya.cost << ")";
    else        cout << nya.l << "::" << nya.r << " (" << nya.cost << ")";
    return os;
}

#define clamp(x, l, r) max(l, min(r, x))
Nyacho operator+(const Nyacho &a, const Nyacho &b) {
    Nyacho c;
    if(a.typ == 0 && b.typ == 0) {
        if(min(a.r, b.r) < max(a.l, b.l)) {
            if(a.r < b.r) c = {1, a.r, b.l, 0};
            else          c = {1, a.l, b.r, a.l - b.r};
        } else {
            c = {0, max(a.l, b.l), min(a.r, b.r), 0};
        }
    } else if(a.typ == 0) {
        c = {1, clamp(b.l, a.l, a.r), b.r, max(0ll, a.l - b.l)};
    } else if(b.typ == 0) {
        c = {1, a.l, clamp(a.r, b.l, b.r), max(0ll, a.r - b.r)};
    } else {
        c = {1, a.l, b.r, max(0ll, a.r - b.l)};
    }
    c.cost += a.cost + b.cost;
    return c;
}

const int MAXN = 300030;

#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
    Nyacho nya[MAXN << 2];
    Nyacho ayn[MAXN << 2];
    void upd(int id, int l, int r, int i, int L, int R) {
        if(l == r) {
            nya[id] = {0, L - i, R - i, 0};
            ayn[id] = {0, L + i, R + i, 0};
            return;
        }
        int m = (l + r) / 2;
        if(i <= m) upd(L(id), l, m, i, L, R);
        else upd(R(id), m + 1, r, i, L, R);
        nya[id] = (nya[L(id)] + nya[R(id)]);
        ayn[id] = (ayn[R(id)] + ayn[L(id)]);
    }
    Nyacho qry_lr(int id, int l, int r, int L, int R) {
        if(l >= L && r <= R) return nya[id];
        int m = (l + r) / 2;
        if(R <= m) return qry_lr(L(id), l, m, L, R);
        if(L > m)  return qry_lr(R(id), m + 1, r, L, R);
        return (qry_lr(L(id), l, m, L, R) + qry_lr(R(id), m + 1, r, L, R));
    }
    Nyacho qry_rl(int id, int l, int r, int L, int R) {
        if(l >= L && r <= R) return ayn[id];
        int m = (l + r) / 2;
        if(R <= m) return qry_rl(L(id), l, m, L, R);
        if(L > m)  return qry_rl(R(id), m + 1, r, L, R);
        return (qry_rl(R(id), m + 1, r, L, R) + qry_rl(L(id), l, m, L, R));
    }
} seg;

// Nyacho nya[MAXN];
// Nyacho ayn[MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // OAO
    int n, q; cin >> n >> q;
    // assert(max(n, q) <= 1000);
    For(i, 1, n - 1) {
        int l, r; cin >> l >> r; r--;
        seg.upd(0, 1, n - 1, i, l, r);
        // nya[i] = {0, l - i, r - i, 0};
        // ayn[i] = {0, l + i, r + i, 0};
        //cout << nya[i] << " " << ayn[i] << "\n";
    }
    while(q--) {
        int op; cin >> op;
        if(op == 1) {
            int p, s, e; cin >> p >> s >> e; e--;
            seg.upd(0, 1, n - 1, p, s, e);
            // nya[p] = {0, s - p, e - p, 0};
            // ayn[p] = {0, s + p, e + p, 0};
        } else {
            int a, b, c, d; cin >> a >> b >> c >> d;
            if(a == c) {
                cout << max(0ll, b - d) << "\n";
                continue;
            }
            Nyacho res;
            if(a < c) {
                c--; b -= a; d -= c + 1;
                res = (Nyacho){0, b, b, 0} + seg.qry_lr(0, 1, n - 1, a, c);
                // For(i, a, c) {
                //     res = merge(res, nya[i]);
                //     //cout << res << "\n";
                // }
            } else {
                a--; b += a; d += c - 1;
                res = (Nyacho){0, b, b, 0} + seg.qry_rl(0, 1, n - 1, c, a);
                // Forr(i, a, c) {
                //     res = merge(res, ayn[i]);
                //     //cout << res << "\n";
                // }
            }
            res = (res + (Nyacho){0, d, d, 0});
            cout << res.cost << "\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 523 ms 85728 KB Output is correct
2 Correct 496 ms 52556 KB Output is correct
3 Correct 511 ms 52572 KB Output is correct
4 Correct 501 ms 52468 KB Output is correct
5 Correct 516 ms 85804 KB Output is correct
6 Correct 521 ms 85656 KB Output is correct
7 Correct 525 ms 85748 KB Output is correct
8 Correct 538 ms 86336 KB Output is correct
9 Correct 503 ms 52836 KB Output is correct
10 Correct 524 ms 85764 KB Output is correct
11 Correct 512 ms 85692 KB Output is correct
12 Correct 535 ms 86236 KB Output is correct
13 Correct 550 ms 86256 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 523 ms 85728 KB Output is correct
43 Correct 496 ms 52556 KB Output is correct
44 Correct 511 ms 52572 KB Output is correct
45 Correct 501 ms 52468 KB Output is correct
46 Correct 516 ms 85804 KB Output is correct
47 Correct 521 ms 85656 KB Output is correct
48 Correct 525 ms 85748 KB Output is correct
49 Correct 538 ms 86336 KB Output is correct
50 Correct 503 ms 52836 KB Output is correct
51 Correct 524 ms 85764 KB Output is correct
52 Correct 512 ms 85692 KB Output is correct
53 Correct 535 ms 86236 KB Output is correct
54 Correct 550 ms 86256 KB Output is correct
55 Correct 1 ms 328 KB Output is correct
56 Correct 533 ms 82560 KB Output is correct
57 Correct 494 ms 49360 KB Output is correct
58 Correct 530 ms 82752 KB Output is correct
59 Correct 537 ms 82748 KB Output is correct
60 Correct 496 ms 49448 KB Output is correct
61 Correct 540 ms 82992 KB Output is correct
62 Correct 550 ms 83024 KB Output is correct
63 Correct 550 ms 82904 KB Output is correct
64 Correct 533 ms 83040 KB Output is correct
65 Correct 531 ms 82740 KB Output is correct
66 Correct 536 ms 82884 KB Output is correct
67 Correct 549 ms 82932 KB Output is correct
68 Correct 521 ms 68404 KB Output is correct
69 Correct 536 ms 82972 KB Output is correct
70 Correct 546 ms 49472 KB Output is correct
71 Correct 537 ms 48716 KB Output is correct
72 Correct 519 ms 60280 KB Output is correct
73 Correct 558 ms 82496 KB Output is correct
74 Correct 528 ms 82492 KB Output is correct
75 Correct 545 ms 82620 KB Output is correct
76 Correct 558 ms 83220 KB Output is correct
77 Correct 1 ms 332 KB Output is correct