QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666296#8941. Even or Odd Spanning Treexh_team#TL 0ms0kbC++201.8kb2024-10-22 17:38:072024-10-22 17:38:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 17:38:16]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-22 17:38:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2014;

mt19937 rnd(time(0));

int a[] = {-1, 4, 7, 2, 6, 5, 1, 9};

int ask(int l, int r) {
    cout << '?' << ' ' << l << ' ' << r << endl;
    int x;
    cin >> x;
    return x;


    // int fi = -1, se = -1;
    // for (int i = l; i <= r; i++) {
    //     fi = max(fi, a[i]);
    // }
    // int x = -1;
    // for (int i = l; i <= r; i++) {
    //     if (a[i] != fi && a[i] > se) {
    //         se = a[i];
    //         x = i;
    //     }
    // }
    // return x;
}

int n, p, ans;
void dfs(int l, int r) {
    if (r - l == 1) {
        ans = l + r - p;
        return;
    }
    if (r - l == 2) {
        if (p == l) {
            int q = ask(l + 1, r);
            ans = l + 1 + r - q;
        } else if (p == r) {
            int q = ask(l, l + 1);
            ans = l + l + 1 - q;
        } else {
            int q = ask(l, l + 1);
            if (p == q) {
                ans = l;
            } else {
                ans = r;
            }
        }
        return;
    }
    int mid = l - 1 + (rnd() & 1 ? (r - l + 1) / 3 : (r - l + 1) / 3 * 2);
    if (l == mid) mid++;
    if (mid + 1 == r) mid--;
    if (p <= mid) {
        int q = ask(l, mid);
        if (p == q) {
            dfs(l, mid);
        } else {
            p = ask(mid + 1, r);
            dfs(mid + 1, r);
        }
    } else {
        int q = ask(mid + 1, r);
        if (p == q) {
            dfs(mid + 1, r);
        } else {
            p = ask(l, mid);
            dfs(l, mid);
        }
    }

}

void solve() {
    cin >> n;
    p = ask(1, n);
    dfs(1, n);
    cout << '!' << ' ' << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);

    int tt;
    cin >> tt;
    while (tt--) solve();

    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

3
2 1
1 2 5
3 1
1 3 1
4 4
1 2 1
1 3 1
1 4 1
2 4 2

output:

? 1 2
! 2
? 1 1
? 0 1
? 1 -1
? 1 -1
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
? 1 0
...

result: