#include<bits/stdc++.h>
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
using namespace std;
const int maxn = 100100;
int N, M, Q, Ans[maxn], S[maxn], T[maxn];
int A[maxn], B[maxn], C[maxn];
vector <int> vs, vt[maxn], ft[maxn];
array<int, 2> D[maxn], E[maxn];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen("cc.inp", "r", stdin);
// freopen("cc.out", "w", stdout);
cin >> N >> Q;
for (int i = 0; i < N; ++i) {
cin >> S[i] >> T[i];
S[i] = -S[i]; T[i] = -T[i];
D[i] = {S[i] + T[i], i};
vs.push_back(S[i]);
}
sort(vs.begin(), vs.end());
vs.resize(M = unique(vs.begin(), vs.end()) - vs.begin());
for (int i = 0; i < N; ++i) {
S[i] = lower_bound(vs.begin(), vs.end(), S[i]) - vs.begin();
for (int j = S[i] + 1; j <= M; j += j & -j)
vt[j].push_back(T[i]);
}
for (int i = 1; i <= M; ++i) {
sort(vt[i].begin(), vt[i].end());
vt[i].resize(unique(vt[i].begin(), vt[i].end()) - vt[i].begin());
ft[i].resize(vt[i].size() + 1);
}
sort(D, D + N);
for (int i = 0; i < Q; ++i) {
cin >> A[i] >> B[i] >> C[i];
A[i] = -A[i];
B[i] = -B[i];
C[i] = -C[i];
E[i] = {C[i], i};
}
sort(E, E + Q);
for (int i1 = 0, i2 = 0; i1 < Q; ++i1) {
while (i2 < N && D[i2][0] <= E[i1][0]) {
for (int i = S[D[i2][1]] + 1; i <= M; i += i & -i)
for (int j = lower_bound(vt[i].begin(), vt[i].end(), T[D[i2][1]]) - vt[i].begin() + 1; j <= vt[i].size(); j += j & -j)
ft[i][j]++;
++i2;
}
for (int i = upper_bound(vs.begin(), vs.end(), A[E[i1][1]]) - vs.begin(); i; i -= i & -i) {
for (int j = upper_bound(vt[i].begin(), vt[i].end(), B[E[i1][1]]) - vt[i].begin(); j; j -= j & -j)
Ans[E[i1][1]] += ft[i][j];
}
}
for (int i = 0; i < Q; ++i) {
cout << Ans[i] << '\n';
}
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:48:98: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = lower_bound(vt[i].begin(), vt[i].end(), T[D[i2][1]]) - vt[i].begin() + 1; j <= vt[i].size(); j += j & -j)
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
5452 KB |
Output is correct |
8 |
Correct |
12 ms |
5488 KB |
Output is correct |
9 |
Correct |
11 ms |
5480 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
7 ms |
5196 KB |
Output is correct |
12 |
Correct |
6 ms |
5196 KB |
Output is correct |
13 |
Correct |
9 ms |
5452 KB |
Output is correct |
14 |
Correct |
9 ms |
5452 KB |
Output is correct |
15 |
Correct |
10 ms |
5452 KB |
Output is correct |
16 |
Correct |
6 ms |
5152 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
5 ms |
5196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
19392 KB |
Output is correct |
2 |
Correct |
394 ms |
19396 KB |
Output is correct |
3 |
Correct |
425 ms |
19464 KB |
Output is correct |
4 |
Correct |
221 ms |
17248 KB |
Output is correct |
5 |
Correct |
142 ms |
11724 KB |
Output is correct |
6 |
Correct |
92 ms |
11252 KB |
Output is correct |
7 |
Correct |
381 ms |
19528 KB |
Output is correct |
8 |
Correct |
395 ms |
19428 KB |
Output is correct |
9 |
Correct |
365 ms |
19524 KB |
Output is correct |
10 |
Correct |
98 ms |
10256 KB |
Output is correct |
11 |
Correct |
189 ms |
16864 KB |
Output is correct |
12 |
Correct |
65 ms |
9960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
19392 KB |
Output is correct |
2 |
Correct |
394 ms |
19396 KB |
Output is correct |
3 |
Correct |
425 ms |
19464 KB |
Output is correct |
4 |
Correct |
221 ms |
17248 KB |
Output is correct |
5 |
Correct |
142 ms |
11724 KB |
Output is correct |
6 |
Correct |
92 ms |
11252 KB |
Output is correct |
7 |
Correct |
381 ms |
19528 KB |
Output is correct |
8 |
Correct |
395 ms |
19428 KB |
Output is correct |
9 |
Correct |
365 ms |
19524 KB |
Output is correct |
10 |
Correct |
98 ms |
10256 KB |
Output is correct |
11 |
Correct |
189 ms |
16864 KB |
Output is correct |
12 |
Correct |
65 ms |
9960 KB |
Output is correct |
13 |
Correct |
467 ms |
19472 KB |
Output is correct |
14 |
Correct |
436 ms |
19464 KB |
Output is correct |
15 |
Correct |
404 ms |
19424 KB |
Output is correct |
16 |
Correct |
244 ms |
17176 KB |
Output is correct |
17 |
Correct |
156 ms |
11820 KB |
Output is correct |
18 |
Correct |
101 ms |
11376 KB |
Output is correct |
19 |
Correct |
472 ms |
19564 KB |
Output is correct |
20 |
Correct |
457 ms |
19416 KB |
Output is correct |
21 |
Correct |
418 ms |
19472 KB |
Output is correct |
22 |
Correct |
97 ms |
10300 KB |
Output is correct |
23 |
Correct |
172 ms |
16800 KB |
Output is correct |
24 |
Correct |
66 ms |
10184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
5452 KB |
Output is correct |
8 |
Correct |
12 ms |
5488 KB |
Output is correct |
9 |
Correct |
11 ms |
5480 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
7 ms |
5196 KB |
Output is correct |
12 |
Correct |
6 ms |
5196 KB |
Output is correct |
13 |
Correct |
9 ms |
5452 KB |
Output is correct |
14 |
Correct |
9 ms |
5452 KB |
Output is correct |
15 |
Correct |
10 ms |
5452 KB |
Output is correct |
16 |
Correct |
6 ms |
5152 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
5 ms |
5196 KB |
Output is correct |
19 |
Correct |
403 ms |
19392 KB |
Output is correct |
20 |
Correct |
394 ms |
19396 KB |
Output is correct |
21 |
Correct |
425 ms |
19464 KB |
Output is correct |
22 |
Correct |
221 ms |
17248 KB |
Output is correct |
23 |
Correct |
142 ms |
11724 KB |
Output is correct |
24 |
Correct |
92 ms |
11252 KB |
Output is correct |
25 |
Correct |
381 ms |
19528 KB |
Output is correct |
26 |
Correct |
395 ms |
19428 KB |
Output is correct |
27 |
Correct |
365 ms |
19524 KB |
Output is correct |
28 |
Correct |
98 ms |
10256 KB |
Output is correct |
29 |
Correct |
189 ms |
16864 KB |
Output is correct |
30 |
Correct |
65 ms |
9960 KB |
Output is correct |
31 |
Correct |
467 ms |
19472 KB |
Output is correct |
32 |
Correct |
436 ms |
19464 KB |
Output is correct |
33 |
Correct |
404 ms |
19424 KB |
Output is correct |
34 |
Correct |
244 ms |
17176 KB |
Output is correct |
35 |
Correct |
156 ms |
11820 KB |
Output is correct |
36 |
Correct |
101 ms |
11376 KB |
Output is correct |
37 |
Correct |
472 ms |
19564 KB |
Output is correct |
38 |
Correct |
457 ms |
19416 KB |
Output is correct |
39 |
Correct |
418 ms |
19472 KB |
Output is correct |
40 |
Correct |
97 ms |
10300 KB |
Output is correct |
41 |
Correct |
172 ms |
16800 KB |
Output is correct |
42 |
Correct |
66 ms |
10184 KB |
Output is correct |
43 |
Correct |
568 ms |
21820 KB |
Output is correct |
44 |
Correct |
525 ms |
21716 KB |
Output is correct |
45 |
Correct |
476 ms |
21464 KB |
Output is correct |
46 |
Correct |
272 ms |
19248 KB |
Output is correct |
47 |
Correct |
165 ms |
11972 KB |
Output is correct |
48 |
Correct |
99 ms |
11076 KB |
Output is correct |
49 |
Correct |
455 ms |
21620 KB |
Output is correct |
50 |
Correct |
463 ms |
21484 KB |
Output is correct |
51 |
Correct |
412 ms |
21572 KB |
Output is correct |
52 |
Correct |
116 ms |
10568 KB |
Output is correct |
53 |
Correct |
200 ms |
18808 KB |
Output is correct |