QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#869581#9222. Price ComboniucardTL 1ms12120kbC++202.4kb2025-01-25 11:32:552025-01-25 11:32:57

Judging History

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

  • [2025-01-25 11:32:57]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:12120kb
  • [2025-01-25 11:32:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,ba[200010],bb[200010];
long long f[200010][2][2],num[2],sum[200010][3],g[2][2],s[2];
struct node
{
	int a,b;
} a[200010];
bool mycmp(node x,node y)
{
	if(x.a!=y.a)
	return x.a>y.a;
	return x.b>y.b;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i].a);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i].b);
	for(int i=1;i<=n;i++)
	ba[i]=a[i].a;
	sort(ba+1,ba+n+1);
	int nn=unique(ba+1,ba+n+1)-(ba+1);
	for(int i=1;i<=n;i++)
	a[i].a=lower_bound(ba+1,ba+nn+1,a[i].a)-ba;
	for(int i=1;i<=n;i++)
	bb[i]=a[i].b;
	sort(bb+1,bb+n+1);
	nn=unique(bb+1,bb+n+1)-(bb+1);
	for(int i=1;i<=n;i++)
	a[i].b=lower_bound(bb+1,bb+nn+1,a[i].b)-bb; 
	a[++n]={0,0},a[++n]={n-1,n-1};
//	for(int i=1;i<=n;i++)
//	cout<<a[i].a<<' '<<a[i].b<<endl;
	sort(a+1,a+n+1,mycmp);
	vector<int> ve;
	memset(f,0x3f,sizeof f);
	f[1][0][0]=0;
	for(int i=2,h=0;i<=n;i++)
	{
		if(a[i].a!=a[i-1].a)
		{
			int id;
			if(!ve.empty())
			id=ve[0];
			for(auto x:ve)
			{
				for(int j=1;j<id;j++)
				{
					if(a[j].b<=a[x].b)
					{
						for(int k=0;k<=1;k++)
						for(int l=0;l<=1;l++)
						g[k][l]=f[j][k][l];
						for(int k=0;k<=1;k++)
						for(int l=0;l<=1;l++)
						{
							if(k^1)
							f[j][k][l]=g[k^1][l];
							else
							f[j][k][l]=g[k^1][l]+ba[a[x].a];
						}
					}
				}
			}
			int now=0,js=0;
			long long num1=0,num2=0;
			for(int j=n;j>=0;j--)
			{
				while(now!=ve.size()&&a[ve[now]].b==j)
				{
					js++;
					if(js%2)
					num1+=bb[j];
					else
					num2+=bb[j];
					now++;
				}
				if(sum[j][2]%2)
				{
					sum[j][1]+=num2;
					sum[j][0]+=num1;
				}
				else
				{
					sum[j][1]+=num1;
					sum[j][0]+=num2;
				}
				sum[j][2]+=js;
			}
			h=1;
			num[0]=0,num[1]=ba[a[i].a];
			ve.clear();
			ve.push_back(i);
		}
		else
		{
			ve.push_back(i); 
			h++;
			num[h%2]+=ba[a[i].a];
		}
		for(int j=1;j<i;j++)
		{
			if(a[j].b<=a[i].b)
			continue;
			int x=h%2,y=(sum[a[i].b][2]-sum[a[j].b][2])%2;
			if(sum[a[j].b][2]%2)
			{
				s[0]=sum[a[i].b][1]-sum[a[j].b][1];
				s[1]=sum[a[i].b][0]-sum[a[j].b][0];
			}
			else
			{
				s[0]=sum[a[i].b][0]-sum[a[j].b][0];
				s[1]=sum[a[i].b][1]-sum[a[j].b][1];
			}
			for(int k=0;k<=1;k++)
			for(int l=0;l<=1;l++)
			f[i][k][l]=min(f[i][k][l],f[j][k^x][l^y]+num[k^x^1]+s[l^y^1]);
		}
	}
	printf("%lld",min({f[n][0][0],f[n][0][1],f[n][1][0],f[n][1][1]}));
	return 0;
}

詳細信息

Test #1:

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

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #2:

score: 0
Accepted
time: 0ms
memory: 12116kb

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #3:

score: -100
Time Limit Exceeded

input:

199913
1212731 2525164 3210261 2457211 1013738 1931420 923123 867112 762069 2108660 108920 2491869 867107 387025 2278045 574027 1661570 820133 1274150 2001346 779766 3305537 3000211 2418643 2108660 2001343 1074820 2754411 826712 3117447 1661569 338161 1849064 3007920 3057426 468078 3252798 1274146 4...

output:


result: