이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define LL long long
#define PB push_back
using namespace __gnu_pbds;
using namespace std;
long long count_swaps(std::vector<int> s) {
LL n = s.size()/2;
ordered_set ss;
vector < LL > v[n*2+1];
LL a[n*2+1], fix[n*2+1];
LL ans = 0;
for ( LL i = 0; i < 2*n; ++i ){
if ( s[i] < 0 ){
s[i] = n - s[i];
}
ss.insert(i);
v[s[i]].PB(i);
a[i+1]=0;
fix[i] = 0;
}/**/
for ( LL i = 0; i < 2*n; ++i ){
if ( fix[i] ) continue;
ss.erase(i);
LL k = s[i];
a[k]++;
if ( k > n ) k -= n;
else k += n;
//cout << i << " " << k << " " << a[k] << endl;
//while ( v[k][a[k]] <= i ) a[k]++;
LL t = v[k][a[k]];
a[k]++;
ans += ss.order_of_key(t);
if ( k > n ) ans++;
fix[t] = 1;
ss.erase(t);
}/**/
return ans;
}
/*/
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> S(2 * n);
for (int i = 0; i < 2 * n; i++)
assert(1 == scanf("%d", &S[i]));
fclose(stdin);
long long result = count_swaps(S);
printf("%lld\n", result);
fclose(stdout);
return 0;
}
/**/
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp:62:1: warning: "/*" within comment [-Wcomment]
/**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |