递增三元组(不知道哪里错了·)

 test2是啥?为啥一直过不了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
const int maxn=100005;
void Print(int p,int a[],int n)
{
	cout<<p<<" :";
	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
	cout<<endl;
}
int main()
{
	int n,ans=0;
	cin>>n;
	int ar1[maxn],ar2[maxn],ar3[maxn];
	for(int j=1;j<=n;j++) cin>>ar1[j];
	for(int j=1;j<=n;j++) cin>>ar2[j];
	for(int j=1;j<=n;j++) cin>>ar3[j];
//	Print(1,ar1,n);
//	Print(2,ar2,n);
//	Print(3,ar3,n);
	sort(ar1+1,ar1+n);
	sort(ar2+1,ar2+n);
	sort(ar3+1,ar3+n);
	int msg2[maxn],msg3[maxn];
	memset(msg2,0,sizeof(msg2));
	memset(msg3,0,sizeof(msg3));
	//先记录第一位的比较信息
	bool flag1,flag2; 
	flag1=flag2=true;
	for(int i=1;i<=n;i++)
	{
		if(ar2[1]>ar1[i]) //记录比当前位小的下标,也是数量。
		{
//			cout<<"^^^";
			msg2[1]=i;
			flag1=false;
		}
		if(ar3[1]>ar2[i]) //记录比当前位小的下标,也是数量。
		{
//			cout<<"{{{";
			msg3[1]=i;
			flag2=false;
		}
	}
//	if(flag1) msg2[1]=n;
//	if(flag2) msg3[1]=n;
//	cout<<"\n*****\n";
//	cout<<msg2[1]<<" "<<msg3[1]<<endl;
//	cout<<"*****\n";
//	再记录后面几位的比较信息
	for(int i=2;i<=n;i++)
	{
		if(ar2[i]>ar1[msg2[i-1]])
		{
			int pos=msg2[i-1];
			while(ar2[i]>ar1[pos]&&pos<=n)
			{
				pos++;
			}
			if(pos<=n) msg2[i]=pos-1;
			else       msg2[i]=n;
		}
		else msg2[i]=msg2[i-1];
		if(ar3[i]>ar2[msg3[i-1]])
		{
			int pos=msg3[i-1];
			while(ar3[i]>ar2[pos]&&pos<=n)
			{
				pos++;
			}
			if(pos<=n) msg3[i]=pos-1;
			else       msg3[i]=n;
		}
		else msg3[i]=msg3[i-1];
	} 
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=msg3[i];j++) ans+=msg2[j];
	}
	cout<<ans<<endl;
	Print(2,msg2,n);
	Print(3,msg3,n);
	return 0;
}
发布了77 篇原创文章 · 获赞 11 · 访问量 4983

猜你喜欢

转载自blog.csdn.net/qq_43346054/article/details/104084706