QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873634 | #2706. Swap Swap Sort | hhoppitree | 0 | 152ms | 4352kb | C++17 | 1.2kb | 2025-01-26 19:14:06 | 2025-01-26 19:14:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n, m, q; scanf("%d%d%d", &n, &m, &q);
vector<int> a(n), s(m + 1), cnt(m);
vector< vector<int> > pos(m);
long long res = 0;
int id = 0;
for (auto &x : a) {
scanf("%d", &x), ++cnt[--x], pos[x].push_back(id++);
for (int i = x + 2; i <= m; i += i & -i) res += s[i];
for (int i = x + 1; i; i -= i & -i) ++s[i];
}
vector<int> per(m);
iota(per.begin(), per.end(), 0);
map< pair<int, int>, int> M;
auto query = [&](int x, int y) {
if (M.count({x, y})) return M[{x, y}];
if (!cnt[x] || !cnt[y]) return 0;
int ty = (cnt[x] > cnt[y]);
if (cnt[x] > cnt[y]) swap(x, y);
long long S = 0;
for (auto v : pos[x]) S += lower_bound(pos[y].begin(), pos[y].end(), v) - pos[y].begin();
if (ty) S = 1ll * cnt[x] * cnt[y] - S;
return M[{x, y}] = S;
};
while (q--) {
int x; scanf("%d", &x);
res += 1ll * cnt[per[x - 1]] * cnt[per[x]] - 2 * query(per[x - 1], per[x]);
swap(per[x - 1], per[x]);
printf("%lld\n", res);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 3840kb
input:
5 4 3 1 4 2 1 2 3 2 1
output:
4 2 2
result:
ok 3 lines
Test #2:
score: 0
Wrong Answer
time: 152ms
memory: 3840kb
input:
5000 2 5000 2 2 2 1 2 1 2 1 2 1 2 2 1 1 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 2 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 ...
output:
3086489 3161662 3236835 3312008 3387181 3462354 3537527 3612700 3687873 3763046 3838219 3913392 3988565 4063738 4138911 4214084 4289257 4364430 4439603 4514776 4589949 4665122 4740295 4815468 4890641 4965814 5040987 5116160 5191333 5266506 5341679 5416852 5492025 5567198 5642371 5717544 5792717 5867...
result:
wrong answer 3rd lines differ - expected: '3086489', found: '3236835'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 87ms
memory: 4352kb
input:
100000 2 100 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 2 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 1 2 2 2 1 2 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 2...
output:
5545733422 9842233195 14138732968 18435232741 22731732514 27028232287 31324732060 35621231833 39917731606 44214231379 48510731152 52807230925 57103730698 61400230471 65696730244 69993230017 74289729790 78586229563 82882729336 87179229109 91475728882 95772228655 100068728428 104365228201 108661727974...
result:
wrong answer 1st lines differ - expected: '1250766126', found: '5545733422'
Subtask #3:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
100000 2 1000000 1 2 2 2 2 1 1 2 1 2 1 1 1 1 1 1 2 2 1 1 1 2 1 2 2 1 1 2 2 2 1 1 1 1 1 1 2 2 1 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 1 1 2 1 2 2 2 1 2 2 2 1 2 1 2 1 1 1 2 1 2 2 1 1 1 1 2 1 2 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 2 1 1 1 1 1 2 1 2...
output:
5546873244 9837953568 14129033892 18420114216 22711194540 27002274864 31293355188 35584435512 39875515836 44166596160 48457676484 52748756808 57039837132 61330917456 65621997780 69913078104 74204158428 78495238752 82786319076 87077399400 91368479724 95659560048 99950640372 104241720696 108532801020 ...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%