QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386359#8553. Exchanging Kubicucup-team1004#WA 30ms6108kbC++173.2kb2024-04-11 15:47:382024-04-11 15:47:38

Judging History

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

  • [2024-04-11 15:47:38]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:6108kb
  • [2024-04-11 15:47:38]
  • 提交

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
#define eb emplace_back
#define all(x) x.begin(),x.end()
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>;
const int N=2e3+5,M=1.5e8+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-8;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n;ll A[N];
ll f[N][N];
int cts=0;
ll qry(int x,int y){
	if(f[x][y]^-INF) return f[x][y];
	cts++;assert(cts<=2*n);
	ll z;cout<<"? "<<x<<' '<<y<<endl;
	fflush(stdout);
	cin>>z;return f[x][y]=z;
}
int id[N],ih,op[N],l[N],r[N],pl[N],pr[N];ll B[N];
ll sl[N],prel[N],sr[N],prer[N];
void Solve(){
	int i,j;cin>>n;cts=0;
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) f[i][j]=-INF;
	for(i=1;i<=n;i++) A[i]=qry(i,i);
	ih=0;
	for(i=1;i<=n&&!A[i];i++) A[i]=-1e15;
	for(i=n;i&&!A[i];i--) A[i]=-1e15;
	for(i=1;i<=n;i++){
		if(A[i]>0) id[++ih]=i,B[ih]=A[i],op[ih]=0;
		else if(!A[i]){
			if(A[i-1]) id[++ih]=i,B[ih]=0,op[ih]=1;
		}
	}
	for(i=1;i<=ih;i++) if(op[i]) l[i]=r[i]=i,pl[i]=pr[i]=i;
	while(1){
		for(i=1;i<=ih;i++)if(op[i]){
			ll tot=0,sum=0;
			sr[i]=prer[i]=-1e18;
			for(j=i+1;j<=ih&&!op[j];j++){
				tot+=B[j];
				sum=max(sum+B[j],0ll);
				prer[j]=max(prer[j-1],tot);
				sr[j]=max(sr[j-1],sum);
			}
		}
		for(i=ih;i;i--) if(op[i]){
			ll tot=0,sum=0;
			sl[i]=prel[i]=-1e18;
			for(j=i-1;j&&!op[j];j--){
				tot+=B[j];
				sum=max(sum+B[j],0ll);
				prel[j]=max(prel[j+1],tot);
				sl[j]=max(sl[j+1],sum);
			}
		}
		int flag=0;
		for(i=1;i<=ih;i++) if(op[i]){
			while(l[i]>1&&!op[l[i]-1]){
				l[i]--;
				for(int j=i+1;j<=r[i];j++){
					if(prer[j]+prel[l[i]]-max(sr[j],sl[l[i]])>prer[pr[i]]+prel[pl[i]]-max(sr[pr[i]],sl[pl[i]])) pr[i]=j,pl[i]=l[i];
				}
			}
			while(r[i]<ih&&!op[r[i]+1]){
				r[i]++;
				for(int j=i-1;j>=l[i];j--){
					if(prer[r[i]]+prel[j]-max(sr[r[i]],sl[j])>prer[pr[i]]+prel[pl[i]]-max(sr[pr[i]],sl[pl[i]])) pr[i]=r[i],pl[i]=j;
				}
			}
			gdb(pl[i],pr[i]);
			if(qry(id[pl[i]],id[pr[i]])>max(sr[pr[i]],sl[pl[i]])){
				op[i]=0;B[i]=qry(id[pl[i]],id[pr[i]])-prer[pr[i]]-prel[pl[i]];
				flag=1;break;
			}
		}
		if(!flag){
			for(int i=1;i<=ih;i++)if(op[i]){
				B[i]=qry(id[pl[i]],id[pr[i]])-prer[pr[i]]-prel[pl[i]];
				op[i]=0;
				flag=1;break;
			}
		}
		if(!flag) break;
	}
	for(i=1;i<=ih;i++) A[id[i]]=B[i];
	cout<<"! ";for(i=1;i<=n;i++) cout<<A[i]<<' ';cout<<endl;fflush(stdout);
}
int main(){
	// freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	int t=1;
	cin>>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: 4112kb

input:

2
3
1
0
1
1
5
2
0
3
0
5
4
5

output:

? 1 1
? 2 2
? 3 3
? 1 3
! 1 -1 1 
? 1 1
? 2 2
? 3 3
? 4 4
? 5 5
? 1 3
? 1 5
! 2 -1 3 -4 5 

result:

ok ok (2 test cases)

Test #2:

score: 0
Accepted
time: 30ms
memory: 6076kb

input:

10000
1
718876398
1
0
1
0
1
0
1
938356223
1
857157125
1
0
1
0
1
0
1
0
1
0
1
965894497
1
0
1
626061677
1
642094813
1
107398046
1
0
1
0
1
0
1
287188651
1
0
1
345108193
1
0
1
0
1
714952783
1
0
1
325760098
1
0
1
800487422
1
322806679
1
0
1
0
1
0
1
866952779
1
741483102
1
492063609
1
0
1
833448280
1
0
1
...

output:

? 1 1
! 718876398 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! 938356223 
? 1 1
! 857157125 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! -1000000000000000 
? 1 1
! 965894497 
? 1 1
! ...

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 5ms
memory: 4084kb

input:

1052
9
167536100
0
373372185
0
427949326
442758705
102715118
0
0
373372185
427949326
9
248442934
306962195
570791475
593033322
0
582850731
559429390
0
120053133
2225121267
559429390
10
785691778
0
981032824
0
0
592503870
0
0
0
0
981032824
1112480382
10
0
737563509
985502704
427600980
0
805973591
771...

output:

? 1 1
? 2 2
? 3 3
? 4 4
? 5 5
? 6 6
? 7 7
? 8 8
? 9 9
? 1 3
? 3 5
! 167536100 -167536100 373372185 -373372185 427949326 442758705 102715118 -1000000000000000 -1000000000000000 
? 1 1
? 2 2
? 3 3
? 4 4
? 5 5
? 6 6
? 7 7
? 8 8
? 9 9
? 3 7
? 7 9
! 248442934 306962195 570791475 593033322 -80983651 58285...

result:

ok ok (1052 test cases)

Test #4:

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

input:

105
98
0
622130364
0
603542943
491665548
0
535594695
169182905
269002770
437838930
534070706
783210752
0
914335037
560159875
0
216552904
666995724
0
0
0
753649796
0
0
0
779352417
0
121063647
0
496743470
0
4104890
0
648149367
0
965790695
732089017
0
0
0
0
6701195
0
0
0
0
750231085
0
0
511641740
36964...

output:

? 1 1
? 2 2
? 3 3
? 4 4
? 5 5
? 6 6
? 7 7
? 8 8
? 9 9
? 10 10
? 11 11
? 12 12
? 13 13
? 14 14
? 15 15
? 16 16
? 17 17
? 18 18
? 19 19
? 20 20
? 21 21
? 22 22
? 23 23
? 24 24
? 25 25
? 26 26
? 27 27
? 28 28
? 29 29
? 30 30
? 31 31
? 32 32
? 33 33
? 34 34
? 35 35
? 36 36
? 37 37
? 38 38
? 39 39
? 40 4...

result:

wrong answer mss of [1, 85] is incorrect, expected=5601104732, found=5830877386 (test case 13)