QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747914#4583. Concerto de Pandemicshinonome_ena#TL 1353ms68140kbC++232.4kb2024-11-14 18:44:092024-11-14 18:44:10

Judging History

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

  • [2024-11-14 18:44:10]
  • 评测
  • 测评结果:TL
  • 用时:1353ms
  • 内存:68140kb
  • [2024-11-14 18:44:09]
  • 提交

answer

//#define LOCAL

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1557557
#define MAXS 20
#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];
ll sp[MAX][MAXS];
int ban[MAX];
int pv[MAX];
int ne[MAX];
int ichk[MAX];
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=N*2;i>=0;i--) smx[i] = min(smx[i], smx[i+1]);
	for(i=1;i<=N;i++) sp[i][0] = smx[i]-i;
	for(i=1;i<=N;i++) DEBUG(sp[i][0]<<' ');
	DEBUG(ln);
	for(j=1;j<MAXS;j++) {
		for(i=1;i<=N;i++) {
			int n = (i+sp[i][j-1]-1)%N;
			n++;
			sp[i][j] = sp[i][j-1]+sp[n][j-1];
		}
	}
	for(i=1;i<=N;i++) {
		int v=i;
		ll sum=0;
		for(j=0;j<MAXS;j++) {
			if(P>>j&1){
				sum+=sp[v][j];
				int n = (v+sp[v][j]-1)%N;
				n++;
				v = n;
			}
		}
		if(sum>=N) 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: 4ms
memory: 24060kb

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: 24144kb

input:

8 1 3 5
1 5
4 2 7

output:

0

result:

ok single line: '0'

Test #3:

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

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: 24200kb

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1353ms
memory: 68140kb

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: -100
Time Limit Exceeded

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:


result: