제출 #696984

#제출 시각아이디문제언어결과실행 시간메모리
696984Elvin_FritlArranging Shoes (IOI19_shoes)C++17
100 / 100
114 ms34508 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif set<int> L[200005], R[200005]; long long vis[200005], ft[200005], n; void upd(int l, int r, int v){ r++;r++; l++; for(;l<=n;l+=(l & -l))ft[l] += v; for(;r<=n;r+=(r & -r))ft[r] -= v; } long long query(int p){ p++; long long sum = 0; for(;p;p-=(p & -p))sum += ft[p]; return sum; } long long count_swaps(std::vector<int> s) { n = (int)s.size(); for(int i=0;i<n;i++){ if(s[i] < 0)L[-s[i]].insert(i); else R[s[i]].insert(i); } for(int i=0;i<n;i++)upd(i, i, i); long long ans = 0; int cnt = 0; for(int i=0;i<n;i++){ if(vis[i])continue; if(s[i] < 0){ L[-s[i]].erase(L[-s[i]].begin()); ans += max(0ll, query(*R[-s[i]].begin()) - query(i) - 1); vis[*R[-s[i]].begin()] = 1; upd(i+1, *R[-s[i]].begin(), 1); R[-s[i]].erase(R[-s[i]].begin()); } else{ ans++; R[s[i]].erase(R[s[i]].begin()); ans += max(0ll, query(*L[s[i]].begin()) - query(i) - 1); vis[*L[s[i]].begin()] = 1; upd(i+1, *L[s[i]].begin(), 1); L[s[i]].erase(L[s[i]].begin()); } } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:6: warning: unused variable 'cnt' [-Wunused-variable]
   38 |  int cnt = 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...