#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2400 KB |
Output is correct |
28 |
Correct |
2 ms |
2392 KB |
Output is correct |
29 |
Correct |
2 ms |
2524 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2568 KB |
Output is correct |
35 |
Correct |
1 ms |
2528 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
2564 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3007 ms |
8628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2400 KB |
Output is correct |
28 |
Correct |
2 ms |
2392 KB |
Output is correct |
29 |
Correct |
2 ms |
2524 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2568 KB |
Output is correct |
35 |
Correct |
1 ms |
2528 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
2564 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Execution timed out |
3007 ms |
8628 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |