QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211477#4617. Arithmetic Subsequenceyiyiyi#AC ✓22ms5732kbC++171011b2023-10-12 17:04:032023-10-12 17:04:04

Judging History

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

  • [2023-10-12 17:04:04]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:5732kb
  • [2023-10-12 17:04:03]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(int i=(s);i>=(t);i--)
using namespace std;
ll ci(){
	ll x; scanf("%lld",&x); return x;
}

enum{N=200023};

pair<int,int> a[N];
pair<int,int> b[N];
bool fail = 0;

void solve(int l,int r){
		//printf("line %d: %d %d\n", __LINE__, l,r);
	if( l>r ) return ;
	if( a[l].first==a[r].first ){
		if( r-l+1 >= 3 ) fail = 1;
		return ;
	}
	int tot = l-1;
	int totr = r+1;
	rep(i,l,r) if( a[i].first&1 ){
		a[i].first--;
		a[i].first/=2;
		b[++tot] = a[i];
	}else{
		a[i].first/=2;
		b[--totr] = a[i];
	}
	rep(i,l,r) a[i] = b[i];
	solve(l,tot);
	solve(totr,r);
}

int c[N];

signed main(){
	int T = ci();
	while( T-- ){
		int n = ci();
		rep(i,1,n) a[i] = {c[i] = ci(), i};
		sort(a+1, a+n+1);
		fail = 0;
		solve(1,n);
		if( fail ){
			puts("NO");
		}else{
			puts("YES");
			rep(i,1,n) printf("%d ", c[a[i].second]); puts("");
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 22ms
memory: 5732kb

input:

25
4
3 6 8 9
5
1 1 1 1 1
5000
204869248 184063453 335277313 805198752 988635160 266844506 494544568 842685418 516257494 110006739 727397507 931812983 898605116 670474885 536302721 818724782 251547299 883494814 479828194 573135914 408419766 283100869 472145517 996777784 393702645 555881361 835407611 ...

output:

YES
3 9 6 8 
NO
YES
997457919 28540927 168284159 392485887 30561279 618477055 33609215 425276159 80450303 766389503 20466943 937493759 234127231 266813311 315469695 642043775 876816255 905333631 953092479 284389759 786805119 126109311 668253311 907828351 548105343 857108607 187678847 689291391 92700...

result:

ok