This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (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... |