#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[sz(V)-2])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 100055;
const int MX = 131072;
struct NOD {
NOD();
ll d, M, m;
NOD operator + (const NOD&) const;
bool f(ll T) { return m+d <= T && T <= M+d; }
};
struct SEG {
NOD dt[MX*2];
void init() { for(int i = MX*2; i--;) dt[i] = NOD(); }
void upd(int, bool);
NOD get() { return dt[1]; }
} seg;
ll A[MAXN];
int O[MAXN];
bitset<MAXN> B;
ll K, T, Ans = 0, AnsT;
int N;
void SEG::upd(int x, bool r) {
x += MX;
if(r) {
dt[x].d = 1;
dt[x].M = K-1;
dt[x].m = 0;
} else {
dt[x].d = -1;
dt[x].M = K;
dt[x].m = 1;
}
for(x >>= 1; x; x >>= 1)
dt[x] = dt[x<<1] + dt[x<<1|1];
}
NOD :: NOD() : d(0), M(K), m(0) {}
NOD NOD::operator + (const NOD &r) const {
NOD ret;
if(M + d <= r.m) {
ret.M = ret.m = K;
ret.d = r.m + r.d - K;
return ret;
}
if(m + d >= r.M) {
ret.M = ret.m = K;
ret.d = r.M + r.d - K;
return ret;
}
ret.d = d + r.d;
if(M + d >= r.M) ret.M = r.M - d;
else ret.M = M;
if(m + d <= r.m) ret.m = r.m - d;
else ret.m = m;
return ret;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> K >> T;
for(int i = 0; i < N; i++) {
char c;
cin >> c >> A[i];
B[i] = '+' == c;
}
iota(O, O+N, 0); sort(O+1, O+N, [&](int a, int b) {
return A[a]-A[a-1] < A[b]-A[b-1];
});
seg.init();
for(int s = 1, e; s < N; s = e) {
ll t = A[O[s]] - A[O[s]-1];
for(e = s+1; e < N && A[O[e]] - A[O[e]-1] == t; e++);
for(int oi = s, i; oi < e; oi++) {
i = O[oi];
seg.upd(i, B[i]);
}
NOD ret = seg.get();
if(ret.f(T)) {
Ans = t;
AnsT = T-ret.d;
}
}
{
ll mn = INFLL + 1;
for(int i = 1; i < N; i++) {
ll t = A[i]-A[i-1];
if(Ans < t && t < mn) mn = t;
}
Ans = mn-1;
}
if(INFLL <= Ans) puts("infinity");
else cout << Ans << ' ' << AnsT << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6520 KB |
Output is correct |
2 |
Correct |
8 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6520 KB |
Output is correct |
2 |
Correct |
9 ms |
6520 KB |
Output is correct |
3 |
Correct |
10 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6520 KB |
Output is correct |
2 |
Correct |
8 ms |
6520 KB |
Output is correct |
3 |
Correct |
9 ms |
6520 KB |
Output is correct |
4 |
Correct |
9 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6520 KB |
Output is correct |
2 |
Correct |
10 ms |
6520 KB |
Output is correct |
3 |
Incorrect |
10 ms |
6520 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
6776 KB |
Output is correct |
2 |
Correct |
20 ms |
6776 KB |
Output is correct |
3 |
Incorrect |
20 ms |
6808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
6776 KB |
Output is correct |
2 |
Correct |
21 ms |
6776 KB |
Output is correct |
3 |
Incorrect |
21 ms |
6776 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
6904 KB |
Output is correct |
2 |
Correct |
25 ms |
6904 KB |
Output is correct |
3 |
Correct |
27 ms |
6904 KB |
Output is correct |
4 |
Incorrect |
19 ms |
6776 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
7032 KB |
Output is correct |
2 |
Correct |
33 ms |
7032 KB |
Output is correct |
3 |
Correct |
26 ms |
7052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
7732 KB |
Output is correct |
2 |
Correct |
61 ms |
7724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
7720 KB |
Output is correct |
2 |
Correct |
60 ms |
7676 KB |
Output is correct |