#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define ld long double
#define en exit(0);
#define pb push_back
#define fi first
#define se second
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ld gold = (3.0 - sqrt(5)) / 2.0;
pair<int,int> dd[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<array<int, 3>, int> mp;
int n, m, k, q;
int ask(int x, int y = 1, int z = 1)
{
if(min({x, y, z}) < 1 || x > n || y > m || z > k)
return 0;
array<int, 3> tmp = {x, y, z};
if(mp.count(tmp))
return mp[tmp];
cout << "? " << x << " " << y << " " << z << endl;
int h;
cin >> h;
assert(q-- != 0);
if(h == -1)
exit(0);
return mp[tmp] = h;
}
void guess(int x, int y = 1, int z = 1)
{
cout << "! " << x << " " << y << " " << z << endl;
}
bool is(int x, int y)
{
int cur = ask(x, y), mx = -1, t = -1;
for(int d = 0;d < 4;d++)
{
int nwx = x + dd[d].fi, nwy = y + dd[d].se;
if(ask(nwx, nwy) > mx)
{
mx = ask(nwx, nwy);
t = d;
}
}
return (cur >= mx);
}
int main()
{
fio
// ifstream cin("in.in");
cin >> n >> m >> k >> q;
if(max(m, k) == 1)
{
int l = 1, r = n;
int lpos = 1 + floor(n * gold), rpos = n - floor(n * gold);
while(l + 5 <= r)
{
int lval = ask(lpos), rval = ask(rpos);
if(lval < rval)
{
l = lpos;
lpos = rpos;
int sz = r - l + 1;
rpos = r - floor(sz * gold);
}
else
{
r = rpos;
rpos = lpos;
int sz = r - l + 1;
lpos = l + floor(sz * gold);
}
}
int mxpos = l;
for(int i = l;i <= r;i++)
if(ask(i) > ask(mxpos))
mxpos = i;
guess(mxpos);
}
else if(k == 1)
{
int ln = 1, rn = n, lm = 1, rm = m;
while(1)
{
int midn = (ln + rn) / 2, mxpos = lm;
for(int i = lm;i <= rm;i++)
if(ask(midn, i) > ask(midn, mxpos))
mxpos = i;
int mxval = ask(midn, mxpos), lft = ask(midn - 1, mxpos);
if(lft > mxval && midn - 1 >= ln)
rn = midn - 1;
else
{
int rgt = ask(midn + 1, mxpos);
if(rgt > mxval && midn + 1 <= rn)
ln = midn + 1;
else
{
guess(midn, mxpos);
break;
}
}
///
int midm = (lm + rm) / 2;
mxpos = ln;
for(int i = ln;i <= rn;i++)
if(ask(i, midm) > ask(mxpos, midm))
mxpos = i;
mxval = ask(mxpos, midm);
lft = ask(mxpos, midm - 1);
if(lft > mxval && midm - 1 >= lm)
rm = midm - 1;
else
{
int rgt = ask(mxpos, midm + 1);
if(rgt > mxval && midm + 1 <= rm)
lm = midm + 1;
else
{
guess(mxpos, midm);
break;
}
}
}
}
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... |