QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457697#8831. Chemistry Classucup-team1004#RE 1ms5960kbC++171.7kb2024-06-29 13:41:412024-06-29 13:41:41

Judging History

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

  • [2024-06-29 13:41:41]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5960kb
  • [2024-06-29 13:41:41]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=2e9+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n;
ll A,B,C[N];
int dp[N],sum[N],q[N],H,T;
void Solve(){
	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=2*n;i++) scanf("%lld",&C[i]);
	sort(C+1,C+2*n+1);
	for(int i=3;i<=2*n;i+=2){
		sum[i]=sum[i-2]+(C[i]-C[i-1]<=B);
	} 
	fill(dp,dp+2*n+1,-INF);dp[0]=0;
	int R=1;H=1;T=0;
	for(int i=2;i<=2*n;i+=2){
		if(C[i]-C[i-1]<=A) dp[i]=dp[i-2];
		if(C[i]-C[i-1]<=B) dp[i]=dp[i-2]+1;
		while(H<=T&&dp[q[T]]+sum[i-1]-sum[q[T]+1]<=dp[i-2]) T--;
		q[++T]=i-2;
		while(H<=T&&C[i]-C[q[H]+1]>A) H++;
		if(H<=T) dp[i]=max(dp[i],dp[q[H]]+sum[i-1]-sum[q[H]+1]);
	}
	printf("%d\n",max(dp[2*n],-1));
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5960kb

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
Runtime Error

input:

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

output:


result: