QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756712#4583. Concerto de PandemicasdfsdfWA 1484ms59840kbC++233.2kb2024-11-16 21:40:212024-11-16 21:40:23

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 21:40:23]
  • 评测
  • 测评结果:WA
  • 用时:1484ms
  • 内存:59840kb
  • [2024-11-16 21:40:21]
  • 提交

answer

//#define LOCAL

#include <bits/stdc++.h>
#pragma GCC optimize("O0")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
#define MAX 1557557
#define MAXS 18
#define ln '\n'

#ifdef LOCAL
#define DEBUG(a) cout<<a
#else
#define DEBUG(a) 1557
#endif

int C[MAX];
int T[MAX];
ll TS[MAX];
int D[MAX];
int N, M, K, P;
int L[MAX];
int R[MAX];
int smx[MAX];
int nxt[MAX];
int sp[MAX][MAXS];
int ban[MAX];
int pv[MAX];
int ne[MAX];
int ichk[MAX];
int psum[MAX];
inline int dis(int l, int r) {
	if (l <= r) return r - l;
	else return r + N - l;
}
bool chk(ll m) {
	DEBUG(m << ln);
	int i, j;
	for (i = 1; i <= K; i++) {
		int loc = D[i] + N;
		int ind1, ind2;
		ind1 = lower_bound(TS + 1, TS + N * 3 + 1, TS[loc - 1] - m) - TS + 1;
		ind2 = upper_bound(TS + 1, TS + N * 3 + 1, TS[loc] + m) - TS - 1;
		L[i] = (ind1 - 1) % N + 1;
		R[i] = (ind2 - 1) % N + 1;
		if (dis(L[i], D[i]) + dis(D[i], R[i]) >= N - 1) {
			ichk[i] = 1;
		}
		else {
			ichk[i] = 0;
			L[i] = ne[L[i]];
			R[i] = pv[R[i]];
		}
	}
	for (i = 1; i <= N * 2 + 1; i++) smx[i] = N * 3;
	for (i = 1; i <= K; i++) {
		if (ichk[i]) continue;
		int l, r;
		l = L[i];
		r = R[i];
		if (l > r) r += N;
		smx[L[i] - 1] = min(smx[L[i] - 1], r);
		smx[L[i] - 1 + N] = min(smx[L[i] - 1 + N], r + N);
		//DEBUG(L[i]<<' '<<R[i]<<ln);
	}
	for (i = 1; i <= K; i++) {
		if (L[i] <= R[i]) psum[L[i]]++, psum[R[i] + 1]--;
		else {
			psum[L[i]]++;
			psum[1]++;
			psum[R[i] + 1]--;
		}
	}
	for (i = 1; i <= N; i++) psum[i] += psum[i - 1];
	int chk = 0;
	for (i = 1; i <= N; i++) if (psum[i] == K) chk = 1;
	for (i = 1; i <= N; i++) psum[i] = 0;
	if (chk) return true;
	for (i = N * 2; i >= 0; i--) smx[i] = min(smx[i], smx[i + 1]);
	for (i = 1; i <= N; i++) {
		nxt[i] = sp[i][0] = (smx[i] - 1) % N + 1;
		if (sp[i][0] < i) sp[i][0] = N + 1;
	}
	sp[N + 1][0] = N + 1;
	for (j = 1; j < MAXS; j++) for (i = 1; i <= N + 1; i++) sp[i][j] = sp[sp[i][j - 1]][j - 1];
	for (i = 1; i <= N; i++) {
		if (ban[i]) continue;
		int v = i;
		int sum = 0;
		for (j = MAXS - 1; j >= 0; j--) if (sp[v][j] != N + 1) sum += 1 << j, v = sp[v][j];
		sum++;
		v = nxt[v];
		for (j = MAXS - 1; j >= 0; j--) if (sp[v][j] < i) sum += 1 << j, v = sp[v][j];
		sum++;
		if (sum <= P) return true;
	}
	return false;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> M >> K >> P;
	int i;
	ll l, r;
	l = -1;
	r = N;
	for (i = 1; i <= M; i++) cin >> C[i] >> T[i], r += T[i], ban[C[i]] = 1, ban[C[i] + N] = 1;
	for (i = 1; i <= N * 2; i++) {
		if (ban[i]) pv[i] = pv[i - 1];
		else pv[i] = i;
	}
	for (i = N * 2; i >= 1; i--) {
		if (ban[i]) ne[i] = ne[i + 1];
		else ne[i] = i;
	}
	for (i = 1; i <= N * 2; i++) {
		if (!ne[i]) ne[i] = ne[i + N];
		if (!pv[i]) pv[i] = pv[i + N];
		ne[i]--;
		pv[i]--;
		ne[i] %= N;
		pv[i] %= N;
		ne[i]++;
		pv[i]++;
	}
	for (i = 1; i <= K; i++) cin >> D[i];
	for (i = 1; i <= M; i++) TS[C[i]] = TS[C[i] + N] = TS[C[i] + N * 2] = T[i];
	for (i = 1; i <= N * 3; i++) TS[i] += TS[i - 1];
	for (i = 1; i <= N * 3; i++) TS[i] += i;
	while (r - l > 1) {
		ll m = l + r >> 1;
		if (chk(m)) r = m;
		else l = m;
	}
	cout << r;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 26144kb

input:

10 4 3 2
1 2
4 4
6 2
7 5
2 5 8

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 26208kb

input:

8 1 3 5
1 5
4 2 7

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 3ms
memory: 26200kb

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 22112kb

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 776ms
memory: 57232kb

input:

190976 113222 55610 23475
51263 120558
10007 171596
46671 108981
117183 169457
18187 84735
149298 124718
79376 129184
28117 76880
109791 87521
114840 59510
38014 178362
41701 11344
27561 192741
173835 54534
71368 76692
122745 95537
152595 158352
43901 162441
98927 105784
22484 96000
19443 113614
370...

output:

170531

result:

ok single line: '170531'

Test #6:

score: 0
Accepted
time: 1484ms
memory: 59840kb

input:

198722 26425 169256 110599
33948 74442
51729 66300
40369 173859
42274 73043
117803 108716
149794 151005
147161 2675
148063 166634
132585 51612
141999 182365
32951 159790
120932 290
82655 150138
49337 10396
171146 129572
33311 193079
195115 171691
180568 77905
65397 110312
156436 149966
9377 55490
12...

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 496ms
memory: 55108kb

input:

200000 150000 50000 24998
187150 200000
81420 200000
167617 200000
100616 200000
135362 200000
156943 200000
83069 200000
48837 200000
179969 200000
138130 200000
133131 200000
196045 200000
169575 200000
163857 200000
106717 200000
191966 200000
131394 200000
145647 200000
160212 200000
75181 20000...

output:

200002

result:

ok single line: '200002'

Test #8:

score: 0
Accepted
time: 495ms
memory: 57384kb

input:

200000 150000 50000 2
99352 200000
85760 200000
126279 200000
78681 200000
191980 200000
123278 200000
90780 200000
183926 200000
92668 200000
92156 200000
157074 200000
104604 200000
87593 200000
183454 200000
38009 200000
132806 200000
96071 200000
135445 200000
123768 200000
80039 200000
199215 2...

output:

1250012500

result:

ok single line: '1250012500'

Test #9:

score: 0
Accepted
time: 27ms
memory: 41160kb

input:

200000 199999 1 1
44417 200000
47743 200000
134710 200000
118852 200000
9605 200000
150296 200000
80589 200000
3336 200000
66496 200000
90172 200000
190899 200000
3355 200000
107595 200000
111949 200000
146872 200000
72419 200000
115626 200000
127077 200000
173509 200000
194749 200000
109608 200000
...

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 811ms
memory: 50456kb

input:

200000 100000 100000 25746
186550 200000
85622 200000
21024 200000
59750 200000
76456 200000
87534 200000
76522 200000
103422 200000
165806 200000
138372 200000
166050 200000
176354 200000
15168 200000
69928 200000
187102 200000
130486 200000
182278 200000
161502 200000
95032 200000
119864 200000
17...

output:

400004

result:

ok single line: '400004'

Test #11:

score: 0
Accepted
time: 363ms
memory: 50784kb

input:

200000 199990 10 9
185044 200000
96615 200000
172973 200000
82849 200000
162889 200000
59668 200000
20522 200000
193263 200000
70559 200000
140931 200000
147680 200000
26312 200000
133330 200000
74332 200000
149589 200000
61277 200000
173461 200000
152403 200000
174666 200000
56706 200000
9288 20000...

output:

3865019326

result:

ok single line: '3865019326'

Test #12:

score: -100
Wrong Answer
time: 145ms
memory: 55408kb

input:

200000 199998 2 1
67932 200000
165398 200000
653 200000
12879 200000
179014 200000
173052 200000
19237 200000
31754 200000
83892 200000
67089 200000
172429 200000
20736 200000
19809 200000
195941 200000
165861 200000
192485 200000
50670 200000
154401 200000
183669 200000
160442 200000
96158 200000
4...

output:

29999950000

result:

wrong answer 1st lines differ - expected: '19999900000', found: '29999950000'