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 ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 6e5 + 2;
const int mod = 1e9 + 7;
struct fenwick {
int bit[N];
void Add(int x, int y) {
for (; x < N; x += x & (-x)) bit[x] += y;
}
int Get(int x) {
x -= 1;
int ans = 0;
for (; x > 0; x -= x & (-x)) ans += bit[x];
return ans;
}
}f1, f2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
vector<array<int, 4>> all;
vector<int> vals;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
all.push_back({a, b, a + b, -1});
vals.push_back(a);
vals.push_back(b);
vals.push_back(a + b);
}
for (int i = 0; i < q; i++) {
int a, b, c;
cin >> a >> b >> c;
smax(c, a + b);
all.push_back({a, b, c, i});
vals.push_back(a);
vals.push_back(b);
vals.push_back(c);
}
sort(all.begin(), all.end(), [&] (array<int, 4> i, array<int, 4> j) {
if (i[2] != j[2]) return i[2] > j[2];
return i[3] > j[3];
});
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
map<int, int> hsh;
for (int i = 0; i < vals.size(); i++) hsh[vals[i]] = i + 1;
vector<int> ans(q);
int o = 0;
for (auto u : all) {
if (u[3] == -1) {
f1.Add(hsh[u[0]], 1);
f2.Add(hsh[u[1]], 1);
o += 1;
}
else {
ans[u[3]] = o - f1.Get(hsh[u[0]]) - f2.Get(hsh[u[1]]);
}
}
for (int i = 0; i < q; i++) cout << ans[i] << en;
return 0;
}
Compilation message (stderr)
examination.cpp: In function 'int main()':
examination.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < vals.size(); i++) hsh[vals[i]] = i + 1;
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |