#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 |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
1684 KB |
Output is correct |
8 |
Correct |
9 ms |
1752 KB |
Output is correct |
9 |
Correct |
8 ms |
1740 KB |
Output is correct |
10 |
Correct |
7 ms |
1268 KB |
Output is correct |
11 |
Correct |
7 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
8 ms |
1684 KB |
Output is correct |
14 |
Correct |
9 ms |
1656 KB |
Output is correct |
15 |
Correct |
9 ms |
1672 KB |
Output is correct |
16 |
Correct |
5 ms |
1112 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
3 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
17472 KB |
Output is correct |
2 |
Correct |
265 ms |
17308 KB |
Output is correct |
3 |
Correct |
276 ms |
17384 KB |
Output is correct |
4 |
Correct |
170 ms |
13544 KB |
Output is correct |
5 |
Correct |
157 ms |
13516 KB |
Output is correct |
6 |
Correct |
99 ms |
8328 KB |
Output is correct |
7 |
Correct |
247 ms |
16416 KB |
Output is correct |
8 |
Correct |
226 ms |
16416 KB |
Output is correct |
9 |
Correct |
218 ms |
16020 KB |
Output is correct |
10 |
Correct |
164 ms |
13076 KB |
Output is correct |
11 |
Correct |
141 ms |
13072 KB |
Output is correct |
12 |
Correct |
67 ms |
8344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
17472 KB |
Output is correct |
2 |
Correct |
265 ms |
17308 KB |
Output is correct |
3 |
Correct |
276 ms |
17384 KB |
Output is correct |
4 |
Correct |
170 ms |
13544 KB |
Output is correct |
5 |
Correct |
157 ms |
13516 KB |
Output is correct |
6 |
Correct |
99 ms |
8328 KB |
Output is correct |
7 |
Correct |
247 ms |
16416 KB |
Output is correct |
8 |
Correct |
226 ms |
16416 KB |
Output is correct |
9 |
Correct |
218 ms |
16020 KB |
Output is correct |
10 |
Correct |
164 ms |
13076 KB |
Output is correct |
11 |
Correct |
141 ms |
13072 KB |
Output is correct |
12 |
Correct |
67 ms |
8344 KB |
Output is correct |
13 |
Correct |
263 ms |
18436 KB |
Output is correct |
14 |
Correct |
237 ms |
17824 KB |
Output is correct |
15 |
Correct |
233 ms |
17440 KB |
Output is correct |
16 |
Correct |
155 ms |
13928 KB |
Output is correct |
17 |
Correct |
158 ms |
14016 KB |
Output is correct |
18 |
Correct |
82 ms |
8348 KB |
Output is correct |
19 |
Correct |
262 ms |
18436 KB |
Output is correct |
20 |
Correct |
240 ms |
17916 KB |
Output is correct |
21 |
Correct |
240 ms |
17940 KB |
Output is correct |
22 |
Correct |
139 ms |
13024 KB |
Output is correct |
23 |
Correct |
139 ms |
12992 KB |
Output is correct |
24 |
Correct |
70 ms |
8364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
1684 KB |
Output is correct |
8 |
Correct |
9 ms |
1752 KB |
Output is correct |
9 |
Correct |
8 ms |
1740 KB |
Output is correct |
10 |
Correct |
7 ms |
1268 KB |
Output is correct |
11 |
Correct |
7 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
8 ms |
1684 KB |
Output is correct |
14 |
Correct |
9 ms |
1656 KB |
Output is correct |
15 |
Correct |
9 ms |
1672 KB |
Output is correct |
16 |
Correct |
5 ms |
1112 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
3 ms |
732 KB |
Output is correct |
19 |
Correct |
263 ms |
17472 KB |
Output is correct |
20 |
Correct |
265 ms |
17308 KB |
Output is correct |
21 |
Correct |
276 ms |
17384 KB |
Output is correct |
22 |
Correct |
170 ms |
13544 KB |
Output is correct |
23 |
Correct |
157 ms |
13516 KB |
Output is correct |
24 |
Correct |
99 ms |
8328 KB |
Output is correct |
25 |
Correct |
247 ms |
16416 KB |
Output is correct |
26 |
Correct |
226 ms |
16416 KB |
Output is correct |
27 |
Correct |
218 ms |
16020 KB |
Output is correct |
28 |
Correct |
164 ms |
13076 KB |
Output is correct |
29 |
Correct |
141 ms |
13072 KB |
Output is correct |
30 |
Correct |
67 ms |
8344 KB |
Output is correct |
31 |
Correct |
263 ms |
18436 KB |
Output is correct |
32 |
Correct |
237 ms |
17824 KB |
Output is correct |
33 |
Correct |
233 ms |
17440 KB |
Output is correct |
34 |
Correct |
155 ms |
13928 KB |
Output is correct |
35 |
Correct |
158 ms |
14016 KB |
Output is correct |
36 |
Correct |
82 ms |
8348 KB |
Output is correct |
37 |
Correct |
262 ms |
18436 KB |
Output is correct |
38 |
Correct |
240 ms |
17916 KB |
Output is correct |
39 |
Correct |
240 ms |
17940 KB |
Output is correct |
40 |
Correct |
139 ms |
13024 KB |
Output is correct |
41 |
Correct |
139 ms |
12992 KB |
Output is correct |
42 |
Correct |
70 ms |
8364 KB |
Output is correct |
43 |
Correct |
505 ms |
43524 KB |
Output is correct |
44 |
Correct |
524 ms |
43548 KB |
Output is correct |
45 |
Correct |
482 ms |
43680 KB |
Output is correct |
46 |
Correct |
247 ms |
29864 KB |
Output is correct |
47 |
Correct |
241 ms |
29712 KB |
Output is correct |
48 |
Correct |
83 ms |
8432 KB |
Output is correct |
49 |
Correct |
481 ms |
44072 KB |
Output is correct |
50 |
Correct |
546 ms |
43616 KB |
Output is correct |
51 |
Correct |
490 ms |
43880 KB |
Output is correct |
52 |
Correct |
212 ms |
24016 KB |
Output is correct |
53 |
Correct |
177 ms |
21792 KB |
Output is correct |