제출 #533031

#제출 시각아이디문제언어결과실행 시간메모리
533031DJ035Arranging Shoes (IOI19_shoes)C++17
100 / 100
174 ms156264 KiB
#include "shoes.h" # pragma GCC optimize ("O3") # pragma GCC optimize ("Ofast") # pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <bits/stdc++.h> #define MEM 111111 #define sanic ios_base::sync_with_stdio(0) #define x first #define y second #define pf push_front #define pb push_back #define all(v) v.begin(), v.end() #define sz size() using namespace std; typedef long long ll; typedef pair<ll, ll> pi; const ll MOD = 1e9+7; const ll INF = 2e14+7; ll mul(ll a, ll b){ return ((a*b)%MOD+MOD)%MOD; } ll add(ll a, ll b){ return ((a+b)%MOD+MOD)%MOD; } ll tr[4*MEM]; ll t,n,ans,m,k; ll v[2*MEM]; queue<ll> q[MEM][2]; void upd(ll p, ll v){ for(int i=p; i<2*MEM; i+=(i&-i)) tr[i] += v; } ll query(ll p){ ll ret = 0; for(int i=p; i>0; i-=(i&-i)) ret += tr[i]; return ret; } long long count_swaps(std::vector<int> s) { ll n=s.sz; ll ans=0; for(int i=n-1; i>=0; i--){ if(s[i]>0) q[s[i]][0].push(i); else q[-s[i]][1].push(i); } for(int i=n-1; i>=0; i--){ if(v[i]) continue; int j=(s[i]>0 ? q[abs(s[i])][1].front() : q[abs(s[i])][0].front()); ll o=query(i+1)-query(j+1); q[abs(s[i])][0].pop(); q[abs(s[i])][1].pop(); if(s[i]>0) ans += i-j-1-o; else ans += i-j-o; v[j] = 1; v[i] = 1; upd(j+1, 1); upd(i+1, 1); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...