QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#458008#8831. Chemistry Classucup-team3591#WA 77ms7832kbC++141.2kb2024-06-29 15:17:352024-06-29 15:17:36

Judging History

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

  • [2024-06-29 15:17:36]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:7832kb
  • [2024-06-29 15:17:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=200005,inf=0x3f3f3f3f;
int n,m,f[MAXN],s[MAXN],tr[MAXN];
ll A,B,a[MAXN];
inline void add(int x,int y) {
	for(; x; x&=x-1) tr[x]=max(tr[x],y);
}
inline int query(int x) {
	int ans=0;
	for(; x<=n; x+=x&-x) ans=max(ans,tr[x]);
	return ans;
}
inline void solve() {
	scanf("%d%lld%lld",&n,&A,&B),m=n<<1;
	for(int i=1; i<=n; ++i) tr[i]=-inf;
	for(int i=1; i<=m; ++i) scanf("%lld",&a[i]);
	stable_sort(a+1,a+m+1);
	for(int i=1; i<=m; i+=2)
		if(a[i+1]-a[i]>=A) {
			printf("-1\n");
			return;
		}
//	for(int i=2; i<=m; i+=2) {
//		s[i]=s[i-2]+(i==m?0:(a[i+1]-a[i]<=B));
//		f[i]=f[i-2]+(a[i]-a[i-1]<=B);
//		for(int j=0; j<=i-2; ++j)
//			if(a[i]-a[j+1]<=A)
//				f[i]=max(f[i],f[j]+s[i-2]-s[j]);
//	}
	for(int i=1; i<=n; ++i) {
		s[i]=s[i-1]+(i==n?0:(a[i<<1|1]-a[i<<1]<=B));
		f[i]=f[i-1]+(a[i<<1]-a[(i<<1)-1]<=B);
		int j=(lower_bound(a+1,a+m+1,a[i<<1]-A)-a)>>1;
		f[i]=max(f[i],s[i-1]+query(max(j,1)));
		if(j==0) f[i]=max(f[i],s[i-1]+f[0]-s[0]);
		add(i,f[i]-s[i]);
	}
	printf("%d\n",f[n]);
}
int main() {
	int t;
	scanf("%d",&t);
	while(t--)solve();
	return 0;
}
/*
4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20

output:

-1
2
1
4

result:

ok 4 number(s): "-1 2 1 4"

Test #2:

score: -100
Wrong Answer
time: 77ms
memory: 7832kb

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:

199995

result:

wrong answer 1st numbers differ - expected: '0', found: '199995'