# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211103 | wanling1212 | Arranging Shoes (IOI19_shoes) | C++14 | 1095 ms | 147832 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 pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=200005;
const ll inf=1e9+7;
map<ll,queue<ll>> m;
ll bit[maxn];
ll lsb(int x)
{
return x&(-x);
}
void add(int x,int v)
{
while(x<maxn)
{
bit[x]+=v;
x+=lsb(x);
}
}
ll query(ll x)
{
ll res=0;
while(x)
{
res+=bit[x];
x-=lsb(x);
}
return res;
}
ll count_swaps(std::vector<int> s)
{
rep(i,s.size())
{
m[s[i]].push(i);
add(i+1,1);
}
ll sum=0;
rep(i,s.size())
{
queue<ll> q=m[-s[i]];
if(q.empty()) continue;
if(m[s[i]].front()!=i) continue;
ll p=q.front();
m[-s[i]].pop();
m[s[i]].pop();
sum+=query(p)-query(i+1);
if(s[i]>0) sum++;
//cout<<i<<" "<<sum<<"\n";
add(p+1,-1);
add(i+1,-1);
}
return sum;
}
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... |