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>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define rep(n) for (int i = 0; i < n; ++i)
#define rep2(n) for (int j = 0; j < n; ++j)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
array<int, 3> max_id (int i, int j1, int k1, int j2, int k2) {
int ma = 0, cur, idj = j1, idk = k2;
for (int j = j1; j <= j2; ++j) {
for (int k = k1; k <= k2; ++k) {
cout << "? " << i << " " << j << " " << k << "\n" << flush;
cin >> cur;
if (cur==-1) return {-1, -1, -1};
if (cur>ma) {
ma = cur;
idj = j, idk = k;
}
}
}
return {ma, idj, idk};
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k, q;
cin >> n >> m >> k >> q;
int lo = 1, hi = n, mid, l, r;
array<int, 3> a;
while (lo<hi) {
mid = (lo+hi)/2, l = 0, r = 0;
a = max_id(mid, 1, 1, m, k);
if (a[0]==-1) return 0;
if (mid>1) {
cout << "? " << mid-1 << " " << a[1] << " " << a[2] << "\n" << flush;
cin >> l;
if (l==-1) return 0;
if (l>a[0]) {
hi = mid-1;
continue;
}
}
if (mid<n) {
cout << "? " << mid+1 << " " << a[1] << " " << a[2] << "\n" << flush;
cin >> r;
if (r==-1) return 0;
if (r>a[0]) {
lo = mid+1;
continue;
}
}
break;
}
cout << "! " << lo << " " << a[1] << " " << a[2] << "\n" << flush;
return 0;
}
Compilation message (stderr)
worm.cpp: In function 'int main()':
worm.cpp:64:57: warning: '*((void*)& a +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | cout << "! " << lo << " " << a[1] << " " << a[2] << "\n" << flush;
| ^~~~
worm.cpp:64:42: warning: '*((void*)& a +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | cout << "! " << lo << " " << a[1] << " " << a[2] << "\n" << flush;
| ^~~
# | 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... |