제출 #677046

#제출 시각아이디문제언어결과실행 시간메모리
677046hello_there_123Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms340 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; int n; int ft[10005]; inline int ls(int x){return x & -x; } int qry(int p){ p++; if(p<1) return 0; int r = 0; for(;p;p-=ls(p)) r+=ft[p]; return r; } void upd(int p, int v){ p++; for(;p<=n;p+=ls(p)) ft[p]+=v; } long long count_swaps(vector<int>s) { int ans = 0; n = s.size(); map<int,queue<int> >mp; for(int i=0;i<n;i++){ int x = s[i]; mp[x].push(i); } bool arr[n+3]; memset(arr,0,sizeof(arr)); for(int i=0;i<n;i++){ mp[s[i]].pop(); if(arr[i]) continue; int first = mp[-s[i]].front(); mp[-arr[i]].pop(); ans+=first-i-1-(qry(first)-qry(i-1)); upd(first,1); arr[first] = 1; if(s[i]>0) ans++; } 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...