Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //weinerschitzel
- //https://codeforces.com/gym/102341/problem/C
- //
- //misaka and elaina will carry me to master
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <utility>
- #include <cassert>
- #include <algorithm>
- #include <vector>
- #include <functional>
- #include <numeric>
- #include <set>
- #include <array>
- #include <queue>
- #include <map>
- #include <chrono>
- #include <random>
- #define ll long long
- #define lb long double
- #define sz(vec) ((int)(vec.size()))
- #define all(x) x.begin(), x.end()
- #define pb push_back
- #define mp make_pair
- #define kill(x, s) {int COND = x; if(COND){ cout << s << "\n"; return ; }}
- #ifdef ONLINE_JUDGE
- #define cerr while(0) cerr
- #endif
- const lb eps = 1e-9;
- const ll mod = 1e9 + 7, ll_max = 1e18;
- //const ll mod = (1 << (23)) * 119 +1, ll_max = 1e18;
- const int MX = 2e3 +10, int_max = 0x3f3f3f3f;
- struct {
- template<class T>
- operator T() {
- T x; std::cin >> x; return x;
- }
- } in;
- using namespace std;
- mt19937 rng(3366);
- int n;
- int arr[MX][MX];
- int op;
- int query(int x, int y){
- if(x < 0 || y < 0 || x >= n || y >= n) return 0;
- if(arr[x][y]) return arr[x][y];
- op++;
- cout << "? " << x+1 << " " << y+1 << endl;
- int a; cin >> a;
- //int a = rng()%(1000000000);
- return arr[x][y] = a;
- }
- int mxin(int a, int b, int c, int d){
- int ans = 0;
- for(int i = a; i<b; i++){
- for(int j = c; j<d; j++){
- ans = max(ans, arr[i][j]);
- }
- }
- return ans;
- }
- void go(int a, int b, int c, int d){
- if(a + 1 == b && c + 1 == d){
- assert(op <= n*3 +210);
- cout << "! " << a+1 << " " << c+1 << endl;
- return ;
- }
- int m1 = (a + b)/2, m2 = (c + d)/2;
- if(b - a > d - c){ //split the longer one
- int best = c;
- for(int i = c; i<d; i++){
- if(query(m1, i) > query(m1, best)){
- best = i;
- }
- }
- for(int i = -1; i<=1; i++){
- for(int j = -1; j<=1; j++){
- query(m1 + i, best + j);
- }
- }
- if(mxin(a, m1, c, d) > mxin(m1, b, c, d)){
- go(a, m1, c, d);
- }else{
- go(m1, b, c, d);
- }
- }else{
- int best = a;
- for(int i = a; i<b; i++){
- if(query(i, m2) >= query(best, m2)){
- best = i;
- }
- }
- for(int i = -1; i<=1; i++){
- for(int j = -1; j<=1; j++){
- query(best + i, m2 + j);
- }
- }
- if(mxin(a, b, c, m2) > mxin(a, b, m2, d)){
- go(a, b, c, m2);
- }else{
- go(a, b, m2, d);
- }
- }
- }
- void solve(){
- cin >> n;
- go(0, n, 0, n);
- }
- signed main(){
- cin.tie(0) -> sync_with_stdio(0);
- int T = 1;
- //cin >> T;
- for(int i = 1; i<=T; i++){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement