제출 #157211

#제출 시각아이디문제언어결과실행 시간메모리
157211abilArranging Shoes (IOI19_shoes)C++14
0 / 100
11 ms9752 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = (1e5 + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); int a[N], minus[N], used[N], t[N * 4]; set<int > s[2][N]; set<int > :: iterator it; int n; void update(int pos, int new_val, int v = 1,int tl = 1,int tr = n){ if(tl == tr){ t[v] = new_val; } else{ int mid = (tl + tr) >> 1; if(mid >= pos){ update(pos, new_val, v + v, tl, mid); } else{ update(pos, new_val, v + v + 1, mid + 1, tr); } t[v] = t[v + v] + t[v + v + 1]; } } int get(int l,int r, int v = 1,int tl = 1,int tr = n){ if(tl > r || tr < l){ return 0; } if(l <= tl && r >= tr){ return t[v]; } int mid = (tl + tr) >> 1; return (get(l, r, v + v, tl, mid) + get(l, r, v + v + 1, mid + 1, tr)); } long long count_swaps(vector<int> s1) { for(int i = 1;i <= n; i++){ a[i] = s1[i - 1]; if(a[i] < 0){ s[0][abs(a[i])].insert(i); } else{ s[1][a[i]].insert(i); } } long long ans = 0, plus = 0; for(int i = 1;i <= n; i++){ if(used[i]){ continue; } if(a[i] < 0){ it = s[1][abs(a[i])].begin(); s[1][abs(a[i])].erase(s[1][abs(a[i])].begin()); s[0][abs(a[i])].erase(s[0][abs(a[i])].begin()); ans += *it - i - 1; ans -= get(i, *it); update(i, -1); update(*it, 1); used[*it] = 1; } else{ it = s[0][a[i]].begin(); s[0][a[i]].erase(s[0][a[i]].begin()); s[1][abs(a[i])].erase(s[1][abs(a[i])].begin()); ans += *it - i; ans -= get(i, i); update(i, -1); update(*it, 1); used[*it] = 1; } } return ans; } /* 6 -2 2 -2 2 -2 2 */

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:58:21: warning: unused variable 'plus' [-Wunused-variable]
  long long ans = 0, plus = 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...