QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168758#6545. Connect the DotsPhantomThreshold#WA 1ms3788kbC++201.3kb2023-09-08 21:16:032023-09-08 21:16:03

Judging History

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

  • [2023-09-08 21:16:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3788kb
  • [2023-09-08 21:16:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		vector<pair<int,int>> ans;
		stack<int> s1,s2;
		int c1=0,c2=0;
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			if(c1==0)s1.push(x),c1=x;
			else if(c1==x and c2==0)s1.push(i);
			else if(c1==x)
			{
				int u;
				while(not s2.empty())
				{
					u=s2.top();s2.pop();
					ans.emplace_back(u,i);
				}
				s2.push(u);
				while(not s1.empty() and s1.top()>u)
				{
					s1.pop();
				}
				s1.push(i);
			}
			else if(c2==0 or c2==x)
			{
				int u;
				while(not s1.empty())
				{
					u=s1.top();s1.pop();
					ans.emplace_back(u,i);
				}
				s1.push(u);
				while(not s2.empty() and s2.top()>u)
				{
					s2.pop();
				}
				s2.push(i);
				c2=x;
			}
			else
			{
				int u,v;
				while(not s1.empty())
				{
					u=s1.top();s1.pop();
					ans.emplace_back(u,i);
				}
				while(not s2.empty())
				{
					v=s2.top();s2.pop();
					ans.emplace_back(v,i);
				}
				if(u<v)
				{
					s1.push(u);
					s2.push(i);
					c2=x;
				}
				else
				{
					s1.push(i);
					s2.push(v);
					c1=x;
				}
			}
		}
		cout<<ans.size()<<"\n";
		for(auto [u,v]:ans)
			cout<<u<<' '<<v<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok all 3 test passed

Test #2:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

1
2 2
1 2

output:

1
1 2

result:

ok all 1 test passed

Test #3:

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

input:

10
5 2
2 2 2 1 2
5 2
2 1 2 1 2
5 2
1 2 2 2 1
5 2
2 1 2 1 1
5 2
1 1 1 2 1
5 2
1 2 2 1 2
5 2
2 1 1 2 2
5 2
2 2 2 1 1
5 2
1 1 2 1 2
5 2
1 2 2 2 1

output:

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

result:

wrong answer TC #1: two identical wire.