#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
struct pt {
int x, y, z, t;
};
bool cmp(pt p, pt q) {
if (p.z == q.z) return p.t > q.t;
return p.z < q.z;
}
bool cmp1(pt p, pt q) {
if (p.x != q.x) return p.x < q.x;
return p.y < q.y;
}
const int MN = 200005;
int n, q, x, y, z, ans[MN], bit[MN];
vector<int> xs, ys, zs, upds;
map<int, int> mx, my, mz;
vector<pt> v;
void upd(int x, int val) {
if (val > 0) upds.push_back(x);
for (int i = x; i < MN; i += i & -i) bit[i] += val;
}
void clear() {
for (int x : upds) upd(x, -1);
upds.clear();
}
int qry(int x) {
int ret = 0;
for (int i = x; i > 0; i -= i & -i) ret += bit[i];
return ret;
}
void solve(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
vector<pt> ps, qs;
for (int i = l; i <= mid; i++) if (v[i].t) qs.push_back(v[i]);
for (int i = mid + 1; i <= r; i++) if (!v[i].t) ps.push_back(v[i]);
sort(ps.begin(), ps.end(), cmp1);
sort(qs.begin(), qs.end(), cmp1);
int ptr = ps.size() - 1;
for (int i = qs.size() - 1; i >= 0; i--) {
while (ptr >= 0 && ps[ptr].x >= qs[i].x) upd(ps[ptr--].y, 1);
ans[qs[i].t] += qry(MN - 1) - qry(qs[i].y - 1);
}
clear();
solve(l, mid), solve(mid + 1, r);
}
int32_t main() {
boost();
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
z = x + y;
xs.push_back(x);
ys.push_back(y);
zs.push_back(z);
v.push_back({x, y, z, 0});
}
for (int i = 1; i <= q; i++) {
cin >> x >> y >> z;
xs.push_back(x);
ys.push_back(y);
zs.push_back(z);
v.push_back({x, y, z, i});
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
sort(ys.begin(), ys.end());
ys.erase(unique(ys.begin(), ys.end()), ys.end());
sort(zs.begin(), zs.end());
zs.erase(unique(zs.begin(), zs.end()), zs.end());
for (int i = 0; i < xs.size(); i++) mx[xs[i]] = i + 1;
for (int i = 0; i < ys.size(); i++) my[ys[i]] = i + 1;
for (int i = 0; i < zs.size(); i++) mz[zs[i]] = i + 1;
for (int i = 0; i < v.size(); i++) v[i].x = mx[v[i].x], v[i].y = my[v[i].y], v[i].z = mz[v[i].z];
sort(v.begin(), v.end(), cmp);
solve(0, v.size() - 1);
for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int32_t main()':
examination.cpp:90:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < xs.size(); i++) mx[xs[i]] = i + 1;
| ~~^~~~~~~~~~~
examination.cpp:91:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 0; i < ys.size(); i++) my[ys[i]] = i + 1;
| ~~^~~~~~~~~~~
examination.cpp:92:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int i = 0; i < zs.size(); i++) mz[zs[i]] = i + 1;
| ~~^~~~~~~~~~~
examination.cpp:93:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 0; i < v.size(); i++) v[i].x = mx[v[i].x], v[i].y = my[v[i].y], v[i].z = mz[v[i].z];
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
14 ms |
2240 KB |
Output is correct |
8 |
Correct |
14 ms |
2244 KB |
Output is correct |
9 |
Correct |
14 ms |
2240 KB |
Output is correct |
10 |
Correct |
11 ms |
1860 KB |
Output is correct |
11 |
Correct |
13 ms |
1864 KB |
Output is correct |
12 |
Correct |
7 ms |
1044 KB |
Output is correct |
13 |
Correct |
11 ms |
2200 KB |
Output is correct |
14 |
Correct |
11 ms |
2120 KB |
Output is correct |
15 |
Correct |
17 ms |
2188 KB |
Output is correct |
16 |
Correct |
9 ms |
1736 KB |
Output is correct |
17 |
Correct |
11 ms |
1780 KB |
Output is correct |
18 |
Correct |
5 ms |
1076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
590 ms |
43080 KB |
Output is correct |
2 |
Correct |
697 ms |
43124 KB |
Output is correct |
3 |
Correct |
650 ms |
43032 KB |
Output is correct |
4 |
Correct |
414 ms |
35688 KB |
Output is correct |
5 |
Correct |
506 ms |
36328 KB |
Output is correct |
6 |
Correct |
260 ms |
25596 KB |
Output is correct |
7 |
Correct |
566 ms |
41828 KB |
Output is correct |
8 |
Correct |
564 ms |
41688 KB |
Output is correct |
9 |
Correct |
541 ms |
40352 KB |
Output is correct |
10 |
Correct |
416 ms |
36336 KB |
Output is correct |
11 |
Correct |
395 ms |
35680 KB |
Output is correct |
12 |
Correct |
207 ms |
25632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
590 ms |
43080 KB |
Output is correct |
2 |
Correct |
697 ms |
43124 KB |
Output is correct |
3 |
Correct |
650 ms |
43032 KB |
Output is correct |
4 |
Correct |
414 ms |
35688 KB |
Output is correct |
5 |
Correct |
506 ms |
36328 KB |
Output is correct |
6 |
Correct |
260 ms |
25596 KB |
Output is correct |
7 |
Correct |
566 ms |
41828 KB |
Output is correct |
8 |
Correct |
564 ms |
41688 KB |
Output is correct |
9 |
Correct |
541 ms |
40352 KB |
Output is correct |
10 |
Correct |
416 ms |
36336 KB |
Output is correct |
11 |
Correct |
395 ms |
35680 KB |
Output is correct |
12 |
Correct |
207 ms |
25632 KB |
Output is correct |
13 |
Correct |
737 ms |
43520 KB |
Output is correct |
14 |
Correct |
732 ms |
45564 KB |
Output is correct |
15 |
Correct |
633 ms |
43164 KB |
Output is correct |
16 |
Correct |
537 ms |
33212 KB |
Output is correct |
17 |
Correct |
595 ms |
33956 KB |
Output is correct |
18 |
Correct |
294 ms |
24996 KB |
Output is correct |
19 |
Correct |
784 ms |
43520 KB |
Output is correct |
20 |
Correct |
798 ms |
44656 KB |
Output is correct |
21 |
Correct |
701 ms |
42400 KB |
Output is correct |
22 |
Correct |
491 ms |
36340 KB |
Output is correct |
23 |
Correct |
456 ms |
35656 KB |
Output is correct |
24 |
Correct |
204 ms |
25628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
14 ms |
2240 KB |
Output is correct |
8 |
Correct |
14 ms |
2244 KB |
Output is correct |
9 |
Correct |
14 ms |
2240 KB |
Output is correct |
10 |
Correct |
11 ms |
1860 KB |
Output is correct |
11 |
Correct |
13 ms |
1864 KB |
Output is correct |
12 |
Correct |
7 ms |
1044 KB |
Output is correct |
13 |
Correct |
11 ms |
2200 KB |
Output is correct |
14 |
Correct |
11 ms |
2120 KB |
Output is correct |
15 |
Correct |
17 ms |
2188 KB |
Output is correct |
16 |
Correct |
9 ms |
1736 KB |
Output is correct |
17 |
Correct |
11 ms |
1780 KB |
Output is correct |
18 |
Correct |
5 ms |
1076 KB |
Output is correct |
19 |
Correct |
590 ms |
43080 KB |
Output is correct |
20 |
Correct |
697 ms |
43124 KB |
Output is correct |
21 |
Correct |
650 ms |
43032 KB |
Output is correct |
22 |
Correct |
414 ms |
35688 KB |
Output is correct |
23 |
Correct |
506 ms |
36328 KB |
Output is correct |
24 |
Correct |
260 ms |
25596 KB |
Output is correct |
25 |
Correct |
566 ms |
41828 KB |
Output is correct |
26 |
Correct |
564 ms |
41688 KB |
Output is correct |
27 |
Correct |
541 ms |
40352 KB |
Output is correct |
28 |
Correct |
416 ms |
36336 KB |
Output is correct |
29 |
Correct |
395 ms |
35680 KB |
Output is correct |
30 |
Correct |
207 ms |
25632 KB |
Output is correct |
31 |
Correct |
737 ms |
43520 KB |
Output is correct |
32 |
Correct |
732 ms |
45564 KB |
Output is correct |
33 |
Correct |
633 ms |
43164 KB |
Output is correct |
34 |
Correct |
537 ms |
33212 KB |
Output is correct |
35 |
Correct |
595 ms |
33956 KB |
Output is correct |
36 |
Correct |
294 ms |
24996 KB |
Output is correct |
37 |
Correct |
784 ms |
43520 KB |
Output is correct |
38 |
Correct |
798 ms |
44656 KB |
Output is correct |
39 |
Correct |
701 ms |
42400 KB |
Output is correct |
40 |
Correct |
491 ms |
36340 KB |
Output is correct |
41 |
Correct |
456 ms |
35656 KB |
Output is correct |
42 |
Correct |
204 ms |
25628 KB |
Output is correct |
43 |
Correct |
1045 ms |
65256 KB |
Output is correct |
44 |
Correct |
1022 ms |
65376 KB |
Output is correct |
45 |
Correct |
999 ms |
67892 KB |
Output is correct |
46 |
Correct |
776 ms |
48592 KB |
Output is correct |
47 |
Correct |
782 ms |
50168 KB |
Output is correct |
48 |
Correct |
269 ms |
21356 KB |
Output is correct |
49 |
Correct |
996 ms |
68312 KB |
Output is correct |
50 |
Correct |
968 ms |
65340 KB |
Output is correct |
51 |
Correct |
994 ms |
67696 KB |
Output is correct |
52 |
Correct |
745 ms |
49992 KB |
Output is correct |
53 |
Correct |
515 ms |
45876 KB |
Output is correct |