제출 #1234084

#제출 시각아이디문제언어결과실행 시간메모리
1234084antonnBitaro, who Leaps through Time (JOI19_timeleap)C++20
4 / 100
3083 ms2752 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3e5 + 7;

int n, q, l[N], r[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for (int i = 1; i < n; ++i) cin >> l[i] >> r[i];

    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int p, s, e;
            cin >> p >> s >> e;
            l[p] = s;
            r[p] = e;
        } else {
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            if (a < c) {
                int t = b;
                ll ans = 0;
                for (int i = a; i < c; ++i) {
                    if (t >= r[i]) {
                        ans += t - (r[i] - 1);
                        t = r[i] - 1;
                    } else {
                        t = max(t, l[i]);
                    }
                    ++t;
                }
                ans += max(0, t - d);
                cout << ans << "\n";
            } else {
                int t = b;
                ll ans = 0;
                for (int i = a - 1; i >= c; --i) {
                    if (t >= r[i]) {
                        ans += t - (r[i] - 1);
                        t = r[i] - 1;
                    } else {
                        t = max(t, l[i]);
                    }
                    ++t;
                }
                ans += max(0, t - d);
                cout << ans << "\n";
            }
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...