Submission #1328632

#TimeUsernameProblemLanguageResultExecution timeMemory
1328632huoiMađioničar (COI22_madionicar)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF 1e18

int query(int l, int r) {
    cout << "? " << l << " " << r << endl;
    int yes; cin >> yes;
    return yes;
}

int gans = 1;

int odd(int n) {
    auto check = [&](int x) {
        for (int i = 1; i <= n; i++) {
            int l = i - x;
            int r = i + x;
            if (l < 1 || r > n) continue;
            if (query(l, r)) return true;
        }
        return false;
    };
    int l = 0, r = n / 2, ans = 0;
    while (l <= r) {
        int m = (l + r) / 2;
        if (check(m)) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    return ans * 2 + 1;
}

int even(int n) {
    auto check = [&](int x) {
        for (int i = 1; i <= n; i++) {
            int l = i - x + 1;
            int r = i + x;
            if (l < 1 || r > n) continue;
            if (query(l, r)) return true;
        }
        return false;
    };
    int l = ans, r = n / 2, ans = 0;
    while (l <= r) {
        int m = (l + r) / 2;
        if (check(m)) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    return ans * 2;
}

void solve() {
    int n;
    cin >> n;
    int gans = odd(n);
    gans = max(gans, even(n));
    cout << "! " << gans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'long long int even(long long int)':
Main.cpp:48:13: error: 'ans' was not declared in this scope; did you mean 'gans'?
   48 |     int l = ans, r = n / 2, ans = 0;
      |             ^~~
      |             gans
Main.cpp:49:17: error: 'r' was not declared in this scope
   49 |     while (l <= r) {
      |                 ^