이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |