QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#44471 | #4583. Concerto de Pandemic | eyiigjkn | WA | 586ms | 12716kb | C++14 | 2.5kb | 2022-08-17 20:16:32 | 2022-08-17 20:16:33 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=1e6;
int n,m,K,lim,a[200010],b[200010],d[200010],fa[200010],nxt[20][200010],len[20][200010];
ll sum[200010];
struct Update
{
int l,r,v;
Update(int l=0,int r=0,int v=0):l(l),r(r),v(v){}
bool operator<(const Update &t)const{return v<t.v;}
}upd[400010];
inline int add(int x,int y){return (x+=y)<INF?x:INF;}
inline int goleft(int x,int k){return (x-=k)>0?x:x+m;}
inline int goright(int x,int k){return (x+=k)<=m?x:x-m;}
inline int calc(int l,int r){return l<=r?sum[r]-sum[l-1]+r-l:sum[n]-sum[l-1]+sum[r]+n-l+r;}
inline int dis(int x,int y){return x<y?y-x:m-x+y;}
int getF(int u){return u==fa[u]?u:fa[u]=getF(fa[u]);}
bool judge(ll x)
{
int tot=0;
for(int i=1;i<=K;i++)
{
int t=b[d[i]],l=0,r=m-1,mid,L,R;
while(l<r)
{
mid=(l+r+1)/2;
if(calc(a[goleft(t,mid)],d[i])<=x) l=mid;
else r=mid-1;
}
L=goleft(t,l);l=0;r=m-1;
while(l<r)
{
mid=(l+r+1)/2;
if(calc(d[i],a[goright(t,mid)])<=x) l=mid;
else r=mid-1;
}
R=goright(t,l);
if(L<=R)
{
if(t<L || t>R) continue;
if(L>1) upd[++tot]=Update(1,L-1,R);
if(R<m) upd[++tot]=Update(R+1,m,R+m);
}
else
{
if(t>R && t<L) continue;
if(L-R>=2) upd[++tot]=Update(R+1,L-1,R+m);
}
}
sort(upd+1,upd+tot+1);
iota(fa+1,fa+m+2,1);
for(int i=1;i<=tot;i++)
{
int l=upd[i].l,r=upd[i].r,v=upd[i].v;
for(int j=getF(l);j<=r;j=getF(j+1))
{
nxt[0][j]=(v<=m?v:v-m);
fa[j]=j+1;
}
}
for(int i=getF(1);i<=m;i=getF(i+1)) nxt[0][i]=i;
for(int i=1;i<=m;i++)
if(nxt[0][i]==i) len[0][i]=INF;
else len[0][i]=dis(i,nxt[0][i]);
int mx=1;
for(;;mx++)
{
bool flag=0;
int *_nxt=nxt[mx],*__nxt=nxt[mx-1],*_len=len[mx],*__len=len[mx-1];
for(int i=1;i<=m;i++)
{
_nxt[i]=__nxt[__nxt[i]];
_len[i]=add(__len[i],__len[__nxt[i]]);
flag|=(_len[i]<m);
}
if(!flag || mx==17) break;
}
for(int i=1;i<=m;i++)
{
int u=i,cur=0,cnt=1;
for(int j=mx;j>=0 && cnt<=lim;j--)
if(cur+len[j][u]<m)
{
cur+=len[j][u];
cnt+=1<<j;
u=nxt[j][u];
}
if(cnt<=lim) return 1;
}
return 0;
}
int main()
{
int x,y;
ll l=0,r=5e6,mid;
cin>>n>>m>>K>>lim;
for(int i=1;i<=m;i++) scanf("%d%d",&x,&y),sum[x]=y;
m=0;
for(int i=1;i<=n;i++)
if(!sum[i])
a[b[i]=++m]=i;
for(int i=1;i<=n;i++) sum[i]+=sum[i-1];
for(int i=1;i<=K;i++) scanf("%d",&d[i]);
while(l<r)
{
mid=(l+r)/2;
if(judge(mid)) r=mid;
else l=mid+1;
}
cout<<l<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8688kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 8660kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 8876kb
input:
5 2 2 1 1 14 2 14 3 5
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 8420kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 586ms
memory: 12716kb
input:
190976 113222 55610 23475 51263 120558 10007 171596 46671 108981 117183 169457 18187 84735 149298 124718 79376 129184 28117 76880 109791 87521 114840 59510 38014 178362 41701 11344 27561 192741 173835 54534 71368 76692 122745 95537 152595 158352 43901 162441 98927 105784 22484 96000 19443 113614 370...
output:
0
result:
wrong answer 1st lines differ - expected: '170531', found: '0'