This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |