QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353431#3050. Kuru Kuru SushiKevin5307WA 567ms5708kbC++202.5kb2024-03-14 08:51:502024-03-14 08:51:52

Judging History

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

  • [2024-03-14 08:51:52]
  • 评测
  • 测评结果:WA
  • 用时:567ms
  • 内存:5708kb
  • [2024-03-14 08:51:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,q;
ll w[100100],psum[100100];
int s[100100],t[100100],fa[100100];
ll f[100100],g[100100];
inline int anc(int x)
{
	while(fa[x]!=x) x=fa[x]=fa[fa[x]];
	return x;
}
mt19937_64 rnd(20210448);
void _sort(vector<int> vec,vector<int> &sorted)
{
	if(!vec.size()) return ;
	int ind=rnd()%vec.size();
	int x=vec[ind];
	int a=min(s[x],t[x]),b=max(s[x],t[x]);
	vector<int> v1,v2;
	for(auto y:vec)
		if(y!=x)
		{
			if(a<=s[y]&&s[y]<=b&&a<=t[y]&&t[y]<=b)
				v1.push_back(y);
			else
			{
				assert(s[y]<=a||s[y]>=b);
				assert(t[y]<=a||t[y]>=b);
				v2.push_back(y);
			}
		}
	sort(v1.begin(),v1.end(),[&](int u,int v)
	{
		if(s[x]<t[x])
			return pair<int,int>(s[u]-s[x],t[x]-t[u])>pair<int,int>(s[v]-s[x],t[x]-t[v]);
		return pair<int,int>(t[u]-t[x],s[x]-s[u])>pair<int,int>(t[v]-t[x],s[x]-s[v]);
	});
	for(auto x:v1)
		sorted.push_back(x);
	sorted.push_back(x);
	sort(v2.begin(),v2.end(),[&](int u,int v)
	{
		if(s[x]<t[x])
			return pair<int,int>((s[x]-s[u]+n)%n,(t[u]-t[x]+n)%n)<pair<int,int>((s[x]-s[v]+n)%n,(t[v]-t[x]+n)%n);
		return pair<int,int>((t[x]-t[u]+n)%n,(s[u]-s[x]+n)%n)<pair<int,int>((t[x]-t[v]+n)%n,(s[v]-s[x]+n)%n);
	});
	for(auto x:v2)
		sorted.push_back(x);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
		cin>>w[i];
		psum[i]=psum[i-1]+w[i];
	}
	for(int i=1;i<=q;i++)
		cin>>s[i]>>t[i];
	for(int i=1;i<=q;i++)
		for(int j=i+1;j<=q;j++)
		{
			int a=min(s[i],t[i]),b=max(s[i],t[i]);
			if((s[j]>a&&s[j]<b)^(t[j]>a&&t[j]<b))
				fa[anc(i)]=anc(j);
			else if((a>=max(s[j],t[j])||b<=min(s[j],t[j]))^(s[j]<t[j])^(s[i]<t[i]))
				fa[anc(i)]=anc(j);
		}
	vector<int> vec,sorted;
	for(int i=1;i<=q;i++)
		if(fa[i]==i)
			vec.push_back(i);
	_sort(vec,sorted);
	for(int i=1;i<=q;i++)
		if(s[i]<t[i])
		{
			f[anc(i)]+=psum[t[i]]-psum[s[i]];
			g[anc(i)]+=psum[n]-psum[t[i]]+psum[s[i]];
		}
		else
		{
			f[anc(i)]+=psum[n]-psum[s[i]]+psum[t[i]];
			g[anc(i)]+=psum[s[i]]-psum[t[i]];
		}
	if(s[sorted[0]]<t[sorted[0]])
	{
		ll tot=0;
		ll ans=0x3f3f3f3f3f3f3f3f;
		for(auto x:sorted)
			tot+=g[x];
		ans=tot;
		for(auto x:sorted)
		{
			tot+=f[x]-g[x];
			ans=min(ans,tot);
		}
		cout<<ans<<endl;
	}
	else
	{
		ll tot=0;
		ll ans=0x3f3f3f3f3f3f3f3f;
		for(auto x:sorted)
			tot+=f[x];
		ans=tot;
		for(auto x:sorted)
		{
			tot+=g[x]-f[x];
			ans=min(ans,tot);
		}
		cout<<ans<<endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 567ms
memory: 5708kb

input:

100000 13965
6828 987 32 151 5 44713 513 369 1934 1913 90374 4 336 286 4116 59505 8184 42405 84543 319 140 2888 6181 1 32 4535 39 1781 11 2 59002 12 1001 895 9 12 26 9497 15169 40 197 8 793 6915 40 47 10 35 3 106 3 3348 5 540 3269 439 402 1309 1165 71 91007 58683 944 11098 1976 5267 12974 170 2161 2...

output:

3132882365143

result:

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