Submission #135385

# Submission time Handle Problem Language Result Execution time Memory
135385 2019-07-24T04:35:58 Z 윤교준(#3250) MP3 Player (CEOI10_mp3player) C++14
60 / 100
62 ms 4348 KB
#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 INFST (2147483000)
#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();
	int d, M, m;
	NOD operator + (const NOD&) const;
	bool f(int 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;

int A[MAXN], O[MAXN];
bitset<MAXN> B;

int N, K, T, Ans = 0, AnsT;

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, t; s < N; s = e) {
		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;
		}
	}

	{
		int mn = INFST+1;
		for(int i = 1, t; i < N; i++) {
			t = A[i]-A[i-1];
			if(Ans < t && t < mn) mn = t;
		}
		Ans = mn-1;
	}
	if(INFST <= Ans) puts("infinity");
	else cout << Ans << ' ' << AnsT << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3448 KB Output is correct
2 Correct 7 ms 3448 KB Output is correct
3 Correct 7 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 6 ms 3448 KB Output is correct
4 Correct 6 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3448 KB Output is correct
2 Correct 8 ms 3448 KB Output is correct
3 Incorrect 8 ms 3508 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3656 KB Output is correct
2 Correct 17 ms 3700 KB Output is correct
3 Incorrect 17 ms 3832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3704 KB Output is correct
2 Correct 19 ms 3832 KB Output is correct
3 Incorrect 18 ms 3832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3704 KB Output is correct
2 Correct 21 ms 3832 KB Output is correct
3 Correct 24 ms 3960 KB Output is correct
4 Incorrect 17 ms 3960 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3832 KB Output is correct
2 Correct 29 ms 3952 KB Output is correct
3 Correct 22 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 4344 KB Output is correct
2 Correct 54 ms 4316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 4348 KB Output is correct
2 Correct 57 ms 4344 KB Output is correct