QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#324063#8016. 不休陀螺lgvc10 290ms113288kbC++141.5kb2024-02-10 15:38:312024-02-10 15:38:32

Judging History

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

  • [2024-02-10 15:38:32]
  • 评测
  • 测评结果:10
  • 用时:290ms
  • 内存:113288kb
  • [2024-02-10 15:38:31]
  • 提交

answer

#include <bits/stdc++.h>
long long qb[1000009],s3[1000009];
int N,E,a[1000009],tk,b[1000009],st[1000009][20],sl[1000009],sg[1000009];
int qm(int l,int r) {
	return std::max(st[l][sl[r-l+1]],st[r-(1<<sl[r-l+1])+1][sl[r-l+1]]);
}
#define lb(n) ((n)&(-(n)))
void up(int n,int v) {
	while(n<=tk+1) {
		sg[n]+=v;
		n+=lb(n);
	}
}
int qr(int n) {
	int as=0;
	while(n) {
		as+=sg[n];
		n-=lb(n);
	}
	return as;
}
signed main(void) {
	scanf("%d %d",&N,&E);
	for(int i=1;i<=N;i++) {
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=N;i++) {
		scanf("%d",&b[i]);
		st[i][0]=std::min(a[i],b[i]);
		s3[i]=s3[i-1]+a[i]-b[i];
		qb[i]=s3[i];
	}
	std::sort(qb,qb+N+1);
	tk=std::unique(qb,qb+N+1)-qb;
	for(int i=0;i<=N;i++) {
		s3[i]=std::lower_bound(qb,qb+tk+1,s3[i])-qb+1;
	}
	for(int i=2;i<=N;i++) sl[i]=sl[i>>1]+1;
	for(int i=1;i<=19;i++) {
		for(int j=1;j<=N;j++) {
			st[j][i]=std::max(st[j][i-1],st[j+(1<<i-1)][i-1]);
		}
	}
/*	long long ans2=0;
	for(int i=1;i<=N;i++) {
		long long s1=0,s2=0,s3=0;
		for(int j=i;j<=N;j++) {
			s1+=std::max(a[j]-b[j],0);
			s2=std::max(s2,1ll*std::min(a[j],b[j]));
			s3+=a[j]-b[j];
			if(s1+s2<=E&&s3<=0) ans2++;
		}
	}
	printf("%lld\n",ans2);*/
	int q=0;
	long long s1=0,ans=0;
	for(int i=1;i<=N;i++) {
		if(q<i) q=i-1;
		while(q<N) {
			if(s1+std::max(a[q+1]-b[q+1],0)+qm(i,q+1)<=E) {
				q++;
				s1+=std::max(a[q]-b[q],0);
				up(s3[q],1);
			} else break;
		}
		ans+=q-i+1;
		if(q>=i) s1-=std::max(a[i]-b[i],0),up(s3[i],-1);
	}
	printf("%lld",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 14240kb

input:

5000 939255322
47952340 92329911 61615795 40122788 47258178 29326499 9822850 42767362 86610596 60318756 52429688 87502511 50194916 96377063 74322128 19511341 28794957 53813791 79075058 35555414 5249682 45174421 101856091 25257909 94697470 45853817 82945426 108415825 41731145 87133877 75167193 598696...

output:

3520115

result:

wrong answer 1st lines differ - expected: '1846283', found: '3520115'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 290ms
memory: 95420kb

input:

774484 763692678
47702350 34856775 28447988 4178162 45063720 8232662 36845607 27038945 44858289 5952529 39159657 21628528 60199611 5544054 59216841 39287087 43449994 20034684 56440004 11583811 44465341 32347476 49196492 22731571 9481143 11726859 35167370 23103544 23109378 38822668 29778048 58004104 ...

output:

245208923

result:

wrong answer 1st lines differ - expected: '124023429', found: '245208923'

Subtask #3:

score: 10
Accepted

Test #10:

score: 10
Accepted
time: 280ms
memory: 113288kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

99999500000

result:

ok single line: '99999500000'

Test #11:

score: 0
Accepted
time: 213ms
memory: 98932kb

input:

829382 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

68786703753

result:

ok single line: '68786703753'

Test #12:

score: 0
Accepted
time: 187ms
memory: 89468kb

input:

715382 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

51176496753

result:

ok single line: '51176496753'

Test #13:

score: 0
Accepted
time: 48ms
memory: 41784kb

input:

212234 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

4504051185

result:

ok single line: '4504051185'

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 24ms
memory: 38952kb

input:

174457 888
0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1...

output:

614760743

result:

wrong answer 1st lines differ - expected: '329807918', found: '614760743'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 128ms
memory: 53512kb

input:

343922 773619774
0 8292680 5684115 0 0 170056 5385926 0 0 1588575 0 0 10947891 170867 35145 0 0 103085 7231562 0 0 0 0 11128944 0 4872226 0 2879880 7565181 0 8631665 0 5162564 9511835 514165 0 9628987 14357934 174784 0 12400154 0 0 8198218 0 8496060 0 0 0 0 10376826 3523227 0 14548249 0 6840016 0 0 ...

output:

67479224

result:

wrong answer 1st lines differ - expected: '36107528', found: '67479224'

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 170ms
memory: 69000kb

input:

468676 582048177
6889433 7293342 20676061 15545414 4911497 12352219 8921719 1705801 19695926 25259227 2645394 17518171 19753552 9449377 982708 22479531 1267985 15594372 20685422 9627290 2017543 6459134 18614020 16206301 14962487 12932255 7101003 29140540 6479702 20607124 2540287 15565156 20274141 11...

output:

685504335

result:

wrong answer 1st lines differ - expected: '353280708', found: '685504335'