Submission #74126455
Source Code Expand
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(N);
vector<int> cnt(M + 1, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
cnt[A[i]]++;
}
map<int, vector<int>> buckets;
for (int v = 1; v <= M; v++) {
buckets[cnt[v]].push_back(v);
}
for (auto& [c, vec] : buckets) {
sort(vec.begin(), vec.end());
}
vector<int> seq = A;
int total_ops = 0;
bool balanced = false;
while (!balanced && total_ops < 2000000) {
auto it = buckets.begin();
int cur_cnt = it->first;
vector<int>& nums = it->second;
int batch_size = nums.size();
if (batch_size == M) {
balanced = true;
break;
}
for (int v : nums) {
seq.push_back(v);
}
total_ops += batch_size;
vector<int> moved = std::move(nums);
buckets.erase(it);
int next_cnt = cur_cnt + 1;
auto& next_bucket = buckets[next_cnt];
if (next_bucket.empty()) {
next_bucket = std::move(moved);
} else {
vector<int> merged;
merge(next_bucket.begin(), next_bucket.end(),
moved.begin(), moved.end(),
back_inserter(merged));
next_bucket = std::move(merged);
}
}
int Q;
cin >> Q;
while (Q--) {
int X;
cin >> X;
if (X <= N) {
cout << A[X - 1] << '\n';
} else if (X <= N + total_ops) {
cout << seq[X - 1] << '\n';
} else {
int k = X - N;
int offset = k - total_ops - 1;
int ans = (offset % M) + 1;
cout << ans << '\n';
}
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - A += v |
| User | a_legend_cat |
| Language | C++ IOI-Style(GNU++20) (GCC 14.2.0) |
| Score | 0 |
| Code Size | 1938 Byte |
| Status | WA |
| Exec Time | 107 ms |
| Memory | 53828 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 475 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 01_handmade_16.txt, 01_handmade_17.txt, 01_handmade_18.txt, 01_handmade_19.txt, 01_handmade_20.txt, 01_handmade_21.txt, 01_handmade_22.txt, 01_handmade_23.txt, 01_handmade_24.txt, 01_handmade_25.txt, 01_handmade_26.txt, 01_handmade_27.txt, 01_handmade_28.txt, 01_handmade_29.txt, 01_handmade_30.txt, 01_handmade_31.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1644 KiB |
| 00_sample_01.txt | AC | 0 ms | 1644 KiB |
| 01_handmade_00.txt | AC | 13 ms | 1644 KiB |
| 01_handmade_01.txt | WA | 72 ms | 44664 KiB |
| 01_handmade_02.txt | AC | 13 ms | 1644 KiB |
| 01_handmade_03.txt | AC | 51 ms | 39636 KiB |
| 01_handmade_04.txt | WA | 86 ms | 52572 KiB |
| 01_handmade_05.txt | WA | 78 ms | 40668 KiB |
| 01_handmade_06.txt | WA | 93 ms | 52392 KiB |
| 01_handmade_07.txt | WA | 87 ms | 49336 KiB |
| 01_handmade_08.txt | WA | 93 ms | 53828 KiB |
| 01_handmade_09.txt | WA | 76 ms | 40568 KiB |
| 01_handmade_10.txt | WA | 94 ms | 53696 KiB |
| 01_handmade_11.txt | AC | 43 ms | 21664 KiB |
| 01_handmade_12.txt | AC | 58 ms | 25608 KiB |
| 01_handmade_13.txt | AC | 83 ms | 45024 KiB |
| 01_handmade_14.txt | WA | 107 ms | 53672 KiB |
| 01_handmade_15.txt | WA | 83 ms | 45188 KiB |
| 01_handmade_16.txt | WA | 105 ms | 53672 KiB |
| 01_handmade_17.txt | WA | 86 ms | 40540 KiB |
| 01_handmade_18.txt | WA | 104 ms | 52456 KiB |
| 01_handmade_19.txt | AC | 45 ms | 17388 KiB |
| 01_handmade_20.txt | AC | 45 ms | 17496 KiB |
| 01_handmade_21.txt | AC | 45 ms | 17496 KiB |
| 01_handmade_22.txt | AC | 68 ms | 44660 KiB |
| 01_handmade_23.txt | AC | 67 ms | 44664 KiB |
| 01_handmade_24.txt | AC | 68 ms | 44664 KiB |
| 01_handmade_25.txt | WA | 98 ms | 53664 KiB |
| 01_handmade_26.txt | WA | 75 ms | 52620 KiB |
| 01_handmade_27.txt | WA | 77 ms | 52620 KiB |
| 01_handmade_28.txt | WA | 80 ms | 52620 KiB |
| 01_handmade_29.txt | WA | 63 ms | 44668 KiB |
| 01_handmade_30.txt | WA | 66 ms | 44656 KiB |
| 01_handmade_31.txt | WA | 66 ms | 44660 KiB |