QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395593 | #8553. Exchanging Kubic | ucup-team052# | WA | 23ms | 3908kb | C++23 | 2.6kb | 2024-04-21 16:28:44 | 2024-04-21 16:28:45 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define D(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
using LL=long long;
mt19937_64 rnd((long long)new char);
int Rnd(int l,int r) {return rnd()%(r-l+1)+l;}
#define N 2005
#define int long long
const int inf=10000000000000;
int n,a[N],sgn[N];
int ANS[N];
int cnt=0;
int qry(int l,int r)
{
printf("? %lld %lld\n",l,r); fflush(stdout);
#ifdef xay5421
cnt++;
int ans=0,cur=0;
for(int i=l;i<=r;i++)
{
cur=max(cur+ANS[i],0LL);
ans=max(ans,cur);
}
return ans;
#endif
int w; cin>>w;
return w;
}
int L[N],R[N],b[N],s[N],m;
int prew[N],pos[N];
void work()
{
cin>>n;
#ifdef xay5421
// n=7;
for(int i=1;i<=n;i++) cin>>ANS[i];
// for(int i=1;i<=n;i++) ANS[i]=Rnd(1,10);
// for(int i=2;i<=n;i+=2) ANS[i]=-ANS[i];
for(int i=1;i<=n;i++) printf("%lld%c",ANS[i]," \n"[i==n]);
cnt=0;
#endif
for(int i=1;i<=n;i++)
{
int w=qry(i,i);
if(w>0) sgn[i]=1,a[i]=w;
else sgn[i]=0,a[i]=0;
}
m=0;
for(int i=1;i<=n;i++)
{
int r=i; while(r<n&&sgn[r+1]==sgn[i]) r++;
if(m==0&&sgn[i]==0) continue;
m++; s[m]=sgn[i],L[m]=i,R[m]=r,b[m]=0;
if(sgn[i]==1)
{
for(int j=i;j<=r;j++) b[m]+=a[j];
}
i=r;
}
if(s[m]==0) m--;
if(m==1)
{
printf("! ");
for(int i=1;i<=n;i++) printf("%lld%c",a[i]," \n"[i==n]);
fflush(stdout);
}
else
{
pos[2]=1,prew[2]=b[1];
for(int i=4;i<=m;i+=2)
{
int w=qry(L[pos[i-2]],R[i-1]);
if(w==prew[i-2]) pos[i]=i-1,prew[i]=b[i-1];
else pos[i]=pos[i-2],prew[i]=w;
// printf("%lld : %lld %lld\n",i,pos[i],prew[i]);
}
for(int i=m-1;i>=2;i-=2)
{
int sufw=0,cur=0,sufpos=m;
for(int j=m;j>i;j--)
{
cur+=b[j];
if(cur<0) cur=0,sufpos=j;
}
sufw=cur;
int sw=qry(L[pos[i]],R[sufpos]);
// printf("%d : %d %d %d\n",i,prew[i],sufw,sw);
if(sw!=prew[i]&&sw!=sufw) b[i]=-prew[i]-sufw+sw;
else b[i]=-min(prew[i],sufw);
}
for(int i=2;i<=m;i+=2) a[L[i]]=b[i];
printf("! ");
for(int i=1;i<=n;i++) printf("%lld%c",a[i]," \n"[i==n]);
fflush(stdout);
}
#ifdef xay5421
for(int i=1;i<=n;i++)
{
int cur1=0,mxw1=0,cur2=0,mxw2=0;
for(int j=i;j<=n;j++)
{
cur1=max(cur1+a[j],0LL);
mxw1=max(mxw1,cur1);
cur2=max(cur2+ANS[j],0LL);
mxw2=max(mxw2,cur2);
if(mxw1!=mxw2) printf("wa %lld %lld\n",i,j),exit(0);
}
}
if(cnt>2*n) printf("tle\n");
else printf("ac\n");
#endif
}
signed main(){
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
int T; cin>>T; while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
input:
2 3 1 0 1 1 5 2 0 3 0 5 4 5 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 ? 1 5 ! 2 -1 3 -4 5
result:
ok ok (2 test cases)
Test #2:
score: 0
Accepted
time: 19ms
memory: 3888kb
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 ! 0 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 938356223 ? 1 1 ! 857157125 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 965894497 ? 1 1 ! 0 ? 1 1 ! 626061677 ? 1 1 ! 642094813 ? 1 1 ! 107398046 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 0 ? 1 1 ! 287188651 ? 1 1 ! 0 ? 1 1 ! 345108193 ? 1 1 ! ...
result:
ok ok (10000 test cases)
Test #3:
score: 0
Accepted
time: 23ms
memory: 3880kb
input:
1052 9 167536100 0 373372185 0 427949326 442758705 102715118 0 0 373372185 973423149 973423149 9 248442934 306962195 570791475 593033322 0 582850731 559429390 0 120053133 2780526396 2780526396 2780526396 10 785691778 0 981032824 0 0 592503870 0 0 0 0 981032824 1112480382 1112480382 10 0 737563509 98...
output:
? 1 1 ? 2 2 ? 3 3 ? 4 4 ? 5 5 ? 6 6 ? 7 7 ? 8 8 ? 9 9 ? 1 3 ? 1 7 ? 1 7 ! 167536100 -167536100 373372185 -373372185 427949326 442758705 102715118 0 0 ? 1 1 ? 2 2 ? 3 3 ? 4 4 ? 5 5 ? 6 6 ? 7 7 ? 8 8 ? 9 9 ? 1 7 ? 1 9 ? 1 9 ! 248442934 306962195 570791475 593033322 -80983651 582850731 559429390 -12005...
result:
ok ok (1052 test cases)
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3908kb
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, 44] is incorrect, expected=1870527649, found=1800717134 (test case 2)