#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2e5 + 5;
int n, q, sz;
int ans[SIZE];
int m;
vector<int> lis;
int bit[SIZE];
void upd(int pos, int x) {
for (; pos <= m; pos += pos & -pos) bit[pos] += x;
}
int que(int pos) {
int re = 0;
for (; pos; pos -= pos & -pos) re += bit[pos];
return re;
}
struct ds {
int x, y, z, id;
ds() {}
ds(int x, int y, int z, int id) : x(x), y(y), z(z), id(id) {}
bool operator < (const ds &o) const {
return make_tuple(x, y, z, id) < make_tuple(o.x, o.y, o.z, o.id);
}
} a[SIZE], tmp[SIZE];
bool cmp(ds a, ds b) { // return a < b
return make_tuple(a.y, a.z, a.id) < make_tuple(b.y, b.z, b.id);
}
void divide(int l, int r) {
if (l == r) return;
int mid = (l + r) / 2;
divide(l, mid), divide(mid + 1, r);
debug(l, r);
for (int i = l, il = l, ir = mid + 1; i <= r; i++) {
if (ir > r || (il <= mid && cmp(a[il], a[ir]))) {
if (a[il].id == 0) upd(a[il].z, 1);
tmp[i] = a[il++];
} else {
if (a[ir].id) ans[a[ir].id] += que(a[ir].z);
tmp[i] = a[ir++];
}
}
FOR (i, l, mid) if (a[i].id == 0) upd(a[i].z, -1);
FOR (i, l, r) a[i] = tmp[i];
}
void solve() {
cin >> n >> q;
FOR (i, 1, n) {
int x, y;
cin >> x >> y;
x = -x, y = -y;
a[++sz] = ds(x, y, x + y, 0);
}
FOR (i, 1, q) {
int x, y, z;
cin >> x >> y >> z;
x = -x, y = -y, z = -z;
a[++sz] = ds(x, y, z, i);
}
FOR (i, 1, sz) lis.pb(a[i].z);
sort(lis.begin(), lis.end());
lis.erase(unique(lis.begin(), lis.end()), lis.end());
m = lis.size();
FOR (i, 1, sz) a[i].z = lower_bound(lis.begin(), lis.end(), a[i].z) - lis.begin() + 1;
sort(a + 1, a + sz + 1);
divide(1, sz);
FOR (i, 1, q) cout << ans[i] << '\n';
}
int main() {
Waimai;
solve();
}
/*
in1
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
out1
2
4
1
1
in2
10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
out2
1
3
5
8
8
3
3
3
5
6
*/
Compilation message
examination.cpp: In function 'void divide(int, int)':
examination.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 7122
| ^~~~
examination.cpp:57:5: note: in expansion of macro 'debug'
57 | debug(l, r);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
5 ms |
4700 KB |
Output is correct |
8 |
Correct |
5 ms |
2652 KB |
Output is correct |
9 |
Correct |
5 ms |
4836 KB |
Output is correct |
10 |
Correct |
5 ms |
2648 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4752 KB |
Output is correct |
13 |
Correct |
5 ms |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
4696 KB |
Output is correct |
15 |
Correct |
4 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
4 ms |
4840 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
11560 KB |
Output is correct |
2 |
Correct |
149 ms |
11228 KB |
Output is correct |
3 |
Correct |
150 ms |
11212 KB |
Output is correct |
4 |
Correct |
130 ms |
10580 KB |
Output is correct |
5 |
Correct |
130 ms |
10840 KB |
Output is correct |
6 |
Correct |
69 ms |
9532 KB |
Output is correct |
7 |
Correct |
134 ms |
11208 KB |
Output is correct |
8 |
Correct |
136 ms |
11216 KB |
Output is correct |
9 |
Correct |
140 ms |
11216 KB |
Output is correct |
10 |
Correct |
117 ms |
10296 KB |
Output is correct |
11 |
Correct |
123 ms |
10184 KB |
Output is correct |
12 |
Correct |
54 ms |
9168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
11560 KB |
Output is correct |
2 |
Correct |
149 ms |
11228 KB |
Output is correct |
3 |
Correct |
150 ms |
11212 KB |
Output is correct |
4 |
Correct |
130 ms |
10580 KB |
Output is correct |
5 |
Correct |
130 ms |
10840 KB |
Output is correct |
6 |
Correct |
69 ms |
9532 KB |
Output is correct |
7 |
Correct |
134 ms |
11208 KB |
Output is correct |
8 |
Correct |
136 ms |
11216 KB |
Output is correct |
9 |
Correct |
140 ms |
11216 KB |
Output is correct |
10 |
Correct |
117 ms |
10296 KB |
Output is correct |
11 |
Correct |
123 ms |
10184 KB |
Output is correct |
12 |
Correct |
54 ms |
9168 KB |
Output is correct |
13 |
Correct |
174 ms |
11728 KB |
Output is correct |
14 |
Correct |
174 ms |
11788 KB |
Output is correct |
15 |
Correct |
167 ms |
11296 KB |
Output is correct |
16 |
Correct |
155 ms |
10836 KB |
Output is correct |
17 |
Correct |
154 ms |
10952 KB |
Output is correct |
18 |
Correct |
88 ms |
9672 KB |
Output is correct |
19 |
Correct |
175 ms |
11848 KB |
Output is correct |
20 |
Correct |
179 ms |
11936 KB |
Output is correct |
21 |
Correct |
179 ms |
11976 KB |
Output is correct |
22 |
Correct |
114 ms |
10188 KB |
Output is correct |
23 |
Correct |
123 ms |
10184 KB |
Output is correct |
24 |
Correct |
54 ms |
9168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
5 ms |
4700 KB |
Output is correct |
8 |
Correct |
5 ms |
2652 KB |
Output is correct |
9 |
Correct |
5 ms |
4836 KB |
Output is correct |
10 |
Correct |
5 ms |
2648 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4752 KB |
Output is correct |
13 |
Correct |
5 ms |
2652 KB |
Output is correct |
14 |
Correct |
4 ms |
4696 KB |
Output is correct |
15 |
Correct |
4 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
4 ms |
4840 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
154 ms |
11560 KB |
Output is correct |
20 |
Correct |
149 ms |
11228 KB |
Output is correct |
21 |
Correct |
150 ms |
11212 KB |
Output is correct |
22 |
Correct |
130 ms |
10580 KB |
Output is correct |
23 |
Correct |
130 ms |
10840 KB |
Output is correct |
24 |
Correct |
69 ms |
9532 KB |
Output is correct |
25 |
Correct |
134 ms |
11208 KB |
Output is correct |
26 |
Correct |
136 ms |
11216 KB |
Output is correct |
27 |
Correct |
140 ms |
11216 KB |
Output is correct |
28 |
Correct |
117 ms |
10296 KB |
Output is correct |
29 |
Correct |
123 ms |
10184 KB |
Output is correct |
30 |
Correct |
54 ms |
9168 KB |
Output is correct |
31 |
Correct |
174 ms |
11728 KB |
Output is correct |
32 |
Correct |
174 ms |
11788 KB |
Output is correct |
33 |
Correct |
167 ms |
11296 KB |
Output is correct |
34 |
Correct |
155 ms |
10836 KB |
Output is correct |
35 |
Correct |
154 ms |
10952 KB |
Output is correct |
36 |
Correct |
88 ms |
9672 KB |
Output is correct |
37 |
Correct |
175 ms |
11848 KB |
Output is correct |
38 |
Correct |
179 ms |
11936 KB |
Output is correct |
39 |
Correct |
179 ms |
11976 KB |
Output is correct |
40 |
Correct |
114 ms |
10188 KB |
Output is correct |
41 |
Correct |
123 ms |
10184 KB |
Output is correct |
42 |
Correct |
54 ms |
9168 KB |
Output is correct |
43 |
Correct |
191 ms |
14124 KB |
Output is correct |
44 |
Correct |
187 ms |
14120 KB |
Output is correct |
45 |
Correct |
186 ms |
14028 KB |
Output is correct |
46 |
Correct |
166 ms |
12864 KB |
Output is correct |
47 |
Correct |
167 ms |
12492 KB |
Output is correct |
48 |
Correct |
95 ms |
9420 KB |
Output is correct |
49 |
Correct |
170 ms |
14040 KB |
Output is correct |
50 |
Correct |
170 ms |
14136 KB |
Output is correct |
51 |
Correct |
168 ms |
13944 KB |
Output is correct |
52 |
Correct |
152 ms |
12572 KB |
Output is correct |
53 |
Correct |
115 ms |
11216 KB |
Output is correct |