제출 #318459

#제출 시각아이디문제언어결과실행 시간메모리
318459joylintpArranging Shoes (IOI19_shoes)C++17
100 / 100
188 ms141292 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; int n; long long BIT[200001]; vector<queue<int>> ls, rs; void mod(int p, int x) { while (p <= n) BIT[p] += x, p += p & -p; } int qry(int p) { int ret = 0; while (p) ret += BIT[p], p -= p & -p; return ret; } long long count_swaps(vector<int> ss) { n = ss.size(); vector<int> s = {0}; for (int i : ss) s.push_back(i); ls.resize(n / 2 + 1), rs.resize(n / 2 + 1); for (int i = 1; i <= n; i++) if (s[i] < 0) ls[-s[i]].push(i); else rs[s[i]].push(i); for (int i = 1; i <= n; i++) mod(i, 1); long long ans = 0; for (int i = 1; i <= n; i++) if (qry(i)) if (s[i] < 0) { int lpos = i, rpos = rs[-s[i]].front(); ls[-s[i]].pop(), rs[-s[i]].pop(); ans += qry(rpos - 1) - qry(lpos); mod(lpos, -1), mod(rpos, -1); } else { int lpos = ls[s[i]].front(), rpos = i; ls[s[i]].pop(), rs[s[i]].pop(); ans += qry(lpos - 1) - qry(rpos - 1); mod(lpos, -1), mod(rpos, -1); } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:42:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   42 |         if (qry(i))
      |            ^
#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...