제출 #894012

#제출 시각아이디문제언어결과실행 시간메모리
894012boxBitaro, who Leaps through Time (JOI19_timeleap)C++17
4 / 100
16 ms4232 KiB
#include <bits/stdc++.h>
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;

const int MAXN = 1e5;

int N, Q;
int L[MAXN], R[MAXN];

i64 qry_slow(int i, int t1, int j, int t2) {
    if (i == j) return t1 > t2 ? t1 - t2 : 0;
    i64 x = 0;
    if (i < j) {
        while (i < j) {
            if (t1 >= R[i]) {
                x += t1 - R[i] + 1;
                t1 = R[i] - 1;
            }
            t1 = max(t1, L[i]);
            i++;
            t1++;
        }
    } else {
        while (i > j) {
            i--;
            if (t1 >= R[i]) {
                x += t1 - R[i] + 1;
                t1 = R[i] - 1;
            }
            t1 = max(t1, L[i]);
            t1++;
        }
    }
    if (t1 > t2) x += t1 - t2;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) cin >> L[i] >> R[i];
    while (Q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            cin >> i, i--;
            cin >> L[i] >> R[i];
        } else {
            int i, t1, j, t2;
            cin >> i >> t1 >> j >> t2, i--, j--;
            cout << qry_slow(i, t1, j, t2) << '\n';
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...