QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#352336#7993. 哈密顿Kevin5307WA 1ms7728kbC++201.8kb2024-03-13 09:55:572024-03-13 09:55:57

Judging History

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

  • [2024-03-13 09:55:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7728kb
  • [2024-03-13 09:55:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
mt19937_64 rnd(20210448);
ull prior[200200];
int ls[200200],rs[200200],siz[200200],tot;
ll sum[200200],val[200200];
void pushup(int x)
{
	siz[x]=siz[ls[x]]+siz[rs[x]]+1;
	sum[x]=sum[ls[x]]+sum[rs[x]]+val[x];
}
int merge(int a,int b)
{
	if(!a||!b) return a+b;
	if(prior[a]>prior[b])
	{
		rs[a]=merge(rs[a],b);
		pushup(a);
		return a;
	}
	else
	{
		ls[b]=merge(a,ls[b]);
		pushup(b);
		return b;
	}
}
void sSplit(int x,int s,int &a,int &b)
{
	if(!x)
	{
		a=b=0;
		return ;
	}
	if(siz[ls[x]]>=s)
	{
		b=x;
		sSplit(ls[x],s,a,ls[b]);
		pushup(b);
	}
	else
	{
		a=x;
		sSplit(rs[x],s-siz[ls[x]]-1,rs[a],b);
		pushup(a);
	}
}
void vSplit(int x,ll v,int &a,int &b)
{
	if(!x)
	{
		a=b=0;
		return ;
	}
	if(val[x]<=v)
	{
		a=x;
		vSplit(rs[x],v,rs[a],b);
		pushup(a);
	}
	else
	{
		b=x;
		vSplit(ls[x],v,a,ls[b]);
		pushup(b);
	}
}
ll aa[100100],bb[100100];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>aa[i]>>bb[i];
	vector<ll> vec;
	for(int i=1;i<=n;i++)
		vec.push_back(aa[i]);
	for(int i=1;i<=n;i++)
		vec.push_back(bb[i]);
	sort(vec.begin(),vec.end());
	int rt=0;
	for(auto x:vec)
	{
		tot++;
		prior[tot]=rnd();
		siz[tot]=1;
		val[tot]=sum[tot]=x;
		rt=merge(rt,tot);
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		int a,b,c,d;
		vSplit(rt,aa[i]-1,a,b);
		sSplit(b,1,b,c);
		a=merge(a,c);
		vSplit(rt,bb[i]-1,a,c);
		sSplit(c,1,c,d);
		a=merge(a,d);
		sSplit(a,n,a,d);
		ans=max(ans,sum[d]+aa[i]+bb[i]);
		a=merge(a,d);
		vSplit(a,aa[i],a,d);
		a=merge(a,merge(b,d));
		vSplit(a,bb[i],a,d);
		a=merge(a,merge(c,d));
	}
	ll sum=0;
	for(auto x:vec)
		sum+=x;
	cout<<ans+ans-sum<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5624kb

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7728kb

input:

2
732734236 669531729
368612323 916696032

output:

116957610

result:

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