QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457979#8837. Increasing Incomeucup-team1004#WA 0ms11844kbC++141.1kb2024-06-29 15:06:172024-06-29 15:06:18

Judging History

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

  • [2024-06-29 15:06:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11844kb
  • [2024-06-29 15:06:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
int n;
namespace bit{
	pii s,t[N];
	void gmax(pii &a,pii b){if(b>a)a=b;}
	void add(int x,pii a){for(;x<=n;gmax(t[x],a),x+=x&(-x));}
	pii qry(int x){for(s={0,0};x;gmax(s,t[x]),x-=x&(-x));return s;}
}
int a[N],p[N],f[N],g[N],T;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++) p[i]=0,bit::t[i]={0,0};
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
		{
			auto k=bit::qry(a[i]);
			f[i]=k.first+1,g[i]=k.second;
			bit::add(a[i],make_pair(f[i],i));
		}
		int w=max_element(f+1,f+n+1)-f;
		for(int i=w;i;i=g[i]) p[i]=1;
		priority_queue<pii> q;
		for(int i=1,j=0;i<=n;i++)
			if(p[i]) j=a[i];
			else if(a[i]>j) q.push({-a[i],i});
			else p[i]=-1;
		for(int i=1,j=0;i<=n;i++)
		{
			if(p[i]==1)
			{
				while(q.size()&&-q.top().first<j)
					printf("%d ",q.top().second),q.pop();
				printf("%d ",i);
				j=a[i];
			}
			else if(p[i]==-1) printf("%d ",i);
		}
		while(q.size()) printf("%d ",q.top().second),q.pop();
		puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
1 2 3
4
2 4 3 1
5
1 5 2 4 3

output:

1 2 3 
1 2 3 4 
1 3 4 5 2 

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 11844kb

input:

153
4
2 4 3 1
4
1 4 2 3
5
2 1 4 5 3
5
1 4 5 3 2
4
1 3 2 4
5
1 5 2 4 3
5
5 3 1 2 4
5
4 1 2 5 3
5
1 2 5 3 4
5
3 1 4 2 5
5
5 4 2 3 1
5
2 1 5 4 3
5
3 4 1 5 2
5
1 4 3 5 2
5
5 1 3 4 2
5
5 3 2 4 1
5
1 5 3 2 4
5
2 4 3 1 5
5
1 5 4 3 2
5
1 2 4 5 3
5
4 2 5 3 1
5
1 3 5 2 4
5
3 1 4 5 2
3
2 1 3
5
1 2 4 3 5
5
5 1 ...

output:

1 2 3 4 
1 3 4 2 
2 3 1 4 5 
1 2 3 4 5 
1 3 4 2 
1 3 4 5 2 
3 4 5 2 1 
2 3 4 5 1 
1 2 4 5 3 
2 4 5 1 3 
3 4 5 2 1 
2 3 4 5 1 
1 2 3 4 5 
1 3 4 5 2 
2 3 4 5 1 
3 4 5 2 1 
1 4 5 3 2 
1 3 4 5 2 
1 2 3 4 5 
1 2 3 4 5 
2 3 4 5 1 
1 2 3 4 5 
2 3 1 4 5 
2 3 1 
1 2 4 5 3 
2 3 4 5 1 
3 4 5 1 2 
3 4 5 2 1 
1 ...

result:

wrong answer Jury found better answer than participant (test case 3)