QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393777 | #8553. Exchanging Kubic | YMH_fourteen | WA | 0ms | 3624kb | C++14 | 2.6kb | 2024-04-19 11:48:43 | 2024-04-19 11:48:43 |
Judging History
answer
// Author: Minghan Ye (Donotplaygame)
// Name: L. Exchanging Kubic
// URL: https://qoj.ac/contest/1596/problem/8553
// ML: 1024 MB
// TL: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "E:/OI/normal/templates/debug.h"
#else
#define dbg(...) (void)0
#define msg(...) (void)0
#endif
#define ll long long
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define ALL(Name) Name.begin(),Name.end()
#define PII pair<int,int>
#define VI vector<int>
#define fi first
#define se second
const int N=2005;
int n;
ll a[N],sm[N];
ll ask(int l,int r)
{
cout<<"? "<<l<<" "<<r<<endl;
ll res;cin>>res;
return res;
}
void answer()
{
cout<<"!";
for(int i=1;i<=n;i++)cout<<" "<<a[i];
cout<<endl;
}
void upd()
{
for(int i=1;i<=n;i++)sm[i]=sm[i-1]+a[i];
}
ll sum(int l,int r){return sm[r]-sm[l-1];}
int main()
{
ios::sync_with_stdio(false),cin.tie(nullptr);
int _;cin>>_;while(_--)
{
cin>>n;
for(int i=1;i<=n;i++)a[i]=ask(i,i);
vector<PII> p;
for(int i=1,lst=0;i<=n+1;i++)
if(a[i]>0)
{
if(!lst)lst=i;
}
else
{
if(lst)p.PB(lst,i-1);
lst=0;
}
while(p.size()>1)
{
// cerr<<"p = [";
// for(int i=0;i<p.size();i++)fprintf(stderr,"(%d, %d)%s",p[i].fi,p[i].se,i+1==p.size()?"]\n":", ");
upd();
vector<PII>::iterator it;
for(auto i=p.begin();i!=p.end();i++)
if(i==p.begin()||sum(i->fi,i->se)<sum(it->fi,it->se))it=i;
if(it!=p.begin())
{
ll t=ask((it-1)->fi,it->se),s=sum((it-1)->fi,(it-1)->se),u=t+sum(it->fi,it->se);
if(t>s)
{
int ls=-1,rs=-1;
for(int i=(it-1)->se+1;;i++)
{
if(a[i]>0)break;
if(a[i]<0){ls=i;break;}
}
for(int i=it->fi-1;;i--)
{
if(a[i]>0)break;
if(a[i]<0){rs=i;break;}
}
if(~ls)a[rs]=s-u-a[ls];
else a[it->fi-1]=s-u;
int st=(it-1)->fi,ed=it->se;
p.emplace(p.erase(it-1,it+1),st,ed);
continue;
}
}
if(it+1!=p.end())
{
ll t=ask(it->fi,(it+1)->se),s=sum((it+1)->fi,(it+1)->se),u=t+sum(it->fi,it->se);
if(t>s)
{
int ls=-1,rs=-1;
for(int i=it->se+1;;i++)
{
if(a[i]>0)break;
if(a[i]<0){ls=i;break;}
}
for(int i=(it+1)->fi-1;;i--)
{
if(a[i]>0)break;
if(a[i]<0){rs=i;break;}
}
if(~ls)a[rs]=s-u-a[ls];
else a[it->se+1]=s-u;
int st=it->fi,ed=(it+1)->se;
p.emplace(p.erase(it,it+2),st,ed);
continue;
}
}
a[it->fi-1]=a[it->se+1]=-sum(it->fi,it->se);
p.erase(it);
}
answer();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
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 -3 3 -2 5
result:
wrong answer mss of [1, 3] is incorrect, expected=4, found=3 (test case 2)