제출 #863797

#제출 시각아이디문제언어결과실행 시간메모리
863797browntoadBitaro, who Leaps through Time (JOI19_timeleap)C++14
4 / 100
3057 ms5012 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define endl '\n'

const ll maxn = 3e5+5;
const ll inf = (1ll<<60);
const ll mod = 1e9+7;

signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, q; cin>>n>>q;
    vector<pii> vc(n);
    REP1(i, n-1){
        cin>>vc[i].f>>vc[i].s;
    }
    REP(z, q){
        int t; cin>>t;
        if (t == 1){
            int x; cin>>x;
            cin>>vc[x].f>>vc[x].s;
        }
        else {
            int a, b, c, d; cin>>a>>b>>c>>d;
            int res = 0, cur = b;
            FOR(i, a, c){
                if (cur < vc[i].f){
                    cur = vc[i].f+1;
                }
                else if (vc[i].f <= cur && cur  < vc[i].s){
                    cur++;
                }
                else {
                    res += (cur-vc[i].s)+1;
                    cur = vc[i].s;
                }
            }
            for (int i = a; i > c; i--){
                if (cur < vc[i-1].f){
                    cur = vc[i-1].f+1;
                }
                else if (vc[i-1].f <= cur && cur  < vc[i-1].s){
                    cur++;
                }
                else {
                    res += (cur-vc[i-1].s)+1;
                    cur = vc[i-1].s;
                }
            }
            res += max(0ll, cur-d);
            cout<<res<<endl;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...