#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> l, vector<int> r) {
int n = l.size();
int t = -1;
long long res = 0;
for (int i = 0; i < n; ++i) {
if (t > r[i]) {
res += t - r[i];
t = r[i];
}
if (t < l[i]) {
t = l[i];
}
++t;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> l(n), r(n);
for (int i = 0; i < n - 1; ++i) {
cin >> l[i] >> r[i];
--r[i];
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int p, s, e;
cin >> p >> s >> e;
--p, --e;
l[p] = s, r[p] = e;
}
if (t == 2) {
int a, b, c, d;
cin >> a >> b >> c >> d;
--a, --c;
if (a == c) {
cout << max(0, b - d) << "\n";
} else {
vector<int> cl, cr;
cl.push_back(b - 1);
cr.push_back(b - 1);
if (a < c) {
for (int i = a; i < c; ++i) {
cl.push_back(l[i]);
cr.push_back(r[i]);
}
} else {
for (int i = a - 1; i >= c; --i) {
cl.push_back(l[i]);
cr.push_back(r[i]);
}
}
cl.push_back(d);
cr.push_back(d);
cout << solve(cl, cr) << "\n";
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3080 ms |
8096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |