이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |