QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#44465#4583. Concerto de PandemiceyiigjknWA 0ms3796kbC++142.9kb2022-08-17 18:20:092022-08-17 18:20:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-17 18:20:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2022-08-17 18:20:09]
  • 提交

answer

# include <bits/stdc++.h>
# define cur_time() chrono::steady_clock::now()
# define clock() chrono::duration<double>(cur_time()-BEGIN).count()
using namespace std;
typedef long long ll;
const int INF=1e6;
int n,m,K,lim,a[200010],b[200010],d[200010],nxt[20][200010],len[20][200010],cnt[200010],cnt1[200010];
ll sum[200010];
pair<int,int> upd[400010];
int add(int x,int y){return (x+=y)<INF?x:INF;}
int goleft(int x,int k){return (x-=k)>0?x:x+m;}
int goright(int x,int k){return (x+=k)<=m?x:x-m;}
ll 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;}
int dis(int x,int y){return x<y?y-x:m-x+y;}
void update(int x,int y){for(int i=x;i<=m;i+=i&-i) cnt[i]+=y;}
int query(int x)
{
	int ans=cnt1[x];
	for(int i=x;i;i-=i&-i) ans+=cnt[i];
	return ans;
}
int getle(int l,int r)
{
	if(l>r) return 0;
	int cur=-query(--l),t=0,s;
	for(int i=__lg(r);i>=0;i--)
		if(t+(1<<i)<=r && cur+(s=cnt[t+(1<<i)]+cnt1[t+(1<<i)]-cnt1[t])<=0)
			cur+=s,t+=1<<i;
	return (++t)<=r?t:0;
}
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;
			cnt1[R]++;
			upd[++tot]={R+1,R};
			upd[++tot]={L,-R};
		}
		else
		{
			if(t>R && t<L) continue;
			upd[++tot]={R+1,R};
			upd[++tot]={L,-R};
		}
	}
	for(int i=1;i<=m;i++) cnt1[i]+=cnt1[i-1];
	sort(upd+1,upd+tot+1);
	for(int i=1,j=1;i<=m;i++)
	{
		for(;j<=tot && upd[j].first<=i;j++)
		{
			int x=upd[j].second;
			if(x>0) update(x,1);
			else update(-x,-1);
		}
		nxt[0][i]=getle(i+1,m);
		if(!nxt[0][i]) nxt[0][i]=getle(1,i-1);
	}
	for(int i=1;i<=m+1;i++) cnt[i]=cnt1[i]=0;
	for(int i=1;i<=m;i++)
		if(!nxt[0][i]) return 1;
		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;
	auto BEGIN=cur_time();
	cin>>n>>m>>K>>lim;
	ll l=1,r=n,mid;
	for(int i=1;i<=m;i++) scanf("%d%d",&x,&y),r+=(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;
		if(clock()>1.5) break;
	}
	if(l==r) cout<<l<<endl;
	else cout<<l<<" , "<<r<<endl;
	return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3704kb

input:

8 1 3 5
1 5
4 2 7

output:

1

result:

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