QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211092#6537. One, Two, Three275307894aWA 1ms5924kbC++141.6kb2023-10-12 09:07:552023-10-12 09:07:55

Judging History

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

  • [2023-10-12 09:07:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5924kb
  • [2023-10-12 09:07:55]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=6e5+5,M=N*4,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,A[N],vis[N];
struct Node{int x,y,z;};vector<Node> ans;
int p1[N],p2[N],H,p3[N];
void work(){
	H=0;int i,j;
	stack<int> s1,s2;
	for(i=1;i<=n;i++) if(!vis[i]){
		if(A[i]==1) s1.emplace(i);
		else if(A[i]==2) s2.emplace(i);
		else {
			if(s1.empty()||s2.empty()) continue; 
			p1[++H]=s1.top();
			for(j=H-1;j&&p2[j]>s2.top();j--) if(p2[j]<p1[j+1]) break;
			if(p2[j]>s2.top()||s2.top()<p1[j+1]){H--;continue;}
			p2[H]=s2.top();p3[H]=i;vis[i]=vis[s1.top()]=vis[s2.top()]=1;
			s2.pop();s1.pop();
			for(j=H;j>1;j--) if(p2[j]<p2[j-1]) swap(p2[j],p2[j-1]);
		}
	}
}
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	work();for(i=1;i<=H;i++) ans.emplace_back((Node){p1[i],p2[i],p3[i]});
	reverse(vis+1,vis+n+1);reverse(A+1,A+n+1);
	work();for(i=1;i<=H;i++) ans.emplace_back((Node){n-p1[i]+1,n-p2[i]+1,n-p3[i]+1});
	printf("%d\n",ans.size());
	for(auto i:ans) printf("%d %d %d\n",i.x-1,i.y-1,i.z-1);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
3 1 2 2 3 1

output:

2
1 3 4
5 2 0

result:

ok count=2

Test #2:

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

input:

6
2 1 3 1 3 2

output:

0

result:

ok count=0

Test #3:

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

input:

3000
1 1 1 1 1 3 1 1 3 3 1 3 1 1 2 3 1 1 2 1 2 1 3 3 3 1 1 2 1 2 2 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 3 3 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 1 1 1 3 3 2 1 3 1 1 2 3 1 2 3 1 1 1 2 1 1 1 1 2 3 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 3 1 3 3 1 1 1 1 3 1 1 2 1 1 1 3 3 1 1 1 1 2 1 1 1 1 1 2 3 3 1...

output:

152
13 14 15
28 30 31
45 46 47
70 71 72
83 84 85
86 87 88
96 97 98
143 144 145
243 244 245
257 258 259
275 276 277
310 312 313
331 332 333
383 385 386
465 466 467
472 473 474
480 481 482
485 486 487
622 623 624
649 650 651
712 713 714
741 742 743
748 749 750
760 763 764
766 769 770
797 798 799
804 8...

result:

wrong answer the number of matches is different