結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2019-07-05 22:20:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,073 bytes |
| コンパイル時間 | 673 ms |
| コンパイル使用メモリ | 55,384 KB |
| 実行使用メモリ | 25,604 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-07-16 17:21:52 |
| 合計ジャッジ時間 | 3,458 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
int query(int x, int y, int n) {
if (y < 0 || y >= n) return x;
if (x < 0 || x >= n) return y;
cout << "? " << x + 1 << " " << y + 1 << endl;
int ret;
cin >> ret;
return ret - 1;
}
const int DEPTH = 9;
int seg[1 << (DEPTH + 1)];
void init(int n) {
int i;
rep(i, (1 << (DEPTH + 1))) seg[i] = -1;
rep(i, n) seg[(1 << DEPTH) - 1 + i] = i;
}
int construct(int n, int a = 0, int b = (1 << DEPTH), int id = 0) {
if (b - a == 1) {
return seg[id];
}
int u = construct(n, a, (a + b) / 2, id * 2 + 1);
int v = construct(n, a, (a + b) / 2, id * 2 + 2);
int res = query(u, v, n);
seg[id] = res;
return res;
}
int update(int pos, int val, int n) {
pos += (1 << DEPTH) - 1;
seg[pos] = val;
while (pos > 0) {
pos = (pos - 1) / 2;
int res = query(seg[pos * 2 + 1], seg[pos * 2 + 2], n);
seg[pos] = res;
}
return seg[0];
}
int main() {
int n;
cin >> n;
init(n);
int winner = construct(n);
int ans = update(winner, -1, n);
cout << "! " << ans + 1 << endl;
return 0;
}
startcpp