# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469326 | AdamGS | Arranging Shoes (IOI19_shoes) | C++14 | 101 ms | 18060 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
vector<int>V[2*LIM];
ll li[2*LIM], tr[8*LIM], N=1;
void upd(int v) {
v+=N;
while(v) {
--tr[v];
v/=2;
}
}
ll cnt(int l, int r) {
if(l>r) return 0;
l+=N; r+=N;
ll ans=tr[l];
if(l!=r) ans+=tr[r];
while(l/2!=r/2) {
if(l%2==0) ans+=tr[l+1];
if(r%2==1) ans+=tr[r-1];
l/=2; r/=2;
}
return ans;
}
ll count_swaps(vector<int>S) {
while(N<S.size()) N*=2;
rep(i, S.size()) {
tr[N+i]=1;
if(S[i]<0) V[-S[i]+LIM].pb(i);
else V[S[i]].pb(i);
}
for(int i=N-1; i>=0; --i) tr[i]=tr[2*i]+tr[2*i+1];
ll ans=0;
rep(i, S.size()) if(tr[N+i]) {
if(S[i]<0) {
ans+=cnt(i+1, V[-S[i]][li[-S[i]]]-1);
upd(V[-S[i]][li[-S[i]]]);
++li[-S[i]];
++li[-S[i]+LIM];
} else {
ans+=cnt(i+1, V[S[i]+LIM][li[S[i]+LIM]]-1)+1;
upd(V[S[i]+LIM][li[S[i]+LIM]]);
++li[S[i]+LIM];
++li[S[i]];
}
}
return ans;
}
Compilation message (stderr)
# | 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... |