QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467628 | #2670. Arranging shoes | james1BadCreeper | 0 | 2ms | 16352kb | C++17 | 1.0kb | 2024-07-08 16:58:35 | 2024-07-08 16:58:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n;
int a[N];
vector<int> p[N];
bool vis[N];
struct Fenwick {
int C[N];
inline void add(int x, int k) { for (; x <= n; x += x & -x) C[x] += k; }
inline int sum(int x) { int r = 0; for (; x; x -= x & -x) r += C[x]; return r; }
inline int sum(int l, int r) { return sum(r) - sum(l - 1); }
} T;
long long count_swaps(vector<int> a) {
n = a.size();
a.push_back(0);
for (int i = n; i >= 1; --i) a[i] = a[i - 1];
for (int i = 1; i <= n; ++i) {
p[a[i] + n].push_back(i);
T.add(i, 1);
}
long long ans = 0;
for (int i = n; i >= 1; --i) if (!vis[i]) {
vis[i] = 1; p[a[i] + n].pop_back();
int res = p[n - a[i]].back(); p[n - a[i]].pop_back();
T.add(res, -1); T.add(i, -1);
vis[res] = 1; ans += T.sum(res, i) + (a[i] < 0);
// cerr << res << " " << i << "\n";
}
// cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 16352kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 -1 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
ok 3 lines
Test #2:
score: -10
Wrong Answer
time: 0ms
memory: 14156kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 1 -1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 0ms
memory: 16100kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -2 -2 2 2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #74:
score: 15
Accepted
time: 2ms
memory: 14336kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 -1 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
ok 3 lines
Test #75:
score: -15
Wrong Answer
time: 0ms
memory: 14008kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -1 -2 1 2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%