#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
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 |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
8 ms |
1748 KB |
Output is correct |
8 |
Correct |
8 ms |
1748 KB |
Output is correct |
9 |
Correct |
9 ms |
1700 KB |
Output is correct |
10 |
Correct |
7 ms |
1264 KB |
Output is correct |
11 |
Correct |
6 ms |
1268 KB |
Output is correct |
12 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
17388 KB |
Output is correct |
2 |
Incorrect |
240 ms |
17504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
17388 KB |
Output is correct |
2 |
Incorrect |
240 ms |
17504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
8 ms |
1748 KB |
Output is correct |
8 |
Correct |
8 ms |
1748 KB |
Output is correct |
9 |
Correct |
9 ms |
1700 KB |
Output is correct |
10 |
Correct |
7 ms |
1264 KB |
Output is correct |
11 |
Correct |
6 ms |
1268 KB |
Output is correct |
12 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |