QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#458042 | #8831. Chemistry Class | ucup-team3591# | RE | 1ms | 7816kb | C++14 | 1.6kb | 2024-06-29 15:29:15 | 2024-06-29 15:29:16 |
Judging History
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];
ll A,B,a[MAXN];
struct Tree {
int l,r,mx;
} tr[MAXN<<2];
void build(int num,int l,int r) {
tr[num].l=l,tr[num].r=r,tr[num].mx=-inf;
if(l==r)return;
build(num<<1,l,(l+r)>>1),build(num<<1|1,(l+r+2)>>1,r);
}
void update(int num,int x,int y) {
if(tr[num].l==tr[num].r) {
tr[num].mx=y;
return;
}
update(num<<1|(x>tr[num<<1].r),x,y);
tr[num].mx=max(tr[num<<1].mx,tr[num<<1|1].mx);
}
int query(int num,int l,int r) {
if(l<=tr[num].l&&tr[num].r<=r) return tr[num].mx;
if(r<=tr[num<<1].r) return query(num<<1,l,r);
if(tr[num<<1].r<l)return query(num<<1|1,l,r);
return max(query(num<<1,l,r),query(num<<1|1,l,r));
}
inline void solve() {
scanf("%d%lld%lld",&n,&A,&B),m=n<<1;
build(1,0,n);
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]);
// }
update(1,0,0);
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,a+m+1,a[i<<1]-A)-a)>>1;
f[i]=max(f[i],s[i-1]+query(1,j,i-1));
update(1,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
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7816kb
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...