Submission #916110

#TimeUsernameProblemLanguageResultExecution timeMemory
916110boris_mihovBitaro, who Leaps through Time (JOI19_timeleap)C++17
4 / 100
3007 ms8628 KiB
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <stack>

typedef long long llong;
const int MAXN = 300000 + 10;
const int INF  = 1e9;

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

void solve()
{
    for (int i = 1 ; i <= q ; ++i)
    {
        int qType;
        std::cin >> qType;
        if (qType == 1)
        {
            int idx;
            std::cin >> idx;
            std::cin >> l[idx] >> r[idx];
            r[idx]--;
            continue;
        }

        int a, tA, b, tB;
        std::cin >> a >> tA >> b >> tB;
        llong ans = 0;
        if (a < b)
        {
            int time = tA;
            for (int j = a ; j < b ; ++j)
            {
                ans += std::max(0, time - r[j]);
                time = std::min(std::max(l[j], time), r[j]) + 1;
            }

            ans += std::max(0, time - tB);
        } else
        {
            int time = tA;
            for (int j = a - 1 ; j >= b ; --j)
            {
                ans += std::max(0, time - r[j]);
                time = std::min(std::max(l[j], time), r[j]) + 1;
            }

            ans += std::max(0, time - tB);
        }

        std::cout << ans << '\n';
    }    
}

void input()
{
    std::cin >> n >> q;
    for (int i = 1 ; i < n ; ++i)
    {
        std::cin >> l[i] >> r[i];
        r[i]--;
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...