Submission #135868

#TimeUsernameProblemLanguageResultExecution timeMemory
135868imyujinMP3 Player (CEOI10_mp3player)C++14
100 / 100
138 ms7168 KiB
#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 = V2 - seg[1].delta; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...