QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#329589 | #4936. Shopping Changes | QRQRQR | WA | 83ms | 3952kb | C++17 | 2.1kb | 2024-02-16 22:19:14 | 2024-02-16 22:19:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> crr;
vector<int> fr;
int n, m, k;
ll cal(int nl, int mid, int nr, ll lh, ll rh, vector<int> arr) {
ll ov = 0;
int pn = mid - nl + 1, sn = nr - mid;
int pre[pn] = {0}, suf[sn] = {0};
for (int i = 0; i < pn; i++) {
pre[i] = arr[nl+i];
}
for (int i = 0; i < sn; i++) {
suf[i] = arr[mid+1+i];
}
int lp = 0, rp = 0, i;
for (i = 0; lp < pn && rp < sn; i++) {
if (pre[lp] > suf[rp]) {
arr[nl+i] = suf[rp++];
ov += pn - lp;
}else {
arr[nl+i] = pre[lp++];
}
}
while (lp < pn) {
arr[nl+i] = pre[lp++];
i++;
}
while (rp < sn) {
arr[nl+i] = suf[rp++];
i++;
}
return ov + lh + rh;
}
ll inver(int nl, int nr, vector<int> arr) {
if (nl == nr) {
return 0LL;
}
int mid = (nl+nr)>>1;
ll lh = inver(nl, mid, arr);
ll rh = inver(mid+1, nr, arr);
ll all = cal(nl, mid, nr, lh, rh, arr);
return all;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
int in;
cin >> in;
crr.push_back(in);
}
ll chin = inver(0, n-1, crr);
while (m--) {
ll ans = 0, temp = 0;
cin >> k;
fr = vector<int>();
for (int i = 0; i < k; i++) {
int in;
cin >> in;
fr.push_back(in);
}
for (int i = 0; i < k; i++) {
temp += (ll)(crr.end() - upper_bound(crr.begin(), crr.end(), fr[i]));
}
ans = temp;
for (int i = 0; i < k; i++) {
temp += (ll)(lower_bound(crr.begin(), crr.end(), fr[i]) - crr.begin());
temp -= (ll)(crr.end() - upper_bound(crr.begin(), crr.end(), fr[i]));
//cout << temp << " ";
ans = min(ans, temp);
}
ans += inver(0, k-1, fr);
ans += chin;
cout << ans << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
3 3 5 6 7 6 2 3 4 8 9 10 2 100 99 3 5 6 7
output:
0 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 2 7 6 5 6 2 3 4 8 9 10 6 10 9 8 4 3 2
output:
3 27
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 1 589284012 1 767928734
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 83ms
memory: 3952kb
input:
10000 9999 298772847 712804102 869795012 527998188 804246450 598105371 843966934 639805471 937482040 887551242 254734680 188704975 17408126 626523673 553956319 697723205 231690822 637079761 232393146 377026277 962223856 338922458 912529500 710873344 942955137 51167037 195729799 529674367 990599310 4...
output:
33495629 33495984 33565967 33511608 33525560 33479946 33550059 33506719 33537365 33485552 33488553 33477337 33490610 33494746 33617814 33481077 33468494 33532985 33635685 33478344 33479175 33663860 33468374 33537419 33469299 33545547 33508516 33468493 33496647 33557063 33551564 33525212 33497161 335...
result:
wrong answer 1st lines differ - expected: '24802338', found: '33495629'