제출 #1357081

#제출 시각아이디문제언어결과실행 시간메모리
1357081coderg300711Arranging Shoes (IOI19_shoes)C++20
100 / 100
44 ms15272 KiB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define sz(x) (int)(x).size()
#define rsz resize
#define ass assign
#define F(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
//template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define each(a,x) for(auto a:x)
#define FOR(i,a) for(int i=0;i<(a);i++)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define eb emplace_back
#define ft front()
#define V vector

#include "shoes.h"

template <class T>
struct BIT{
      int n;
      V<T> t;
      BIT(){};
      BIT(int _n){
            n=_n;
            t.ass(n+1,0);
      }
      T query(int i){
            T res=0;
            for(;i>=1;i-=(i&-i))res+=t[i];
            return res;
      }
      void upd(int i,T val){
            if(i<=0)return;
            for(;i<=n;i+=(i&-i))t[i]+=val;
      }
      void upd(int l,int r,T val){
            upd(l,val);
            upd(r+1,-val);
      }
      T query(int l,int r){
            if(l>r)return 0;
            return query(r)-query(l-1);
      }
};

ll count_swaps(V<int> s){
int n=sz(s);
const int lim=100005;
V<V<int>> pos(200010);
V<int> ptr(200010,0);
FOR(i,n)pos[s[i]+lim].pb(i);
V<int> target(n);
V<bool> vis(n,0);
int cnt=0;
FOR(i,n){
      if(vis[i])continue;
      int v=s[i],pval=-v;
      int id=i,pid=pos[pval+lim][ptr[pval+lim]++];      
      vis[id]=vis[pid]=1;
      ptr[v+lim]++;
      if(v<0){
            target[id]=2*cnt+1;
            target[pid]=2*cnt+2;
      }else{
            target[id]=2*cnt+2;
            target[pid]=2*cnt+1;
      }
      cnt++;
}
BIT<int> bit(n);
ll res=0;
FOR(i,n){
      res+=bit.query(target[i]+1,n);
      bit.upd(target[i],1);
}
return res;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…