Submission #398498

#TimeUsernameProblemLanguageResultExecution timeMemory
398498kevinxiehkArranging Shoes (IOI19_shoes)C++17
10 / 100
256 ms280076 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; ll fen[100005]; ll hv[100005]; int n; void update(int id, int val) { id++; while(id <= n + 1) { fen[id] += val; id += (id & (-id)); } return; } ll pre(int id) { if(id <= -1) return 0; int ans = 0; id++; while(id) { ans += fen[id]; id -= (id & (-id)); } return ans; } int range(int l, int r){ return pre(r) - pre(l - 1); } long long count_swaps(vector<int> arr) { n = arr.size(); queue<int> pl[n + 5]; int dk[n + 5]; int t = 0; for(int i = 0; i < n; i++) { if(arr[i] < 0) { dk[i] = t; t++; pl[-arr[i]].push(t); t++; } } for(int i = 0; i < n; i++) { if(arr[i] > 0) { dk[i] = pl[arr[i]].front(); pl[arr[i]].pop(); } } ll ans = 0; for(int i = 0; i < n; i++) { ans += i - pre(dk[i]); update(dk[i], 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...