#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <tuple>
using namespace std;
const int MAXN = 100007, MAXC = 2e9 + 7;
vector<int> val_x, val_y;
pair<int, int> pnts[MAXN];
int N, Q, X[MAXN], Y[MAXN], Z[MAXN], ans[MAXN];
vector<int> queries;
struct IT2D
{
int bit[MAXN];
void init() { memset(bit, 0, sizeof bit); }
void upd(int i, int x) { for (++i; i < MAXN; i += i & (-i)) bit[i] += x; }
int get(int i) { int ans = 0; for (++i; i > 0; i -= i & (-i)) ans += bit[i]; return ans; }
} bit_x, bit_y;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> Q;
for (int i = 0; i < N; ++i) {
cin >> pnts[i].first >> pnts[i].second;
val_x.push_back(pnts[i].first);
val_y.push_back(pnts[i].second);
}
sort(val_x.begin(), val_x.end()); val_x.erase(unique(val_x.begin(), val_x.end()), val_x.end());
sort(val_y.begin(), val_y.end()); val_y.erase(unique(val_y.begin(), val_y.end()), val_y.end());
for (int i = 0; i < Q; ++i) { cin >> X[i] >> Y[i] >> Z[i]; Z[i] = max(Z[i], X[i] + Y[i]); }
queries.resize(Q);
iota(queries.begin(), queries.end(), 0);
// iterate x
sort(pnts, pnts + N, [&](pair<int, int> p1, pair<int, int> p2) { return p1.first < p2.first; } );
sort(queries.begin(), queries.end(), [&](int i, int j) { return X[i] < X[j]; });
bit_x.init(); bit_y.init();
for (int i = 0, j = 0; i < N || j < Q;) {
if (j < Q && (i == N || X[queries[j]] <= pnts[i].first)) {
ans[queries[j]] += i;
++j;
} else {
bit_y.upd(lower_bound(val_y.begin(), val_y.end(), pnts[i].second) - val_y.begin(), 1);
++i;
}
}
// cerr << "S" << endl;
for (int id = 0; id < Q; ++id) ans[id] += bit_y.get(lower_bound(val_y.begin(), val_y.end(), Y[id]) - val_y.begin() - 1);
// iterate x + y), 0);
sort(pnts, pnts + N, [&](pair<int, int> p1, pair<int, int> p2) { return p1.first + p1.second < p2.first + p2.second; } );
sort(queries.begin(), queries.end(), [&](int i, int j) { return Z[i] < Z[j]; });
bit_x.init(); bit_y.init();
for (int i = 0, j = 0; i < N || j < Q;) {
if (j < Q && (i == N || Z[queries[j]] <= pnts[i].first + pnts[i].second)) {
ans[queries[j]] += i;
ans[queries[j]] -= bit_x.get(lower_bound(val_x.begin(), val_x.end(), X[queries[j]]) - val_x.begin() - 1);
ans[queries[j]] -= bit_y.get(lower_bound(val_y.begin(), val_y.end(), Y[queries[j]]) - val_y.begin() - 1);
++j;
} else {
bit_x.upd(lower_bound(val_x.begin(), val_x.end(), pnts[i].first) - val_x.begin(), 1);
bit_y.upd(lower_bound(val_y.begin(), val_y.end(), pnts[i].second) - val_y.begin(), 1);
++i;
}
}
for (int i = 0; i < Q; ++i) {
cout << N - ans[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
8 ms |
1272 KB |
Output is correct |
8 |
Correct |
8 ms |
1272 KB |
Output is correct |
9 |
Correct |
8 ms |
1272 KB |
Output is correct |
10 |
Correct |
7 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1276 KB |
Output is correct |
12 |
Correct |
6 ms |
1276 KB |
Output is correct |
13 |
Correct |
8 ms |
1400 KB |
Output is correct |
14 |
Correct |
8 ms |
1272 KB |
Output is correct |
15 |
Correct |
8 ms |
1272 KB |
Output is correct |
16 |
Correct |
6 ms |
1276 KB |
Output is correct |
17 |
Correct |
6 ms |
1272 KB |
Output is correct |
18 |
Correct |
5 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
5508 KB |
Output is correct |
2 |
Correct |
228 ms |
5468 KB |
Output is correct |
3 |
Correct |
227 ms |
5476 KB |
Output is correct |
4 |
Correct |
132 ms |
5440 KB |
Output is correct |
5 |
Correct |
154 ms |
5444 KB |
Output is correct |
6 |
Correct |
91 ms |
5484 KB |
Output is correct |
7 |
Correct |
216 ms |
5484 KB |
Output is correct |
8 |
Correct |
210 ms |
5480 KB |
Output is correct |
9 |
Correct |
202 ms |
5556 KB |
Output is correct |
10 |
Correct |
144 ms |
5416 KB |
Output is correct |
11 |
Correct |
118 ms |
5476 KB |
Output is correct |
12 |
Correct |
71 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
5508 KB |
Output is correct |
2 |
Correct |
228 ms |
5468 KB |
Output is correct |
3 |
Correct |
227 ms |
5476 KB |
Output is correct |
4 |
Correct |
132 ms |
5440 KB |
Output is correct |
5 |
Correct |
154 ms |
5444 KB |
Output is correct |
6 |
Correct |
91 ms |
5484 KB |
Output is correct |
7 |
Correct |
216 ms |
5484 KB |
Output is correct |
8 |
Correct |
210 ms |
5480 KB |
Output is correct |
9 |
Correct |
202 ms |
5556 KB |
Output is correct |
10 |
Correct |
144 ms |
5416 KB |
Output is correct |
11 |
Correct |
118 ms |
5476 KB |
Output is correct |
12 |
Correct |
71 ms |
5100 KB |
Output is correct |
13 |
Correct |
236 ms |
5572 KB |
Output is correct |
14 |
Correct |
233 ms |
5608 KB |
Output is correct |
15 |
Correct |
224 ms |
5480 KB |
Output is correct |
16 |
Correct |
148 ms |
5564 KB |
Output is correct |
17 |
Correct |
167 ms |
5468 KB |
Output is correct |
18 |
Correct |
92 ms |
5484 KB |
Output is correct |
19 |
Correct |
280 ms |
5424 KB |
Output is correct |
20 |
Correct |
235 ms |
5428 KB |
Output is correct |
21 |
Correct |
232 ms |
5596 KB |
Output is correct |
22 |
Correct |
144 ms |
5352 KB |
Output is correct |
23 |
Correct |
118 ms |
5200 KB |
Output is correct |
24 |
Correct |
70 ms |
5096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
8 ms |
1272 KB |
Output is correct |
8 |
Correct |
8 ms |
1272 KB |
Output is correct |
9 |
Correct |
8 ms |
1272 KB |
Output is correct |
10 |
Correct |
7 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1276 KB |
Output is correct |
12 |
Correct |
6 ms |
1276 KB |
Output is correct |
13 |
Correct |
8 ms |
1400 KB |
Output is correct |
14 |
Correct |
8 ms |
1272 KB |
Output is correct |
15 |
Correct |
8 ms |
1272 KB |
Output is correct |
16 |
Correct |
6 ms |
1276 KB |
Output is correct |
17 |
Correct |
6 ms |
1272 KB |
Output is correct |
18 |
Correct |
5 ms |
1272 KB |
Output is correct |
19 |
Correct |
227 ms |
5508 KB |
Output is correct |
20 |
Correct |
228 ms |
5468 KB |
Output is correct |
21 |
Correct |
227 ms |
5476 KB |
Output is correct |
22 |
Correct |
132 ms |
5440 KB |
Output is correct |
23 |
Correct |
154 ms |
5444 KB |
Output is correct |
24 |
Correct |
91 ms |
5484 KB |
Output is correct |
25 |
Correct |
216 ms |
5484 KB |
Output is correct |
26 |
Correct |
210 ms |
5480 KB |
Output is correct |
27 |
Correct |
202 ms |
5556 KB |
Output is correct |
28 |
Correct |
144 ms |
5416 KB |
Output is correct |
29 |
Correct |
118 ms |
5476 KB |
Output is correct |
30 |
Correct |
71 ms |
5100 KB |
Output is correct |
31 |
Correct |
236 ms |
5572 KB |
Output is correct |
32 |
Correct |
233 ms |
5608 KB |
Output is correct |
33 |
Correct |
224 ms |
5480 KB |
Output is correct |
34 |
Correct |
148 ms |
5564 KB |
Output is correct |
35 |
Correct |
167 ms |
5468 KB |
Output is correct |
36 |
Correct |
92 ms |
5484 KB |
Output is correct |
37 |
Correct |
280 ms |
5424 KB |
Output is correct |
38 |
Correct |
235 ms |
5428 KB |
Output is correct |
39 |
Correct |
232 ms |
5596 KB |
Output is correct |
40 |
Correct |
144 ms |
5352 KB |
Output is correct |
41 |
Correct |
118 ms |
5200 KB |
Output is correct |
42 |
Correct |
70 ms |
5096 KB |
Output is correct |
43 |
Correct |
259 ms |
5484 KB |
Output is correct |
44 |
Correct |
263 ms |
5484 KB |
Output is correct |
45 |
Correct |
254 ms |
5480 KB |
Output is correct |
46 |
Correct |
158 ms |
5480 KB |
Output is correct |
47 |
Correct |
188 ms |
5356 KB |
Output is correct |
48 |
Correct |
97 ms |
5224 KB |
Output is correct |
49 |
Correct |
252 ms |
5520 KB |
Output is correct |
50 |
Correct |
248 ms |
5356 KB |
Output is correct |
51 |
Correct |
239 ms |
5484 KB |
Output is correct |
52 |
Correct |
167 ms |
5272 KB |
Output is correct |
53 |
Correct |
126 ms |
5408 KB |
Output is correct |