제출 #999911

#제출 시각아이디문제언어결과실행 시간메모리
999911MateiKing80Monochrome Points (JOI20_monochrome)C++14
4 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll string s; vector<int> w, b; struct AIB { vector<int> aib; AIB(int N) { aib.resize(N + 1, 0); } inline int lsb(int x) { return x & -x; } void update(int pos, int val) { while(pos < aib.size()) aib[pos] += val, pos += lsb(pos); } int query(int pos) { int ans = 0; while(pos) ans += aib[pos], pos -= lsb(pos); return ans; } }; int n; int nrInv(int k) { int ans = 0; AIB ds(2 * n); vector<pair<int, int>> v; for(int i = 0; i < n; i ++) v.push_back({w[i], b[(i + k) % n]}); for(auto &i : v) if(i.first > i.second) swap(i.first, i.second); sort(v.begin(), v.end()); for(int i = 0; i < n; i ++) { //cout << v[i].first << " " << v[i].second << "\n"; ans += ds.query(v[i].second) - ds.query(v[i].first); ds.update(v[i].second, 1); } //cout << '\n'; return ans; } signed main() { cin >> n >> s; for(int i = 0; i < 2 * n; i ++) { if(s[i] == 'B') b.push_back(i + 1); else w.push_back(i + 1); } int pas = (1 << 30), pos = 0; while(pas) { if(pos + pas <= n && nrInv(pos + pas - 1) < nrInv(pos + pas)) pos += pas; pas /= 2; } cout << nrInv(pos); }

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

monochrome.cpp: In member function 'void AIB::update(ll, ll)':
monochrome.cpp:24:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while(pos < aib.size())
      |               ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...