#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 5;
int v[nmax], dt[nmax];
int n, vmax, v2;
namespace AINT {
struct Node {
int pmax = 0, pmin = 0, sum = 0;
Node(int val = 0): pmax(max(val, 0)), pmin(min(0, val)), sum(val) {;}
Node(int a, int b, int c): pmax(a), pmin(b), sum(c) {;}
Node operator + (const Node& x) const {
return Node(max(pmax, x.pmax + sum), min(pmin, x.pmin + sum), sum + x.sum);
}
};
Node aint[nmax * 4];
void upd(int poz, int node = 1, int cl = 1, int cr = n) {
if(cl == cr) {
aint[node] = Node(0);
return;
}
int mid = cl + cr >> 1;
if(poz <= mid)
upd(poz, 2 * node, cl, mid);
else
upd(poz, 2 * node + 1, mid + 1, cr);
aint[node] = aint[2 * node] + aint[2 * node + 1];
}
Node construct(int node = 1, int cl = 1, int cr = n) {
if(cl == cr)
return aint[node] = Node(v[cl]);
int mid = cl + cr >> 1;
return aint[node] = construct(2 * node, cl, mid) + construct(2 * node + 1, mid + 1, cr);
}
int getans() {
int l = -aint[1].pmin, r = vmax - aint[1].pmax, delta = aint[1].sum;
if(l > r && vmax + delta == v2)
return vmax;
if(l <= v2 - delta && v2 - delta <= r)
return (v2 - delta == r? vmax : v2 - delta);
return -1;
}
};
int main() {
cin >> n >> vmax >> v2;
char ch;
int lastt = 0;
for(int i = 0, t; i < n; i++) {
cin >> ch >> t;
v[i] = (ch == '-'? -1 : 1);
dt[i] = t - lastt;
lastt = t;
}
--n;
AINT::construct();
vector<int> index(n), values(n);
iota(index.begin(), index.end(), 1);
sort(index.begin(), index.end(), [&](int a, int b) { return dt[a] > dt[b]; });
iota(values.begin(), values.end(), 1);
for(auto &x : values)
x = dt[x];
sort(values.begin(), values.end(), greater<int>());
values.resize(unique(values.begin(), values.end()) - values.begin());
//for(auto x : values)
//cout << x << ' ';
//cout << '\n';
int ptr = 0, inf = 0;
for(auto x : values) {
while(ptr < index.size() && dt[index[ptr]] == x)
AINT::upd(index[ptr]), ptr++;
int temp = AINT::getans();
if(temp != -1) {
if(inf == 0)
cout << "infinity\n";
else
cout << x - 1 << ' ' << temp << '\n';
return 0;
}
inf = 1;
}
cout << "0 " << v2 << '\n';
}
Compilation message
mp3player.cpp: In function 'void AINT::upd(int, int, int, int)':
mp3player.cpp:24:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int mid = cl + cr >> 1;
| ~~~^~~~
mp3player.cpp: In function 'AINT::Node AINT::construct(int, int, int)':
mp3player.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = cl + cr >> 1;
| ~~~^~~~
mp3player.cpp: In function 'int main()':
mp3player.cpp:73:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | while(ptr < index.size() && dt[index[ptr]] == x)
| ~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
5 ms |
4932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4948 KB |
Output is correct |
2 |
Correct |
7 ms |
4948 KB |
Output is correct |
3 |
Correct |
6 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
5224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
5284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
5460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
5580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
6528 KB |
Output is correct |
2 |
Correct |
90 ms |
6544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
6552 KB |
Output is correct |
2 |
Correct |
86 ms |
6444 KB |
Output is correct |