제출 #202486

#제출 시각아이디문제언어결과실행 시간메모리
202486dolphingarlic운세 보기 2 (JOI14_fortune_telling2)C++14
0 / 100
5 ms376 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; int a[200001], b[200001], t[200001], bit[600001]; vector<int> compressed; void update(int pos) { for (; pos <= compressed.size(); pos += (pos & (-pos))) bit[pos]++; } int query(int x, int y) { int ans = 0; for (; y; y -= (y & (-y))) ans += bit[y]; for (x--; x; x -= (x & (-x))) ans -= bit[x]; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; FOR(i, 0, n) { cin >> a[i] >> b[i]; compressed.push_back(a[i]); compressed.push_back(b[i]); } FOR(i, 0, q) { cin >> t[i]; compressed.push_back(t[i]); } sort(compressed.begin(), compressed.end()); compressed.erase(unique(compressed.begin(), compressed.end()), compressed.end()); FOR(i, 0, n) { a[i] = lower_bound(compressed.begin(), compressed.end(), a[i]) - compressed.begin() + 1; b[i] = lower_bound(compressed.begin(), compressed.end(), b[i]) - compressed.begin() + 1; } FOR(i, 0, q) { t[i] = lower_bound(compressed.begin(), compressed.end(), t[i]) - compressed.begin() + 1; update(t[i]); } ll ans = 0; FOR(i, 0, n) { int num = (query(compressed.size(), max(a[i], b[i])) + (a[i] < b[i])) & 1; if (num) ans += compressed[b[i] - 1]; else ans += compressed[a[i] - 1]; } cout << ans; return 0; }

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

fortune_telling2.cpp: In function 'void update(int)':
fortune_telling2.cpp:9:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 void update(int pos) { for (; pos <= compressed.size(); pos += (pos & (-pos))) bit[pos]++; }
                               ~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...