This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int n,m,k;
int query(int x,int y,int z){
if(x<1||x>n||y<1||y>m||z<1||z>k)return 0;
if(mp.count(x+y*(n+1)+z*(n+1)*(m+1)))return mp[x+y*(n+1)+z*(n+1)*(m+1)];
int res;
cout<<"? "<<x<<" "<<y<<" "<<z<<endl;
cin>>res;
return mp[x+y*(n+1)+z*(n+1)*(m+1)]=res;
}
int main(){
int q;
cin>>n>>m>>k>>q;
if(k!=1){
}else if(m!=1){
int xl=1,xr=n,yl=1,yr=m,mx=query(n/2,m/2,1);
pair<int,int>mxpos={n/2,m/2};
while(1){
if(query(mxpos.first,mxpos.second,1)>query(mxpos.first,mxpos.second-1,1)
&&query(mxpos.first,mxpos.second,1)>query(mxpos.first,mxpos.second+1,1)
&&query(mxpos.first,mxpos.second,1)>query(mxpos.first-1,mxpos.second,1)
&&query(mxpos.first,mxpos.second,1)>query(mxpos.first+1,mxpos.second,1))break;
if(xl<xr){
int x=(xl+xr)/2;
if(query(x,mxpos.second,1)<mx){
if(x<mxpos.first)xl=x+1;
else xr=x-1;
continue;
}else mx=query(x,mxpos.second,1),mxpos.first=x;
if(query(x,mxpos.second,1)<query(x-1,mxpos.second,1)){
xr=x-1;
if(query(x-1,mxpos.second,1)>mx)mx=query(x-1,mxpos.second,1),mxpos.first=x-1;
continue;
}else if(query(x,mxpos.second,1)<query(x+1,mxpos.second,1)){
xl=x+1;
if(query(x+1,mxpos.second,1)>mx)mx=query(x+1,mxpos.second,1),mxpos.first=x+1;
continue;
}
yl=1,yr=m;
continue;
}
int y=(yl+yr)/2;
if(query(mxpos.first,y,1)<mx){
if(y<mxpos.second)yl=y+1;
else yr=y-1;
continue;
}else mx=query(mxpos.first,y,1),mxpos.second=y;
if(query(mxpos.first,y,1)<query(mxpos.first,y-1,1)){
yr=y-1;
if(query(mxpos.first,y-1,1)>mx)mx=query(mxpos.first,y-1,1),mxpos.second=y-1;
continue;
}else if(query(mxpos.first,y,1)<query(mxpos.first,y+1,1)){
yl=y+1;
if(query(mxpos.first,y+1,1)>mx)mx=query(mxpos.first,y+1,1),mxpos.second=y+1;
continue;
}
else xl=1,xr=n;
}
cout<<"! "<<mxpos.first<<' '<<mxpos.second<<" 1"<<endl;
}else{
int l=1,r=n,mx=0,mxpos;
while(l<r){
int mid=(l+r)/2;
if(query(mid,1,1)<mx){
if(mid<mxpos)l=mid+1;
else r=mid-1;
continue;
}else mx=query(mid,1,1),mxpos=mid;
if(query(mid,1,1)<query(mid-1,1,1)){
r=mid-1;
if(query(mid-1,1,1)>mx)mx=query(mid-1,1,1),mxpos=mid-1;
}else if(query(mid,1,1)<query(mid+1,1,1)){
l=mid+1;
if(query(mid+1,1,1)>mx)mx=query(mid+1,1,1),mxpos=mid+1;
}else l=r=mid;
}
cout<<"! "<<l<<" 1 1"<<endl;
}
}
Compilation message (stderr)
worm.cpp: In function 'int main()':
worm.cpp:68:17: warning: 'mxpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | if(mid<mxpos)l=mid+1;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |