제출 #780574

#제출 시각아이디문제언어결과실행 시간메모리
780574Minindu206Arranging Shoes (IOI19_shoes)C++14
25 / 100
132 ms138816 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long const int MAXN = 1e5 + 5; using namespace std; queue<int> pos[MAXN], neg[MAXN]; struct fenwick { int n; vector<int> fn; void init(int _n) { this->n = _n + 1; fn.resize(n, 0); } void update(int x, int y) { x++; while(x < n) { fn[x] += y; x += (x & (-x)); } } int sum(int ind) { ind++; int ans = 0; while(ind) { ans += fn[ind]; ind -= (ind & (-ind)); } return ans; } }; ll count_swaps(vector<int> s) { int n = s.size() / 2; for(int i=0;i<2 * n;i++) { if(s[i] > 0) pos[s[i]].push(i); else neg[-s[i]].push(i); } vector<int> vis(2 * n); fenwick tree; tree.init((2 * n)); ll ans = 0; for(int i=0;i<2*n;i++) { ll swps = 0; if(vis[i]) continue; if(s[i] > 0) { int nxt = neg[s[i]].front(); neg[s[i]].pop(); pos[s[i]].pop(); // cout << i << " " << nxt << '\n'; // cout << "swaps " << (nxt - i) - (tree.sum(nxt + 1) - tree.sum(i + 1)) << '\n'; ans += (nxt - i) - (tree.sum(nxt + 1) - tree.sum(i)); tree.update(nxt + 1, 1); vis[i] = 1; vis[nxt] = 1; } else { int nxt = pos[-s[i]].front(); pos[-s[i]].pop(); neg[-s[i]].pop(); // cout << i << " " << nxt << '\n'; // cout << "swaps " << (nxt - i - 1) - (tree.sum(nxt + 1) - tree.sum(i + 1)) << '\n'; ans += (nxt - i - 1) - (tree.sum(nxt + 1) - tree.sum(i)); tree.update(nxt + 1, 1); vis[i] = 1; vis[nxt] = 1; } } return ans; }

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

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