QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376704#6545. Connect the DotsWorld_CreaterWA 1ms5768kbC++141.4kb2024-04-04 15:25:182024-04-04 15:25:18

Judging History

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

  • [2024-04-04 15:25:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5768kb
  • [2024-04-04 15:25:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,a[200005],cnt[200005],lst[200005],nxt[200005],vis[200005];
priority_queue<pair<int,int> > q;
vector<pair<int,int> > ans;
void checkadd(int x)
{
	if(!x) return ;
	if(nxt[x]&&lst[x]&&a[nxt[x]]!=a[lst[x]]) q.emplace(-cnt[a[x]],x);
}
void del(int x)
{
	if(!x) return ;
	cnt[a[x]]--;
	nxt[lst[x]]=nxt[x];
	lst[nxt[x]]=lst[x];
	if(nxt[x]&&lst[x]&&a[nxt[x]]!=a[lst[x]]) ans.emplace_back(lst[x],nxt[x]);
	checkadd(lst[x]);
	checkadd(nxt[x]);
}
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		nxt[0]=1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			cnt[a[i]]++;
			lst[i]=i-1;
			nxt[i]=(i+1)%(n+1);
			if(i>1&&a[i]!=a[i-1]) ans.emplace_back(i-1,i);
		}
		for(int i=1;i<=n;i++) checkadd(i);
		q.emplace(-(n+1),n+1);
		while(!q.empty())
		{
			auto [y,x]=q.top();
			// cerr<<x<<" "<<y<<"\n";
			if(x==n+1&&nxt[nxt[nxt[0]]])
			{
				del(nxt[nxt[0]]);
				continue ;
			}
			q.pop();
			if(x==n+1) continue ;
			if(vis[x]) continue ;
			vis[x]=1;
			if(x==-1)
			{
				for(int i=lst[x];lst[i];i=lst[i]) del(i);
				for(int i=nxt[x];nxt[i];i=nxt[i]) del(i);
				del(x);
				break ;
			}
			del(x);
		}
		cout<<ans.size()<<"\n";
		for(auto [l,r]:ans)
		{
			cout<<l<<" "<<r<<"\n";
		}
		while(!q.empty()) q.pop();
		ans.clear();
		for(int i=1;i<=n;i++)
		{
			cnt[a[i]]=0;
			vis[i]=0;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok all 3 test passed

Test #2:

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

input:

1
2 2
1 2

output:

1
1 2

result:

ok all 1 test passed

Test #3:

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

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
4 5
2 4
1 4
5
1 2
2 3
3 4
4 5
1 4
4
1 2
4 5
3 5
2 5
5
1 2
2 3
3 4
3 5
1 5
4
3 4
4 5
2 4
1 4
5
1 2
3 4
4 5
2 4
1 5
3
1 2
3 4
2 4
4
3 4
3 5
2 5
1 5
5
2 3
3 4
4 5
1 3
1 5
4
1 2
4 5
3 5
2 5

result:

wrong answer output = 3, answer = 4.