QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109668 | #5378. 匹配问题 | vme50 | 0 | 151ms | 28124kb | C++17 | 1.1kb | 2023-05-30 09:19:50 | 2023-05-30 09:19:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define pb push_back
const int up=5e5;
int n,m1,m2,tp,a[N],b[N],s[N],w[N],st[N],bt[N],dp[N];
vector<int> vc[N];
void upd(int x,int vl) {for(;x<=n;x+=x&-x) bt[x]+=vl;}
int qry(int x)
{
int t=0,nw=0;--x;for(;x;x-=x&-x) nw+=bt[x];
for(int i=18;i>=0;--i) if(t+(1<<i)<=n && nw>=bt[t+(1<<i)])
t+=1<<i,nw-=bt[t];return t;
}
int main()
{
scanf("%d %d %d",&n,&m1,&m2);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i) scanf("%d",&b[i]),++s[b[i]];
sort(a+1,a+n+1);for(int i=1;i<=up;++i) s[i]+=s[i-1];
for(int i=1,t,nw=-1e9;i<=n;++i)
{
w[i]=s[a[i]-1]-i+1;nw=max(nw,w[i]);
t=s[min(a[i]+m1,up)]-nw;if(t<n) vc[t+1].pb(i);
}
for(int i=1,t,l,r,nw=0;i<=n;++i)
{
upd(i,1);for(auto j:vc[i]) upd(j,-1);
while(tp && w[i]>w[st[tp]]) --tp;st[++tp]=i;
t=s[min(a[i]+m2,up)]-i;l=1;r=tp;
while(l<=r)
{
int mid=(l+r)/2;
if(t<w[st[mid]]) l=mid+1;else r=mid-1;
}nw=max(nw,st[r]);
if(nw) dp[i]=dp[t<w[i]?qry(nw):nw-1]+1;
}printf("%d\n",n-dp[n]);return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 1ms
memory: 17280kb
input:
2 2 1 1 1 1 1
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 8ms
memory: 17260kb
input:
10 200000 100000 34181 300096 24293 22680 402306 193269 438170 254676 188147 73971 216849 477743 461911 135785 467234 278230 287107 223666 124173 135091
output:
7
result:
ok single line: '7'
Test #3:
score: -4
Wrong Answer
time: 3ms
memory: 17284kb
input:
10 200000 50000 298370 136488 436143 52173 206095 140981 321188 407844 342157 193338 138374 383207 156748 442404 386749 492604 354156 229996 447123 418264
output:
7
result:
wrong answer 1st lines differ - expected: '5', found: '7'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #100:
score: 0
Wrong Answer
time: 151ms
memory: 28124kb
input:
500000 500000 10 200184 74991 71203 334998 316800 34483 120570 301054 331108 232072 189788 397143 490296 56807 361700 88818 42376 460305 371750 450351 338384 429789 426045 445029 152316 408919 188124 144966 457495 475025 225370 260510 383159 495247 54319 246245 240728 372033 439599 119720 449020 451...
output:
412983
result:
wrong answer 1st lines differ - expected: '312193', found: '412983'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%