# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697288 | Baytoro | Arranging Shoes (IOI19_shoes) | C++17 | 104 ms | 57164 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 <bits/stdc++.h>
//#include "shoes.h"
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
//#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int N=1e6+5;
int bit[N];
void update(int i, int v){
for(;i<=N;i+=i&-i){
bit[i]+=v;
}
}
ll query(int i){
int res=0;
for(;i>0;i-=i&-i) res+=bit[i];
return res;
}
ll query(int l, int r){
return query(r)-query(l-1);
}
vector<int> a[N][2];
ll count_swaps(vector<int> s){
int n=s.size();
for(int i=1;i<=n;i++){
update(i,1);
a[abs(s[i-1])][s[i-1]<0].pb(i);
}
ll res=0;
for(int i=1;i<=n;i++) for(int j=0;j<2;j++) reverse(all(a[i][j]));
for(int i=1;i<=n;i++){
if(!s[i-1]) continue;
int x=s[i-1],y=(s[i-1]<0),z=a[abs(x)][y^1].back();
a[abs(x)][0].pop_back();
a[abs(x)][1].pop_back();
s[z-1]=0;
s[i-1]=0;
update(z,-1);
if(y) res+=query(i+1,z);
else res+=query(i,z);
}
return res;
}
/*void solve(){
int n;cin>>n;
vector<int> vec(n);
for(int i=0;i<n;i++)
cin>>vec[i];
cout<<count_swaps(vec);
}
main(){
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}*/
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... |