#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct NOD {
int M, m, delta;
NOD(int Vm = 0, int d = 0) {
M = Vm - max(0, d);
m = max(0, -d);
delta = d;
}
NOD(int a, int b, int d) {
M = a;
m = b;
delta = d;
}
void print() {
printf("M = %d, m = %d, delta = %d\n", M, m, delta);
}
} seg[4 * MAXN];
char B[MAXN];
int T[MAXN], ts[MAXN];
int Vm;
void updseg(int idx, int l, int r, int x, int z) {
if(l == r) seg[idx] = NOD(Vm, z);
else {
int m = (l + r) / 2;
if(x <= m) updseg(idx * 2, l, m, x, z);
else updseg(idx * 2 + 1, m + 1, r, x, z);
NOD &L = seg[idx * 2], &R = seg[idx * 2 + 1];
if(L.M + L.delta <= R.m)
seg[idx] = NOD(Vm, Vm, R.m + R.delta - Vm);
else if(L.m + L.delta >= R.M)
seg[idx] = NOD(Vm, Vm, R.M + R.delta - Vm);
else
seg[idx] = NOD(min(L.M, R.M - L.delta), max(L.m, R.m - L.delta), L.delta + R.delta);
}
}
int main() {
int N, V2;
int Tans, Vans;
cin >> N >> Vm >> V2;
for(int i = 0; i < N; i++) cin >> B[i] >> T[i];
for(int i = N - 1; i > 0; i--) T[i] -= T[i - 1];
for(int i = 1; i < 4 * N; i++) seg[i] = NOD(Vm);
for(int i = 0; i < N - 1; i++) ts[i] = i + 1;
sort(ts, ts + N - 1, [&](const int a, const int b) { return T[a] < T[b]; } );
//for(int i = 0; i < N - 1; i++) printf("%d ", ts[i]);
//printf("\n");
Tans = T[ts[0]] - 1;
Vans = V2;
ts[N - 1] = N;
T[N] = 0;
for(int i = 0; i < N - 1; i++) {
updseg(1, 0, N - 1, ts[i], B[ts[i]] == '+' ? 1 : -1);
if(T[ts[i]] != T[ts[i + 1]]) {
if(seg[1].M + seg[1].delta == V2) {
Tans = T[ts[i + 1]] - 1;
Vans = Vm;
}
else if(seg[1].m < V2 - seg[1].delta && V2 - seg[1].delta < seg[1].M) {
Tans = T[ts[i + 1]] - 1;
Vans = Vm;
}
else if(seg[1].m + seg[1].delta == V2) {
Tans = T[ts[i + 1]] - 1;
Vans = seg[1].m;
}
}
//seg[1].print();
}
if(Tans == -1) cout << "infinity";
else cout << Tans << " " << Vans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
8 ms |
4984 KB |
Output is correct |
3 |
Incorrect |
7 ms |
4984 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5112 KB |
Output is correct |
2 |
Correct |
12 ms |
5112 KB |
Output is correct |
3 |
Correct |
11 ms |
5084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
5468 KB |
Output is correct |
2 |
Correct |
32 ms |
5436 KB |
Output is correct |
3 |
Correct |
32 ms |
5396 KB |
Output is correct |
4 |
Correct |
31 ms |
5368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
5452 KB |
Output is correct |
2 |
Correct |
36 ms |
5496 KB |
Output is correct |
3 |
Correct |
35 ms |
5496 KB |
Output is correct |
4 |
Correct |
29 ms |
5456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
5640 KB |
Output is correct |
2 |
Correct |
44 ms |
5600 KB |
Output is correct |
3 |
Correct |
51 ms |
5696 KB |
Output is correct |
4 |
Correct |
35 ms |
5540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
5980 KB |
Output is correct |
2 |
Correct |
61 ms |
5980 KB |
Output is correct |
3 |
Correct |
52 ms |
5948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
7064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
7180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |