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;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
int X, Y, Z;
int Q;
vector<vector<vi>> arr;
int query(int x, int y, int z){
int ret;
if(x<=0 or x>=X+1 or y<=0 or y>=Y+1 or z<=0 or z>=Z+1){
return 0;
}
if(Q == 0){
return -1;
}
if(arr[x][y][z] == 0){
Q--;
cout<<"? "<<x<<" "<<y<<" "<<z<<endl;
cin>>ret;
arr[x][y][z] = ret;
}
else{
ret = arr[x][y][z];
}
return ret;
}
bool isMax(int x, int y, int z){
bool ret = 1;
FOR(i, -1, 1, 2){
FOR(j, -1, 1, 2){
if( query(x, y, z) < query(x+i, y+j, z) ){
ret = 0;
}
}
}
return ret;
}
pii solve(int z){
int xl = 1, xr = X, xmid;
int yl = 1, yr = Y, ymid;
while(xl + 1 < xr and yl + 1 < yr){
xmid = (xl + xr) / 2;
ymid = (yl + yr) / 2;
int xlyl = query(xmid, ymid, 1);
int xlyr = query(xmid, ymid+1, 1);
int xryl = query(xmid+1, ymid, 1);
int xryr = query(xmid+1, ymid+1, 1);
int Max = max({xlyl, xlyr, xryl, xryr});
if(xlyl == Max){
xr = xmid;
yr = ymid;
}
else if(xlyr == Max){
xr = xmid;
yl = ymid + 1;
}
else if(xryl == Max){
xl = xmid + 1;
yr = ymid;
}
else{
xl = xmid + 1;
yl = ymid + 1;
}
}
FOR(i, xl, xr, 1){
FOR(j, yl, yr, 1){
if( isMax(i, j, z) ){
return mkp(i, j);
}
}
}
return mkp(-1, -1);
}
signed main(){
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
cin>>X>>Y>>Z>>Q;
arr.resize(X + 1);
for(auto& i : arr){
i.resize(Y + 1);
for(auto& j : i){
j.resize(Z + 1);
}
}
pii res = solve(1);
cout<<"! "<<res.F<<" "<<res.S<<" 1"<<endl;
return 0;
}
# | 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... |