제출 #955153

#제출 시각아이디문제언어결과실행 시간메모리
955153AcanikolicArranging Shoes (IOI19_shoes)C++14
100 / 100
88 ms33880 KiB
#include <bits/stdc++.h> #define pb push_back #define F first #define S second using namespace std; const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 1e9; long long fenw[N]; vector<int>p(N); set<int>g[N][2];//0 neg 1 pos void add(int index,int n,int val) { while(index <= n) { fenw[index] += val; index += index & -index; } } long long get(int index) { long long ret = 0; while(index >= 1) { ret += fenw[index]; index -= index & -index; } return ret; } long long count_swaps(vector<int>a) { int n = a.size(); for(int i = 0; i < n; i++) { if(a[i] > 0) g[a[i]][1].insert(i + 1); else g[-a[i]][0].insert(i + 1); } int index = 1; for(int i = 0; i < n; i++) { if(a[i] < 0) { if(g[-a[i]][0].find(i + 1) == g[-a[i]][0].end()) continue; p[i + 1] = index++; g[-a[i]][0].erase(i + 1); p[*g[-a[i]][1].begin()] = index++; g[-a[i]][1].erase(g[-a[i]][1].begin()); }else { if(g[a[i]][1].find(i + 1) == g[a[i]][1].end()) continue; p[*g[a[i]][0].begin()] = index++; g[a[i]][0].erase(g[a[i]][0].begin()); p[i + 1] = index++; g[a[i]][1].erase(i + 1); } } long long res = 0; for(int i = 1; i <= n; i++) { res += get(n) - get(p[i]); add(p[i],n,1); } return res; } /*signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int>a(n); for(int i = 0; i < n; i++) cin >> a[i]; cout << count_swaps(a); return 0; }*/
#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...