#include <stdio.h>
#define N 100000
#define N_ (1 << 17)
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int tt[N]; char cc[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (tt[ii[j]] == tt[i_])
j++;
else if (tt[ii[j]] < tt[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int sum[N_ * 2], sufmn[N_ * 2], sufmx[N_ * 2], n_;
void pul(int i) {
int l = i << 1, r = l | 1;
sum[i] = sum[l] + sum[r];
sufmn[i] = min(sufmn[l] + sum[r], sufmn[r]);
sufmx[i] = max(sufmx[l] + sum[r], sufmx[r]);
}
void build(char *cc, int n) {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 1; i < n; i++)
sum[n_ + i] = cc[i] == '+' ? 1 : -1, sufmn[n_ + i] = min(sum[n_ + i], 0), sufmx[n_ + i] = max(sum[n_ + i], 0);
for (i = n_ - 1; i > 0; i--)
pul(i);
}
void update(int i) {
i += n_;
sum[i] = sufmn[i] = sufmx[i] = 0;
while (i > 1)
pul(i >>= 1);
}
int mn, mx;
void query(int d) {
int i, s;
i = 1, s = mn = mx = 0;
while (i < n_) {
int s_ = s + sum[i << 1 | 1];
int mn_ = min(mn, sufmn[i << 1 | 1] + s);
int mx_ = max(mx, sufmx[i << 1 | 1] + s);
if (mx_ - mn_ <= d)
s = s_, mn = mn_, mx = mx_, i = i << 1 | 0;
else
i = i << 1 | 1;
}
}
int main() {
static int ii[N];
int n, vmax, v2, i;
scanf("%d%d%d", &n, &vmax, &v2);
for (i = 0; i < n; i++) {
static char s[2];
scanf("%s%d", s, &tt[i]);
cc[i] = s[0];
}
for (i = n - 1; i > 0; i--) {
tt[i] -= tt[i - 1];
ii[i] = i;
}
sort(ii, 1, n);
build(cc, n);
i = n - 1;
while (1) {
int t;
query(vmax);
if (mx <= v2 && v2 <= vmax + mn) {
if (i + 1 == n)
printf("infinity\n");
else
printf("%d %d\n", tt[ii[i + 1]] - 1, v2 == vmax + mn ? vmax : v2 - sum[1]);
return 0;
}
t = tt[ii[i]];
while (i >= 0 && tt[ii[i]] == t)
update(ii[i--]);
}
return 0;
}
Compilation message
mp3player.c: In function 'main':
mp3player.c:87:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d%d%d", &n, &vmax, &v2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mp3player.c:91:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf("%s%d", s, &tt[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1360 KB |
Output is correct |
2 |
Correct |
13 ms |
1464 KB |
Output is correct |
3 |
Correct |
10 ms |
1404 KB |
Output is correct |
4 |
Correct |
8 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1492 KB |
Output is correct |
2 |
Correct |
15 ms |
1468 KB |
Output is correct |
3 |
Correct |
12 ms |
1492 KB |
Output is correct |
4 |
Correct |
10 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1620 KB |
Output is correct |
2 |
Correct |
8 ms |
1620 KB |
Output is correct |
3 |
Correct |
16 ms |
2196 KB |
Output is correct |
4 |
Correct |
11 ms |
1548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2628 KB |
Output is correct |
2 |
Correct |
35 ms |
2536 KB |
Output is correct |
3 |
Correct |
18 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
4940 KB |
Output is correct |
2 |
Correct |
32 ms |
5116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
5080 KB |
Output is correct |
2 |
Correct |
63 ms |
5120 KB |
Output is correct |