QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#472579#7932. AND-OR closureucup-team052#RE 0ms0kbC++232.1kb2024-07-11 17:17:162024-07-11 17:17:16

Judging History

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

  • [2024-07-11 17:17:16]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-11 17:17:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 500005
int a[N],n,ans[N];
int solve(int l,int r,int ad)
{
	printf("%d %d\n",l,r);
	if(r>n) exit(1);
	if(l>r) return 0;
	if(l==r)
	{
		ans[l]=ad+1;
		return ans[l];
	}
	int mid=-1;
	for(int i=l+1;i<=r;i++) if(a[i]>a[l])
	{
		mid=i;
		break;
	}
	printf("%d %d %d\n",l,r,mid);
	if(mid==-1)
	{
		ans[l]=ad+(r-l+1);
		solve(l+1,r,ad);
		return ans[l];
	}
	else
	{
		int premxcnt=a[l]-(mid-l);
		int ansmx=0;
		int w=mid-l;
		// ans[l]=ans[mid]=ad+w;
		for(int i=l+1;i<=mid-1;i++) a[i]-=premxcnt+2;
		ansmx=max(ansmx,solve(l+1,mid-1,ad));
		ad+=w;
		a[mid]-=w;
		int cur=mid;
		// solving [cur + 1, r]
		vector<int> tmppos; tmppos.push_back(cur);
		for(int i=0;i<premxcnt;)
		{
			int nw=cur+(a[cur]-premxcnt+i);
			printf("%d %d - %d\n",l,r,nw);
			if(a[nw]>nw-cur+premxcnt-i)
			{ // h[nw]=h[cur]
				for(int i=cur+1;i<=nw-1;i++) a[i]-=premxcnt-i;
				ansmx=max(ansmx,solve(cur+1,nw-1,ad));
				tmppos.push_back(nw);
				a[nw]-=(nw-cur-1);
				cur=nw;
			}
			else
			{ // h[nw+1] is premx
				for(int i=cur+1;i<=nw;i++) a[i]-=premxcnt-i;
				ansmx=max(ansmx,solve(cur+1,nw,ad));
				ansmx++;
				for(int i:tmppos) ans[i]=ansmx;
				tmppos.clear();
				tmppos.push_back(nw+1);
				ad=ansmx;
				a[nw+1]-=(nw+1-l);
				cur=nw+1;
				i++;
			}
		}
		for(int i=cur+1;i<=r;i++) a[i]--;
		ansmx=max(ansmx,solve(cur+1,r,ad));
		assert(tmppos.size()==1);
		ansmx++;
		ans[tmppos[0]]=ansmx;
		return ansmx;
	}
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	solve(1,n,0);
	for(int i=1;i<=n;i++) printf("%d%c",ans[i]," \n"[i==n]);
	return 0;
}



詳細信息

Test #1:

score: 0
Runtime Error

input:

4
0 1 3 5

output:

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

result: