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>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define test 1
#define TEST if(test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;
int N, M, K, Q;
map<ll, int> mp;
int ask(int x, int y, int z){
if(x<1 || x>N || y<1 || y>M || z<1 || z>K) return 0;
ll t = (ll)x*(ll)(M+1)*(ll)(K+1)+(ll)y*(ll)(K+1)+(ll)z;
if(mp[t]!=0){
return mp[t];
}
printf("? %d %d %d\n", x, y, z);
int ret;
fflush(stdout);
scanf("%d", &ret);
mp[t] = ret;
return ret;
}
void ans(int x, int y, int z){
printf("! %d %d %d\n", x, y, z);
fflush(stdout);
}
void pro1(){
int s = 0, e = N+1, m;
int mx = 0;
while(s<e){
if(s==e-1){
int t1 = ask(s, 1, 1), t2 = ask(e, 1, 1);
if(t1>t2){
ans(s, 1, 1);
}else{
ans(e, 1, 1);
}
return;
}
m = (s+e)/2;
int h = ask(m, 1, 1);
if(h>mx){
int h2 = ask(m+1, 1, 1);
if(h>h2){
e = m;
mx = h;
}else{
s = m+1;
mx = h2;
}
}else{
if(ask(s, 1, 1)<ask(e, 1, 1)){
s = m;
}else{
e = m;
}
}
}
ans(s, 1, 1);
}
vector<pii> vt;
void pro2(){
pii s={1, 1}, e={N, M};
pii mx = {0, 0};
while(s.first!=e.first || s.second!=e.second){
if(s.second!=e.second){
while(!vt.empty()) vt.pop_back();
int m = (s.second + e.second)/2;
for(int i=s.first; i<=e.first; i++){
vt.pb({ask(i, m, 1), i});
}
sort(vt.begin(), vt.end());
if(vt.back().first>=ask(mx.first, mx.second, 1)){
if(ask(vt.back().second, m-1, 1)>vt.back().first){
mx.first = vt.back().second; mx.second = m-1;
e.second = m-1;
}else if(ask(vt.back().second, m+1, 1)>vt.back().first){
mx.first = vt.back().second; mx.second = m+1;
s.second = m+1;
}else{
ans(vt.back().second, m, 1);
return;
}
}else{
if(mx.second<m){
e.second = m-1;
}else{
s.second = m+1;
}
}
}
if(s.first!=e.first){
while(!vt.empty()) vt.pop_back();
int m = (s.first+e.first)/2;
for(int i=s.second; i<=e.second; i++){
vt.pb({ask(m, i, 1), i});
}
sort(vt.begin(), vt.end());
if(vt.back().first>=ask(mx.first, mx.second, 1)){
if(ask(m-1, vt.back().second, 1)>vt.back().first){
mx.first = m-1; mx.second = vt.back().second;
e.first = m-1;
}else if(ask(m+1, vt.back().second, 1)>vt.back().first){
mx.first = m+1; mx.second = vt.back().second;
s.first = m+1;
}else{
ans(m, vt.back().second, 1);
return;
}
}else{
if(mx.first<m){
e.first = m-1;
}else{
s.first = m+1;
}
}
}
}
ans(s.first, s.second, 1);
}
struct Point{
int x, y, z;
};
int dx[6] = {1, -1, 0, 0, 0, 0}, dy[6] = {0, 0, 1, -1, 0, 0}, dz[6] = {0, 0, 0, 0, 1, -1};
void pro3(){
Point mx = {0, 0, 0};
for(int i=0; i<Q/2; i++){
int x, y, z;
x = rand()%N+1; y = rand()%M+1; z = rand()%K+1;
if(ask(x, y, z)>ask(mx.x, mx.y, mx.z)){
mx.x = x; mx.y = y; mx.z = z;
}
}
while(1){
int m=0, t=0;
for(int i=0; i<6; i++){
int ret = ask(mx.x+dx[i], mx.y+dy[i], mx.z+dz[i]);
if(ret>m){
m = ret;
t = i;
}
}
if(m>ask(mx.x, mx.y, mx.z)){
mx.x+=dx[t];
mx.y+=dy[t];
mx.z+=dz[t];
}else{
ans(mx.x, mx.y, mx.z);
return;
}
}
}
int main(){
scanf("%d%d%d%d", &N, &M, &K, &Q);
if(M==1 && K==1 && N==1000000){
pro1();
}else if(K==1){
pro2();
}else{
pro3();
}
return 0;
}
Compilation message (stderr)
worm.cpp: In function 'int ask(int, int, int)':
worm.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &ret);
~~~~~^~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:182:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &N, &M, &K, &Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |