Submission #135765

# Submission time Handle Problem Language Result Execution time Memory
135765 2019-07-24T10:44:15 Z imyujin MP3 Player (CEOI10_mp3player) C++14
60 / 100
147 ms 6652 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

#define fi first
#define se second

const int MAXN = 100005;

char B[MAXN];
int T[MAXN];
pii seg[4 * MAXN];
int lazy[4 * MAXN];
int ts[MAXN];

void updseg(int idx, int l, int r, int x, int y, int z) {
	if(x <= l && r <= y) {
		seg[idx].fi += z;
		seg[idx].se += z;
		lazy[idx] += z;
	}
	else if(l <= y && x <= r) {
		int m = (l + r) / 2;
		updseg(idx * 2, l, m, x, y, z);
		updseg(idx * 2 + 1, m + 1, r, x, y, z);
		seg[idx].fi = max(seg[idx * 2].fi, seg[idx * 2 + 1].fi) + lazy[idx];
		seg[idx].se = min(seg[idx * 2].se, seg[idx * 2 + 1].se) + lazy[idx];
	}
}

int main() {
	int N, Vm, V2;
	int ansT, ansV;

	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 = 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");

	ansT = T[ts[0]] - 1;
	ansV = V2;
	int sum = V2;
	for(int i = 1; i < 4 * N; i++) seg[i] = make_pair(V2, V2);
	for(int i = 0; i < N - 1; i++) {
		updseg(1, 0, N - 1, 0, ts[i], B[ts[i]] == '+' ? -1 : 1);
		sum += B[ts[i]] == '+' ? -1 : 1;
		if((i == N - 2 || T[ts[i]] != T[ts[i + 1]]) && seg[1].fi <= Vm && seg[1].se >= 0) {
			ansT = i == N - 2 ? -1 : (T[ts[i + 1]] - 1);
			ansV = seg[1].fi == Vm ? Vm : sum;
		}
		//printf("sum = %d, seg[1] = (%d, %d), ansT = %d, ansV = %d\n", sum, seg[1].fi, seg[1].se, ansT, ansV);
	}

	if(ansT == -1) cout << "infinity";
	else cout << ansT << " " << ansV;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 420 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 7 ms 632 KB Output is correct
3 Correct 6 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 2184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 3228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 147 ms 6452 KB Output is correct
2 Correct 127 ms 6652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 6524 KB Output is correct
2 Correct 129 ms 6648 KB Output is correct