이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
const double phi = (sqrt(5) + 1) / 2.0;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
int X, Y, Z;
int Q;
vector<vector<vi>> arr;
int gMax;
int gMax_x, gMax_y, gMax_z;
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(arr[x][y][z] == 0){
cout<<"? "<<x<<" "<<y<<" "<<z<<endl;
cin>>ret;
arr[x][y][z] = ret;
}
else{
ret = arr[x][y][z];
}
if(ret > gMax){
gMax = ret;
gMax_x = x;
gMax_y = y;
gMax_z = z;
}
return ret;
}
int solve_1D(int L, int R, int mid){
//cerr<<"solve("<<L<<", "<<R<<", "<<mid<<") "<<endl;
if(L == R) return L;
int ml = L + floor((R-L) * (2-phi));
int mr = R - floor((R-L) * (2-phi));
//assert(ml <= mr);
if( mid*2 < L+R ){
ml = mid;
}
else{
mr = mid;
}
//assert(ml <= mr);
int vl = query(ml, 1, 1);
int vr = query(mr, 1, 1);
if(vl > vr){
return solve_1D(L, mr - 1, ml);
}
else{
return solve_1D(ml + 1, R, mr);
}
}
int dx[6] = {1, -1, 0, 0, 0, 0};
int dy[6] = {0, 0, 1, -1, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};
bool isMax(int x, int y, int z){
bool ret = 1;
FOR(i, 0, 5, 1){
if( query(x, y, z) < query(x+dx[i], y+dy[i], z+dz[i]) ){
ret = 0;
}
}
return ret;
}
pii solve_2D(int xL, int xR, int yL, int yR){
//cerr<<"solve("<<xL<<", "<<xR<<", "<<yL<<", "<<yR<<")"<<endl;
assert(xL<=gMax_x and gMax_x<=xR and yL<=gMax_y and gMax_y<=yR);
if(xR-xL<=1 and yR-yL<=1){
FOR(i, xL, xR, 1){
FOR(j, yL, yR, 1){
if(isMax(i, j, 1)){
return mkp(i, j);
}
}
}
}
if(xR-xL > yR-yL){ /// cut x
int xmid = (xL + xR) / 2;
FOR(i, yL, yR, 1){
query(xmid, i, 1);
}
query(xmid-1, gMax_y, 1);
query(xmid+1, gMax_y, 1);
if(gMax_x == xmid){
return mkp(xmid, gMax_y);
}
else if(gMax_x < xmid){
return solve_2D(xL, xmid-1, yL, yR);
}
else{
return solve_2D(xmid+1, xR, yL, yR);
}
}
else{ /// cut y
int ymid = (yL + yR) / 2;
FOR(i, xL, xR, 1){
query(i, ymid, 1);
}
query(gMax_x, ymid-1, 1);
query(gMax_x, ymid+1, 1);
if(gMax_y == ymid){
return mkp(gMax_x, ymid);
}
else if(gMax_y < ymid){
return solve_2D(xL, xR, yL, ymid-1);
}
else{
return solve_2D(xL, xR, ymid+1, yR);
}
}
}
int randll(int r){
int a = rand();
int b = rand();
int c = rand();
int d = rand();
return ((a<<36) ^ (b<<24) ^ (c<<12) ^ d) % r;
}
pair<pii,int> solve_3D(){
int pick = Q/2;
FOR(i, 1, pick, 1){
int x = randll(X) + 1;
int y = randll(Y) + 1;
int z = randll(Z) + 1;
query(x, y, z);
}
int px = gMax_x, py = gMax_y, pz = gMax_z;
while(!isMax(px, py, pz)){
px = gMax_x, py = gMax_y, pz = gMax_z;
}
return mkp(mkp(px, py), pz);
}
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);
}
}
gMax = -INF;
gMax_x = 1;
gMax_y = 1;
gMax_z = 1;
if(Y==1 and Z==1){
int res = solve_1D(1, X, 1 + (X-1)*(phi-1));
cout<<"! "<<res<<" 1 1"<<endl;
}
else if(Z==1){
pii res = solve_2D(1, X, 1, Y);
cout<<"! "<<res.F<<" "<<res.S<<" 1"<<endl;
}
else{
auto res = solve_3D();
cout<<"! "<<res.F.F<<" "<<res.F.S<<" "<<res.S<<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... |