이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include <cstdio>
#include <cassert>
#define Int long long
#define fore(i , n) for(int i = 0 ; i<n;i++)
#define pb push_back
#define forn(i , x , y) for(int i = x ; i >= y; i--)
Int swaps(vector<int> a , vector<int> b)
{
map<int , vector<int>> pos;
int m = (int)a.size();
fore(i , m)
{
pos[a[i]].pb(i);
}
Tree<int> t;
int ans = 0;
forn(i , m - 1 , 0)
{
t.insert(pos[b[i]].back());
ans+=t.order_of_key(pos[b[i]].back());
pos[b[i]].pop_back();
}
return ans;
}
Int count_swaps(vector<int> s)
{
vector<int> t;
for(auto &x : s)
{
if((int)t.size() % 2 == 0)
t.pb(0);
else
t.pb(1);
if(x < 0)
x = 0;
else
x = 1;
}
return swaps(s , t);
}
//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;
//}
# | 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... |