QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#431920#6537. One, Two, Threegrass8cowCompile Error//C++141.3kb2024-06-06 12:02:392024-06-06 12:02:40

Judging History

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

  • [2024-06-06 12:02:40]
  • 评测
  • [2024-06-06 12:02:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[1010000];
#define pb push_back
vector<int>p0,p1,p2;
int A,B,C,s[1001000][3];
int L[1010000],R[1010000],e,M[1001000];
vector<int>g[1001000];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]),a[i]--;
		for(int j=0;j<3;j++)
		s[i][j]=s[i-1][j]+(a[i]==j);
		if(a[i]==0)p0.pb(i);
		if(a[i]==1)p1.pb(i);
		if(a[i]==2)p2.pb(i);
	}
	A=B=C=min(min(p0.size(),p2.size()),p1.size());
	for(int i=0;i<=n;i++)A=min(A,s[i][0]+s[n][2]-s[i][2]);
	for(int i=0;i<=n;i++)B=min(B,s[i][2]+s[n][0]-s[i][0]);
	for(int l=0;l<=n;l++)for(int r=l;r<=n;r++){
		int a1=s[l][0]+(s[n][2]-s[r][2]),a2=s[l][2]+(s[n][0]-s[r][0]),e=s[r][1]-s[l][1];
		C=min(C,e+a1+a2),A=min(A,e+a1),B=min(B,e+a2);
		//max(X-a1,0)+max(Y-a2,0)<=s[r][1]-s[l][1]
	}
	C=min(C,A+B),B=min(B,C-A);
	printf("%d\n",A+B);
	for(int i=0;i<A;i++)L[++e]=p0[i],R[e]=p2[t2-A+i];
	for(int i=0;i<B;i++)L[++e]=p2[i],R[e]=p0[t0-B+i];
	for(int i=1;i<=e;i++)g[L[i]].pb(i);
	priority_queue<pair<int,int> >q;
	for(int i=1;i<=n;i++){
		for(int x:g[i])q.push({-R[x],x});
		if(a[i]==1&&!q.empty()){
			int o=q.top().second;q.pop();
			assert(i<=R[o]);
			M[o]=i;
		}
	}
	for(int i=1;i<=e;i++)assert(M[i]);
	for(int i=1;i<=e;i++)printf("%d %d %d\n",L[i]-1,M[i]-1,R[i]-1);
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:29:50: error: ‘t2’ was not declared in this scope; did you mean ‘tm’?
   29 |         for(int i=0;i<A;i++)L[++e]=p0[i],R[e]=p2[t2-A+i];
      |                                                  ^~
      |                                                  tm
answer.code:30:50: error: ‘t0’ was not declared in this scope; did you mean ‘y0’?
   30 |         for(int i=0;i<B;i++)L[++e]=p2[i],R[e]=p0[t0-B+i];
      |                                                  ^~
      |                                                  y0
answer.code:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
answer.code:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf("%d",&a[i]),a[i]--;
      |                 ~~~~~^~~~~~~~~~~~