This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
/*const int MOD = 998244353;
inline int lgput(int a, int b) {
int ans = 1;
while(b > 0) {
if(b & 1) ans = (1LL * ans * a) % MOD;
b >>= 1;
a = (1LL * a * a) % MOD;
}
return ans;
}
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}
inline int inv(int x) {
return lgput(x, MOD - 2);
}*/
/*int fact[], invfact[];
inline void prec(int n) {
fact[0] = 1;
for(int i = 1; i <= n; i++) {
fact[i] = (1LL * fact[i - 1] * i) % MOD;
}
invfact[n] = lgput(fact[n], MOD - 2);
for(int i = n - 1; i >= 0; i--) {
invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
}
}
inline int comb(int n, int k) {
if(n < k) return 0;
return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/
using namespace std;
struct SegTree {
struct Node {
int mn, mx;
int sum;
};
vector <Node> aint;
int n;
inline void init(int _n) {
n = _n;
aint.resize(4 * n + 1);
}
inline void refresh(int nod) {
aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
aint[nod].mn = min(aint[2 * nod + 1].mn, aint[2 * nod + 1].sum + aint[2 * nod].mn);
aint[nod].mx = max(aint[2 * nod + 1].mx, aint[2 * nod + 1].sum + aint[2 * nod].mx);
}
void update(int nod, int left, int right, int pos, int val) {
if(left == right) {
aint[nod] = {val, val, val};
}
else {
int mid = (left + right) / 2;
if(pos <= mid) update(2 * nod, left, mid, pos, val);
else update(2 * nod + 1, mid + 1, right, pos, val);
refresh(nod);
}
}
};
int main() {
#if 0
ifstream cin("A.in");
ofstream cout("A.out");
#endif
int i, n, vmax, v2;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> vmax >> v2;
vector <int> sgn(n + 1), c(n + 1);
for(i = 1; i <= n; i++) {
char ch;
cin >> ch >> c[i];
sgn[i] = (ch == '-' ? -1 : 1);
}
vector < pair <int, int> > t;
for(i = 2; i <= n; i++) {
t.push_back({c[i] - c[i - 1], i});
}
sort(t.begin(), t.end());
SegTree st; st.init(n);
int ans = t[0].first - 1; i = 0;
while(i < t.size()) {
int j = i;
while(j < t.size() && t[i].first == t[j].first) {
st.update(1, 1, n, t[j].second, sgn[t[j].second]);
j++;
}
int mn = st.aint[1].mn;
int mx = st.aint[1].mx;
bool bad = 0;
if(mn < 0) {
if(v2 == 0 || v2 - mn <= vmax) {
}
else {
bad = 1;
}
}
if(mx > 0) {
if(v2 == vmax || v2 - mx >= 0) {
}
else {
bad = 1;
}
}
if(!bad) {
ans = (j < t.size() ? t[j].first - 1 : t[i].first);
}
i = j;
}
if(ans == t.back().first) {
cout << "infinity";
return 0;
}
int v1 = 0;
for(int step = 1 << 12; step; step >>= 1) {
int cur = v1 + step;
if(cur > vmax) {
continue;
}
for(i = 2; i <= n; i++) {
if(c[i] - c[i - 1] <= ans) {
cur += sgn[i];
}
cur = min(cur, vmax);
cur = max(cur, 0);
}
if(cur <= v2) {
v1 += step;
}
}
cout << ans << " " << v1;
return 0;
}
Compilation message (stderr)
mp3player.cpp: In function 'int main()':
mp3player.cpp:123:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i < t.size()) {
~~^~~~~~~~~~
mp3player.cpp:125:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < t.size() && t[i].first == t[j].first) {
~~^~~~~~~~~~
mp3player.cpp:149:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ans = (j < t.size() ? t[j].first - 1 : t[i].first);
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |