题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem: Omkar and Modes
Time limit: 3 seconds
Memory limit: 256 MB
This is an interactive problem.
Ray lost his array and needs to find it by asking Omkar. Omkar is willing to disclose that the array has the following qualities:
1. The array has n (1 <= n <= 2 * 10^5) elements.
2. Every element in the array a_i is an integer in the range 1 <= a_i <= 10^9.
3. The array is sorted in nondecreasing order.
Ray is allowed to send Omkar a series of queries. A query consists of two integers, l and r such that 1 <= l <= r <= n. Omkar will respond with two integers, x and f.
- x is the mode of the subarray from index l to index r inclusive. The mode of an array is defined by the number that appears the most frequently. If there are multiple numbers that appear the most number of times, the smallest such number is considered to be the mode.
- f is the amount of times that x appears in the queried subarray.
The array has k (1 <= k <= min(25000, n)) distinct elements. However, due to Ray's sins, Omkar will not tell Ray what k is.
Help Ray find his lost array.
Input
The only line of the input contains a single integer n (1 <= n <= 2 * 10^5), which equals to the length of the array that you are trying to find.
Interaction Protocol
The interaction starts with reading n.
Then you can make one type of query:
"? l r" (without quotes) (1 <= l <= r <= n) where l and r are the bounds of the subarray that you wish to query.
The answer to each query will be in the form "x f" where x is the mode of the subarray and f is the number of times x appears in the subarray.
x satisfies (1 <= x <= 10^9).
f satisfies (1 <= f <= r - l + 1).
If you make an invalid query (violating ranges), you will get an output "-1". If you terminate after receiving the response "-1", you will get the "Wrong answer" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
To output your answer, print:
"! a_1 a_2 ... a_n" (without quotes) which is an exclamation point followed by the array with a space between every element. And quit after that. This query is not counted towards the query limit.
After printing a query do not forget to output end of line and flush the output.
Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Scoring
The physical objective is per-case array query count Q_j; smaller is better. The physical reference is `a = k_j`; matching a positive reference earns 60 points.
k_j is the number of distinct blocks in the hidden array; the implemented physical reference is max(1,k_j).
Define the historical low-score expression (in points):
P_low = 60*max(0,(12*k_j-Q_j)/(11*k_j))^2.
A valid solution with `Q_j=0` receives 100 points, including a zero-baseline instance. Otherwise, if `P_low<=60`, retain `max(0,P_low)`. For `P_low>60` and a positive physical reference, award:
r = a / Q_j
P = min(100, 60 + ln(r)).
Here `r` is the improvement factor relative to the physical reference, and `ln` is the natural logarithm with coefficient 1. In the uncapped upper branch, `r = exp(P-60)`: each additional point means an `exp(1)`-fold improvement in the physical objective. The factor is computed from the physical objective and its reference, not from a transformed reward or the old point score. Invalid output retains its existing rejection or zero score; the zero-cost exception applies only after validation. Apply this mapping to each internal case, then average the points. Both reported ratio channels use points divided by 100. Across official files, take the arithmetic mean.
Example Input:
6
2 2
2 2
3 2
2 1
Example Output:
? 1 6
? 1 3
? 4 6
? 3 4
! 1 1 2 3 3 4
结果
Kimi K3.1 ProKimi
max
38.5
平均得分 ↑
- 38.5采样 1 · 部分分
- 42.9k平均输出 token(含思考) ↓
- 30.2输出速度 tokens/s ↑
- 1426 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
46.3
平均得分 ↑
- 46.3采样 1 · 部分分
- 14.2k平均输出 token(含思考) ↓
- 24.7输出速度 tokens/s ↑
- 575 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
47.9
平均得分 ↑
- 47.9采样 1 · 部分分
- 80.9k平均输出 token(含思考) ↓
- 158.2输出速度 tokens/s ↑
- 512 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
23.0
平均得分 ↑
- 23.0采样 1 · 部分分
- 76.9k平均输出 token(含思考) ↓
- 78.1输出速度 tokens/s ↑
- 985 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 138 行
#include <bits/stdc++.h> using namespace std; struct Solver { int n; vector<int> answer; vector<int> pointValue; explicit Solver(int n) : n(n), answer(n + 1, 0), pointValue(n + 1, 0) {} pair<int, int> ask(int l, int r) { cout << "? " << l << ' ' << r << endl; int x, f; if (!(cin >> x >> f)) exit(0); if (x == -1) exit(0); return {x, f}; } int getPoint(int pos) { if (pointValue[pos] != 0) return pointValue[pos]; int value = ask(pos, pos).first; pointValue[pos] = value; return value; } void fillInterval(int l, int r, int value) { fill(answer.begin() + l, answer.begin() + r + 1, value); } int locateRun(int l, int r, int x, int f) { if (getPoint(l) == x) return l; if (getPoint(r) == x) return r - f + 1; const int maxStart = r - f; const int minEnd = l + f; const int remaining = (r - l + 1) - f; auto ordinaryBinarySearch = [&]() { int lo = l + 1, hi = maxStart; while (lo < hi) { int mid = (lo + hi) >> 1; if (getPoint(mid) < x) lo = mid + 1; else hi = mid; } return lo; }; int budget = 0; for (int t = remaining; t; t >>= 1) ++budget; int leftFalse = l; int rightFalse = r; long long leftStep = 1, rightStep = 1; int used = 0; while (true) { int p = (int)min<long long>(maxStart, (long long)l + leftStep); int value = getPoint(p); if (value >= x) { int lo = leftFalse + 1, hi = p; while (lo < hi) { int mid = (lo + hi) >> 1; if (getPoint(mid) < x) lo = mid + 1; else hi = mid; } return lo; } leftFalse = p; leftStep <<= 1; if (++used >= budget) return ordinaryBinarySearch(); int q = (int)max<long long>(minEnd, (long long)r - rightStep); value = getPoint(q); if (value <= x) { int lo = q, hi = rightFalse; while (hi - lo > 1) { int mid = (lo + hi) >> 1; if (getPoint(mid) <= x) lo = mid; else hi = mid; } return lo - f + 1; } rightFalse = q; rightStep <<= 1; if (++used >= budget) return ordinaryBinarySearch(); } } void solve(int l, int r) { if (l > r) return; if (l == r) { answer[l] = getPoint(l); return; } if (pointValue[l] != 0 && pointValue[l] == pointValue[r]) { fillInterval(l, r, pointValue[l]); return; } auto [x, f] = ask(l, r); if (f == r - l + 1) { fillInterval(l, r, x); return; } int start = locateRun(l, r, x, f); int finish = start + f - 1; fillInterval(start, finish, x); solve(l, start - 1); solve(finish + 1, r); } void run() { solve(1, n); cout << '!'; for (int i = 1; i <= n; ++i) cout << ' ' << answer[i]; cout << endl; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; Solver solver(n); solver.run(); return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 87 行
#include <bits/stdc++.h> using namespace std; int n; vector<int> answer_array; unordered_map<uint64_t, pair<int, int>> query_cache; pair<int, int> ask(int l, int r) { uint64_t key = (uint64_t(uint32_t(l)) << 32) | uint32_t(r); auto it = query_cache.find(key); if (it != query_cache.end()) return it->second; cout << "? " << l << " " << r << endl; int x, f; if (!(cin >> x >> f)) exit(0); if (x == -1) exit(0); return query_cache[key] = {x, f}; } void solve(int l, int r) { if (l > r) return; auto [x, f] = ask(l, r); if (f == r - l + 1) { for (int i = l; i <= r; ++i) answer_array[i] = x; return; } int p = -1; if (f == 1 || x == 1) { p = l + f - 1; } else if (x == 1000000000) { p = r; } else { int lo = l + f - 1; int hi = r; auto [y, c] = ask(l, lo); if (c == f) { p = lo; } else if (y == x) { p = lo + f - c; } else { ++lo; while (p == -1 && lo < hi) { int mid = lo + (hi - lo) / 2; auto [z, cnt] = ask(l, mid); if (cnt == f) { hi = mid; } else if (z == x) { p = mid + f - cnt; } else { lo = mid + 1; } } if (p == -1) p = lo; } } for (int i = p - f + 1; i <= p; ++i) answer_array[i] = x; solve(l, p - f); solve(p + 1, r); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; answer_array.assign(n + 1, 0); query_cache.reserve(1024); solve(1, n); cout << "!"; for (int i = 1; i <= n; ++i) { cout << " " << answer_array[i]; } cout << endl; return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 97 行
#include <bits/stdc++.h> using namespace std; struct Task { int l, r; int x, f; bool known; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ans(n + 1, 0); vector<Task> st; st.push_back({1, n, 0, 0, false}); auto ask = [&](int l, int r) -> pair<int, int> { cout << "? " << l << " " << r << '\n'; cout.flush(); int x, f; cin >> x >> f; return {x, f}; }; while (!st.empty()) { Task cur = st.back(); st.pop_back(); int l = cur.l, r = cur.r; if (l > r) continue; int x = cur.x, f = cur.f; if (!cur.known) { auto res = ask(l, r); x = res.first; f = res.second; } int len = r - l + 1; if (f == len) { fill(ans.begin() + l, ans.begin() + r + 1, x); continue; } if (f == 1) { ans[l] = x; if (l + 1 <= r) { st.push_back({l + 1, r, 0, 0, false}); } continue; } auto res = ask(l, l + f - 1); int y = res.first; int g = res.second; if (y == x) { int s; if (g == f) s = l; else s = l + f - g; int e = s + f - 1; fill(ans.begin() + s, ans.begin() + e + 1, x); if (l <= s - 1) { st.push_back({l, s - 1, 0, 0, false}); } if (e + 1 <= r) { st.push_back({e + 1, r, 0, 0, false}); } } else { if (len == f + g) { fill(ans.begin() + l, ans.begin() + l + g, y); fill(ans.begin() + l + g, ans.begin() + r + 1, x); } else { st.push_back({l, l + f - 1, y, g, true}); if (l + f <= r) { st.push_back({l + f, r, 0, 0, false}); } } } } cout << "!"; for (int i = 1; i <= n; ++i) { cout << ' ' << ans[i]; } cout << '\n'; cout.flush(); return 0; }
MiniMax M3.1 Flash · 采样 1 · 185 行
#include <bits/stdc++.h> using namespace std; struct Reply { int value; int frequency; }; struct Task { int l, r; int modeValue; int maxFrequency; }; struct Pivot { int start; int value; }; Reply ask(int l, int r) { cout << "? " << l << ' ' << r << '\n'; cout.flush(); int x, f; if (!(cin >> x) || x == -1) exit(0); if (!(cin >> f)) exit(0); return {x, f}; } /* The interval is aligned with block boundaries, and modeValue is its mode with frequency maxFrequency. The function finds either the leftmost or the rightmost block having frequency maxFrequency. */ Pivot locatePivot(int l, int r, int modeValue, int maxFrequency) { const int length = r - l + 1; // Try the last maxFrequency positions. int suffixStart = r - maxFrequency + 1; Reply suffixReply = ask(suffixStart, r); if (suffixReply.frequency == maxFrequency) { // A window of length maxFrequency is monochromatic. return {suffixStart, suffixReply.value}; } if (suffixReply.value == modeValue) { // The window ends inside the modeValue block. int start = suffixStart - maxFrequency + suffixReply.frequency; return {start, modeValue}; } // The first maxFrequency positions may directly locate the leftmost maximum. Reply prefixReply = ask(l, l + maxFrequency - 1); if (prefixReply.frequency == maxFrequency) { return {l, prefixReply.value}; } if (prefixReply.value == modeValue) { int start = l + maxFrequency - prefixReply.frequency; return {start, modeValue}; } /* For a suffix [p, r], its mode frequency equals maxFrequency exactly when p is at or before the start of the rightmost maximum-frequency block. Find the largest such p. */ int falseStart = suffixStart; long long distance = static_cast<long long>(maxFrequency) + 1; while (true) { if (distance >= length) distance = length; int start = r - static_cast<int>(distance) + 1; Reply current = ask(start, r); if (current.frequency == maxFrequency) { int low = start; // True. int high = falseStart; // False. Reply lowReply = current; while (high - low > 1) { int mid = low + (high - low) / 2; Reply middleReply = ask(mid, r); if (middleReply.frequency == maxFrequency) { low = mid; lowReply = middleReply; } else if (middleReply.value == modeValue) { int blockStart = mid - maxFrequency + middleReply.frequency; return {blockStart, modeValue}; } else { high = mid; } } return {low, lowReply.value}; } if (current.value == modeValue) { int blockStart = start - maxFrequency + current.frequency; return {blockStart, modeValue}; } falseStart = start; if (distance <= 2LL * maxFrequency) { distance = 2LL * maxFrequency; } else { distance *= 2; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; vector<int> answer(n + 1); vector<Task> tasks; tasks.reserve(2 * min(n, 25000)); tasks.push_back({1, n, 0, 0}); while (!tasks.empty()) { Task task = tasks.back(); tasks.pop_back(); int l = task.l; int r = task.r; if (l > r) continue; int modeValue = task.modeValue; int maxFrequency = task.maxFrequency; if (modeValue == 0) { Reply reply = ask(l, r); modeValue = reply.value; maxFrequency = reply.frequency; } if (maxFrequency == r - l + 1) { fill(answer.begin() + l, answer.begin() + r + 1, modeValue); continue; } Pivot pivot = locatePivot(l, r, modeValue, maxFrequency); int start = pivot.start; int value = pivot.value; int finish = start + maxFrequency - 1; fill(answer.begin() + start, answer.begin() + finish + 1, value); // The part to the right contains only smaller-frequency blocks. if (finish < r) { tasks.push_back({finish + 1, r, 0, 0}); } // If a different block was removed, modeValue remains the left mode. if (l < start) { if (value != modeValue) { tasks.push_back({l, start - 1, modeValue, maxFrequency}); } else { tasks.push_back({l, start - 1, 0, 0}); } } } cout << '!'; for (int i = 1; i <= n; ++i) { cout << ' ' << answer[i]; } cout << '\n'; cout.flush(); return 0; }