题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Time Limit: 2 s
Memory Limit: 256 MB
This is an interactive problem.
There are n students, having roll numbers 1 to n. Mr. 1048576 knows that exactly 1 student is absent today. In order to determine who is absent, he can ask some queries to the class. In each query, he provide two integers l and r (1≤l≤r≤n) and all students whose roll numbers are between l and r (inclusive) are expected to raise their hands.
But the students are dishonest. Some students whose roll numbers lie in the given range may not raise their hands, while some other students whose roll number does not lie in the given range may raise their hands. But only the following 4 cases are possible for a particular query (l,r) —
1. True Positive: r−l+1 students are present and r−l+1 students raised their hands.
2. True Negative: r−l students are present and r−l students raised their hands.
3. False Positive: r−l students are present but r−l+1 students raised their hands.
4. False Negative: r−l+1 students are present but r−l students raised their hands.
In the first two cases, the students are said to be answering honestly, while in the last two cases, the students are said to be answering dishonestly. The students can mutually decide upon their strategy, not known to Mr. 1048576. Also, their strategy always meets the following two conditions —
1. The students will never answer honestly 3 times in a row.
2. The students will never answer dishonestly 3 times in a row.
Mr. 1048576 is willing to mark at most 2 students as absent (though he knows that only one is). The attendance is said to be successful if the student who is actually absent is among those two. Also, he can only ask up to 2* ⌈log_{1.116}n⌉ queries. Help him complete a successful attendance.
Interaction
First read a line containing a single integer t (1≤t≤2048) denoting the number of independent test cases that you must solve.
For each test case, first read a line containing a single integer n (5≤n≤10^5). Then you may ask up to 2* ⌈log_{1.116}n⌉ queries.
Your score depends on the query count as specified below.
To ask a query, print a single line in the format "? l r" (without quotes) (1≤l≤r≤n). Then read a single line containing a single integer x (r−l≤x≤r−l+1) denoting the number of students who raised their hands corresponding to the query.
To mark a student as absent, print a single line in the format "! a" (without quotes) (1≤a≤n). Then read a single integer y (y∈{0,1}). If the student with roll number a was absent, y=1, else, y=0. Note that this operation does not count as a query but you can do this operation at most 2 times.
To end a test case, print a single line in the format "#" (without quotes). Then you must continue solving the remaining test cases.
The sum of n over all test cases does not exceed 10^5.
To flush the buffer, use fflush(stdout) or cout.flush()
The answer may change depending on your queries but will always remain consistent with the constraints and the answer to the previous queries.
Example
input
2
5
3
2
1
2
0
1
0
2
0
1
6
6
2
2
0
1
1
0
0
0
1
output
? 1 4
? 3 5
? 2 2
? 1 3
? 3 3
? 3 3
! 3
? 2 4
? 4 4
! 2
#
? 1 6
? 1 3
? 4 6
? 1 1
? 3 3
? 5 5
! 3
? 2 2
? 4 4
! 4
#
## Scoring
All feasibility and interaction limits apply before scoring; invalid output receives zero. Points are averaged over test files. For the logarithmic branch, write x for the original minimizing quantity and a for its physical 60-point reference. The improvement factor is r=a/x, and the upper-band award is P=min(100,60+ln(r)). Here ln is natural: r=1 corresponds to 60 points, and on the uncapped logarithmic upper band, r=exp(P-60). Each additional point multiplies the physical improvement factor by e (divides a minimizing objective by e or multiplies a maximizing objective by e, as applicable). The lower-band, zero-objective, and completion rules below still apply.
For subcase j, let Q_j be its query count and L_j>1 its query limit. Define the per-subcase physical reference a_j=A_j=0.4*L_j+0.6 and B_j=100*min(1,max(0,(L_j-Q_j)/(L_j-1))). Guess actions are not queries.
For a valid subcase, award 100 if Q_j=0; otherwise award B_j when B_j<=60, and min(100,60+ln(r_j)) when B_j>60, where x_j=Q_j and r_j=a_j/x_j. The file score is the minimum subcase award. A failed subcase gives zero for the file. The checker reports the file score divided by 100.
结果
Kimi K3.1 ProKimi
max
0.0
平均得分 ↑
- 0.0采样 1 · 编译错误
- 47.9k平均输出 token(含思考) ↓
- 27.1输出速度 tokens/s ↑
- 1768 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
35.3
平均得分 ↑
- 35.3采样 1 · 部分分
- 25.5k平均输出 token(含思考) ↓
- 24.0输出速度 tokens/s ↑
- 1066 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
0.0
平均得分 ↑
- 0.0采样 1 · 答案错误
- 63.1k平均输出 token(含思考) ↓
- 169.7输出速度 tokens/s ↑
- 373 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
0.0
平均得分 ↑
- 0.0采样 1 · 答案错误
- 83.9k平均输出 token(含思考) ↓
- 88.3输出速度 tokens/s ↑
- 952 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 251 行
#include <bits/stdc++.h> using namespace std; const int NXT[4][2] = { {1, 2}, {-1, 2}, {0, 3}, {0, -1} }; struct Endgame { static const int INF = 1000000000; vector<int> dist, move; vector<vector<int>> patterns; static int nextConfig(int key, int qmask, int reply) { int m = key >> 8; int states = key & 255; int newMask = 0, newM = 0; for (int i = 0; i < m; i++) { int s = (states >> (2 * i)) & 3; int b = (qmask >> i) & 1; int h = reply ^ b; int ns = NXT[s][h]; if (ns != -1) { newMask |= ns << (2 * newM); newM++; } } if (newM <= 2) return -1; return (newM << 8) | newMask; } Endgame() { dist.assign(5 << 8, INF); move.assign(5 << 8, -1); patterns.resize(5); for (int m = 3; m <= 4; m++) { for (int i = 0; i < m; i++) { for (int j = i; j < m; j++) { int mask = 0; for (int k = i; k <= j; k++) mask |= 1 << k; patterns[m].push_back(mask); } } } vector<int> configs; for (int m = 3; m <= 4; m++) { int lim = 1 << (2 * m); for (int mask = 0; mask < lim; mask++) { configs.push_back((m << 8) | mask); } } for (int pass = 0; pass < 1000; pass++) { bool changed = false; for (int key : configs) { int m = key >> 8; int best = dist[key]; int bestMove = move[key]; for (int qmask : patterns[m]) { bool ok = true; int worst = 0; for (int reply = 0; reply < 2; reply++) { int nk = nextConfig(key, qmask, reply); if (nk == -1) continue; if (dist[nk] >= INF) { ok = false; break; } worst = max(worst, dist[nk]); } if (ok && worst + 1 < best) { best = worst + 1; bestMove = qmask; } } if (best < dist[key]) { dist[key] = best; move[key] = bestMove; changed = true; } } if (!changed) break; } } }; struct Candidate { int roll, state; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Endgame endgame; int T; cin >> T; const long double PHI = (1.0L + sqrtl(5.0L)) / 2.0L; while (T--) { int n; cin >> n; vector<Candidate> candidates; candidates.reserve(n); auto ask = [&](int l, int r) { cout << "? " << l << ' ' << r << '\n' << flush; int x; cin >> x; return x - (r - l); }; auto applyQuery = [&](int l, int r, int reply) { vector<Candidate> next; next.reserve(candidates.size()); for (const Candidate &c : candidates) { int b = (l <= c.roll && c.roll <= r) ? 1 : 0; int h = reply ^ b; int ns = NXT[c.state][h]; if (ns != -1) next.push_back({c.roll, ns}); } candidates.swap(next); }; int firstReply = ask(1, n); int firstHonesty = firstReply ^ 1; int initialState = (firstHonesty == 0 ? 0 : 2); for (int i = 1; i <= n; i++) { candidates.push_back({i, initialState}); } auto configurationKey = [&]() { int m = (int)candidates.size(); int mask = 0; for (int i = 0; i < m; i++) { mask |= candidates[i].state << (2 * i); } return (m << 8) | mask; }; while (candidates.size() > 2) { bool usedEndgame = false; if (candidates.size() <= 4) { int key = configurationKey(); if (endgame.dist[key] < Endgame::INF && endgame.move[key] != -1) { int qmask = endgame.move[key]; int first = -1, last = -1; for (int i = 0; i < (int)candidates.size(); i++) { if ((qmask >> i) & 1) { if (first == -1) first = i; last = i; } } int l = candidates[first].roll; int r = candidates[last].roll; int reply = ask(l, r); applyQuery(l, r, reply); usedEndgame = true; } } if (usedEndgame) continue; int m = candidates.size(); vector<long double> d(m); long double U = 0, V = 0; for (int i = 0; i < m; i++) { int s = candidates[i].state; long double u, v; if (s == 0) { u = 1; v = PHI; } else if (s == 1) { u = 0; v = PHI; } else if (s == 2) { u = PHI; v = 1; } else { u = PHI; v = 0; } U += u; V += v; d[i] = v - u; } long double target = (V - U) / 2; long double prefix = 0; long double bestDifference = numeric_limits<long double>::infinity(); int bestR = n; int index = 0; for (int r = 1; r <= n; r++) { while (index < m && candidates[index].roll == r) { prefix += d[index]; index++; } long double difference = fabsl(prefix - target); if (difference < bestDifference) { bestDifference = difference; bestR = r; } } int reply = ask(1, bestR); applyQuery(1, bestR, reply); } auto guess = [&](int roll) { cout << "! " << roll << '\n' << flush; int y; cin >> y; return y; }; int result = guess(candidates[0].roll); if (result == 0 && candidates.size() > 1) { guess(candidates[1].roll); } cout << "#\n" << flush; } return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 189 行
#include <bits/stdc++.h> using namespace std; struct Candidate { int roll; int h = 0; int run = 0; }; static vector<Candidate> applyAnswer(const vector<Candidate>& cs, const vector<int>& z, int y) { vector<Candidate> nxt; for (int i = 0; i < (int)cs.size(); ++i) { int required = y ^ z[i]; Candidate d = cs[i]; if (d.run == 0) { d.h = required; d.run = 1; } else { if (d.run == 2 && required == d.h) continue; if (required == d.h) { d.run = 2; } else { d.h = required; d.run = 1; } } nxt.push_back(d); } return nxt; } static const vector<pair<int, int>> smallBounds = { {0, 0}, {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 2} }; static vector<vector<int>> smallPatterns() { vector<vector<int>> p; for (auto [a, b] : smallBounds) { vector<int> z(3, 0); for (int i = a; i <= b; ++i) z[i] = 1; p.push_back(z); } return p; } static const vector<vector<int>> patterns3 = smallPatterns(); static unordered_map<string, int> memoSmall; static unordered_map<string, int> choiceSmall; static string smallKey(const vector<Candidate>& cs, int depth) { string s = to_string(depth) + ":"; for (const auto& c : cs) { s.push_back(char('0' + c.h * 2 + (c.run - 1))); s.push_back(','); } return s; } static bool solveSmall(const vector<Candidate>& cs, int depth) { if ((int)cs.size() <= 2) return true; if (depth == 0) return false; string key = smallKey(cs, depth); auto it = memoSmall.find(key); if (it != memoSmall.end()) return it->second; for (int p = 0; p < 6; ++p) { bool ok = true; for (int y = 0; y <= 1; ++y) { vector<Candidate> nxt = applyAnswer(cs, patterns3[p], y); if (!nxt.empty() && !solveSmall(nxt, depth - 1)) { ok = false; break; } } if (ok) { memoSmall[key] = 1; choiceSmall[key] = p; return true; } } memoSmall[key] = 0; return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<Candidate> cs(n); for (int i = 0; i < n; ++i) cs[i].roll = i + 1; int queryCount = 0; auto ask = [&](int l, int r) { cout << "? " << l << " " << r << endl; int x; cin >> x; ++queryCount; int len = r - l + 1; int y = (x == len ? 1 : 0); vector<int> z(cs.size(), 0); for (int i = 0; i < (int)cs.size(); ++i) { if (l <= cs[i].roll && cs[i].roll <= r) z[i] = 1; } cs = applyAnswer(cs, z, y); }; auto synchronized = [&]() { if (cs.empty()) return true; int h = cs[0].h; for (const auto& c : cs) { if (c.run != 1 || c.h != h) return false; } return true; }; ask(1, n); while ((int)cs.size() > 3) { int m = cs.size(); int firstCount = m / 2; ask(1, cs[firstCount - 1].roll); m = cs.size(); if (cs[0].run == 2) { int runTwoCount = 0; while (runTwoCount < m && cs[runTwoCount].run == 2) { ++runTwoCount; } int take = runTwoCount / 2; ask(1, cs[take - 1].roll); } else { int start = 0; while (start < m && cs[start].run != 2) ++start; int runTwoCount = m - start; int take = runTwoCount / 2; ask(1, cs[start + take - 1].roll); } if ((int)cs.size() > 3) { while (!synchronized()) ask(1, n); } } if ((int)cs.size() > 2) { memoSmall.clear(); choiceSmall.clear(); int depth = 1; while (!solveSmall(cs, depth)) ++depth; while ((int)cs.size() > 2) { string key = smallKey(cs, depth); int p = choiceSmall[key]; auto [a, b] = smallBounds[p]; ask(cs[a].roll, cs[b].roll); --depth; } } if (!cs.empty()) { cout << "! " << cs[0].roll << endl; int result; cin >> result; if (result == 0 && cs.size() == 2) { cout << "! " << cs[1].roll << endl; cin >> result; } } cout << "#" << endl; } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 139 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; double logn = log((double)n); double logbase = log(1.116); int max_q = 2 * (int)ceil(logn / logbase - 1e-12); vector<int> state(n + 1, 0); vector<char> valid(n + 1, 1); vector<int> valid_positions; valid_positions.reserve(n); for (int i = 1; i <= n; ++i) valid_positions.push_back(i); int h1, h2; { cout << "? 1 " << n << endl; int x; cin >> x; int c = (x == n) ? 1 : 0; h1 = c ^ 1; } { cout << "? 1 " << n << endl; int x; cin >> x; int c = (x == n) ? 1 : 0; h2 = c ^ 1; } int init_state = (h1 << 1) | h2; for (int i = 1; i <= n; ++i) state[i] = init_state; int queries_used = 2; while (queries_used < max_q && valid_positions.size() > 2) { int U0 = 0, U1 = 0; for (int i = 1; i <= n; ++i) { if (!valid[i]) continue; if (state[i] == 0) ++U0; else if (state[i] == 3) ++U1; } int D = U1 - U0; int W0_floor = (int)floor(D / 2.0); int OFFSET = n + 2; int sz = 2 * n + 5; vector<int> last_pos(sz, -1); int P = 0; int minPrev = 0, maxPrev = 0; last_pos[P + OFFSET] = 0; int best_f = -1; int best_l = 1, best_r = 1; for (int r = 1; r <= n; ++r) { int w = 0; if (valid[r]) { if (state[r] == 3) w = 1; else if (state[r] == 0) w = -1; } P += w; int L = P - maxPrev; int R = P - minPrev; auto consider = [&](int Wc) { if (Wc < L || Wc > R) return; int v = P - Wc; int j = last_pos[v + OFFSET]; if (j == -1) return; int f_val = min(U0 + Wc, U1 - Wc); if (f_val > best_f) { best_f = f_val; best_l = j + 1; best_r = r; } }; consider(L); consider(R); consider(W0_floor); consider(W0_floor + 1); if (P < minPrev) minPrev = P; if (P > maxPrev) maxPrev = P; last_pos[P + OFFSET] = r; } if (best_f == 0) { int V = valid_positions.size(); if (V > 1) { int median_pos = valid_positions[V / 2]; best_l = 1; best_r = median_pos; } else if (V == 1) { best_l = best_r = valid_positions[0]; } } int l = best_l, r = best_r; cout << "? " << l << " " << r << endl; int x; cin >> x; int len = r - l + 1; int c = (x == len) ? 1 : 0; for (int i = 1; i <= n; ++i) { if (!valid[i]) continue; int A = (l <= i && i <= r) ? 1 : 0; int new_h = c ^ A; int s = state[i]; if ((s == 0 && new_h == 0) || (s == 3 && new_h == 1)) { valid[i] = 0; } else { state[i] = ((s & 1) << 1) | new_h; } } valid_positions.clear(); for (int i = 1; i <= n; ++i) { if (valid[i]) valid_positions.push_back(i); } ++queries_used; } if (!valid_positions.empty()) { int pos = valid_positions[0]; cout << "! " << pos << endl; int y; cin >> y; if (y == 0 && valid_positions.size() > 1) { pos = valid_positions[1]; cout << "! " << pos << endl; cin >> y; } } else { cout << "! 1" << endl; int y; cin >> y; } cout << "#" << endl; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 279 行
#include <bits/stdc++.h> using namespace std; struct Candidate { int pos; int group; int older = -1; int last = -1; bool alive = true; }; class ThreeCandidateSolver { static constexpr int STATES = 125; static constexpr int INF = 1e9; int pw[3] = {1, 5, 25}; const array<int, 7> masks = {0, 1, 2, 3, 4, 6, 7}; int aliveCount(int state) const { int result = 0; for (int i = 0; i < 3; ++i) { int digit = (state / pw[i]) % 5; if (digit != 4) ++result; } return result; } int transition(int state, int mask, int response) const { int nextState = 0; for (int i = 0; i < 3; ++i) { int digit = (state / pw[i]) % 5; if (digit == 4) { nextState += 4 * pw[i]; continue; } int older = digit >> 1; int last = digit & 1; int inside = (mask >> i) & 1; int honest = response ^ inside; if (older == last && last == honest) { digit = 4; } else { digit = (last << 1) | honest; } nextState += digit * pw[i]; } return nextState; } public: array<int, STATES> distance{}; array<int, STATES> action{}; ThreeCandidateSolver() { distance.fill(INF); action.fill(-1); for (int state = 0; state < STATES; ++state) { if (aliveCount(state) <= 2) { distance[state] = 0; } } bool changed = true; while (changed) { changed = false; for (int state = 0; state < STATES; ++state) { if (distance[state] != INF) continue; int bestDistance = INF; int bestAction = -1; for (int mask : masks) { bool possible = true; int maximumNextDistance = 0; for (int response = 0; response <= 1; ++response) { int nextState = transition(state, mask, response); if (distance[nextState] == INF) { possible = false; break; } maximumNextDistance = max(maximumNextDistance, distance[nextState]); } if (possible && maximumNextDistance + 1 < bestDistance) { bestDistance = maximumNextDistance + 1; bestAction = mask; } } if (bestAction != -1) { distance[state] = bestDistance; action[state] = bestAction; changed = true; } } } } }; static int ask(int l, int r) { cout << "? " << l << ' ' << r << endl; int x; if (!(cin >> x)) exit(0); return x - (r - l); } static void applyResponse(vector<Candidate> &candidates, int response, int selectedGroup) { for (Candidate &candidate : candidates) { if (!candidate.alive) continue; int inside = (candidate.group == selectedGroup); int honest = response ^ inside; if (candidate.older == candidate.last && candidate.last == honest) { candidate.alive = false; } else { candidate.older = candidate.last; candidate.last = honest; } } } static void removeDead(vector<Candidate> &candidates) { vector<Candidate> remaining; remaining.reserve(candidates.size()); for (const Candidate &candidate : candidates) { if (candidate.alive) remaining.push_back(candidate); } candidates.swap(remaining); } static pair<int, int> intervalForMask(const vector<Candidate> &candidates, int mask, int n) { if (mask == 0) { int freePosition = 1; while (freePosition <= n && (freePosition == candidates[0].pos || freePosition == candidates[1].pos || freePosition == candidates[2].pos)) { ++freePosition; } return {freePosition, freePosition}; } if (mask == 1) return {candidates[2].pos, candidates[2].pos}; if (mask == 2) return {candidates[1].pos, candidates[1].pos}; if (mask == 3) return {candidates[1].pos, candidates[2].pos}; if (mask == 4) return {candidates[0].pos, candidates[0].pos}; if (mask == 6) return {candidates[0].pos, candidates[1].pos}; return {candidates[0].pos, candidates[2].pos}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; if (!(cin >> t)) return 0; ThreeCandidateSolver solver; while (t--) { int n; cin >> n; vector<Candidate> candidates; candidates.reserve(n); for (int position = 1; position <= n; ++position) { candidates.push_back({position, -1, -1, -1, true}); } while (candidates.size() > 3) { int m = static_cast<int>(candidates.size()); int groupSize[4]; int base = m / 4; int remainder = m % 4; for (int group = 0; group < 4; ++group) { groupSize[group] = base + (group < remainder); } int index = 0; for (int group = 0; group < 4; ++group) { for (int j = 0; j < groupSize[group]; ++j) { candidates[index++].group = group; } } int starts[4]; starts[0] = 0; for (int group = 1; group < 4; ++group) { starts[group] = starts[group - 1] + groupSize[group - 1]; } for (int selectedGroup = 1; selectedGroup <= 3; ++selectedGroup) { int l = candidates[starts[selectedGroup]].pos; int r = candidates[starts[selectedGroup] + groupSize[selectedGroup] - 1].pos; int response = ask(l, r); applyResponse(candidates, response, selectedGroup); } removeDead(candidates); } if (candidates.size() == 3) { while (candidates.size() == 3) { int state = 0; for (int i = 0; i < 3; ++i) { int pairCode = (candidates[i].older << 1) | candidates[i].last; state += pairCode * (i == 0 ? 1 : (i == 1 ? 5 : 25)); } int mask = solver.action[state]; if (mask == -1) { mask = 7; } auto [l, r] = intervalForMask(candidates, mask, n); int response = ask(l, r); for (int i = 0; i < 3; ++i) { if (!candidates[i].alive) continue; int inside = (mask >> i) & 1; int honest = response ^ inside; if (candidates[i].older == candidates[i].last && candidates[i].last == honest) { candidates[i].alive = false; } else { candidates[i].older = candidates[i].last; candidates[i].last = honest; } } removeDead(candidates); } } if (!candidates.empty()) { cout << "! " << candidates[0].pos << endl; int result; cin >> result; if (result == 0 && candidates.size() > 1) { cout << "! " << candidates[1].pos << endl; cin >> result; } } cout << "#" << endl; } return 0; }