#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int inf = 1e9 + 1;
const int N = 1e5 + 5;
vector<int> f[2 * N], bit[2 * N];
vector<pair<int, ii>> Sd;
vector<int> X, Y;
vector<pair<ii, ii>> E;
int n, q, ans[N];
void fakeup(int a, int b) {
int x = lower_bound(X.begin(), X.end(), a) - X.begin();
while(x > 0) {
int y = lower_bound(Y.begin(), Y.end(), b) - Y.begin();
while(y > 0) {
f[x].pb(y);
y -= y & (-y);
}
x -= x & (-x);
}
}
void fakeget(int a, int b) {
int x = lower_bound(X.begin(), X.end(), a) - X.begin();
while(x < 2 * N) {
int y = lower_bound(Y.begin(), Y.end(), b) - Y.begin();
while(y < Y.size()) {
f[x].pb(y);
y += y & (-y);
}
x += x & (-x);
}
}
void up(int a, int b) {
// a = lower_bound(X.begin(), X.end(), a) - X.begin();
b = lower_bound(Y.begin(), Y.end(), b) - Y.begin();
int x = lower_bound(X.begin(), X.end(), a) - X.begin();
while(x > 0) {
int y = lower_bound(f[x].begin(), f[x].end(), b) - f[x].begin();
while(y > 0) {
bit[x][y]++;
y -= y & (-y);
}
x -= x & (-x);
}
}
int get(int a, int b) {
//a = lower_bound(X.begin(), X.end(), a) - X.begin();
b = lower_bound(Y.begin(), Y.end(), b) - Y.begin();
int sum = 0;
int x = lower_bound(X.begin(), X.end(), a) - X.begin();
while(x < 2 * N) {
int y = lower_bound(f[x].begin(), f[x].end(), b) - f[x].begin();
//cout << y << " " << f[x].size() << "\n";
while(y < f[x].size()) {
// cout << x << " " << y << " " << bit[x].size() << " " << X.size() << "\n";
sum += bit[x][y];
y += y & (-y);
}
x += x & (-x);
}
return sum;
}
int main() {
//cin.tie(0), ios_base::sync_with_stdio(0);
for(int i = 0; i < 2 * N; i++)
f[i].pb(-1);
cin >> n >> q;
X.pb(-1);
Y.pb(-1);
for(int i = 1; i <= n; i++) {
int s, t;
cin >> s >> t;
int val = s + t;
X.pb(s);
Y.pb(t);
Sd.pb({val, {s, t}});
}
sort(Sd.begin(), Sd.end());
for(int i = 1; i <= q; i++) {
int x, y, z;
cin >> x >> y >> z;
X.pb(x);
Y.pb(y);
E.pb({{z, i}, {x, y}});
}
sort(E.begin(), E.end());
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
int ptr = Sd.size() - 1;
for(int i = E.size() - 1; i >= 0; i--) {
while(ptr >= 0 && E[i].fi.fi <= Sd[ptr].fi) {
fakeup(Sd[ptr].se.fi, Sd[ptr].se.se);
ptr--;
}
fakeget(E[i].se.fi, E[i].se.se);
}
for(int i = 0; i < 2 * N; i++) {
sort(f[i].begin(), f[i].end());
f[i].erase(unique(f[i].begin(), f[i].end()), f[i].end());
bit[i].resize(f[i].size() + 5, 0);
}
ptr = Sd.size() - 1;
for(int i = E.size() - 1; i >= 0; i--) {
while(ptr >= 0 && E[i].fi.fi <= Sd[ptr].fi) {
up(Sd[ptr].se.fi, Sd[ptr].se.se);
ptr--;
}
ans[E[i].fi.se] = get(E[i].se.fi, E[i].se.se);
}
for(int i = 1; i <= q; i++)
cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'void fakeget(int, int)':
examination.cpp:42:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(y < Y.size()) {
~~^~~~~~~~~~
examination.cpp: In function 'int get(int, int)':
examination.cpp:72:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(y < f[x].size()) {
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
22264 KB |
Output is correct |
2 |
Correct |
42 ms |
22236 KB |
Output is correct |
3 |
Correct |
47 ms |
22264 KB |
Output is correct |
4 |
Correct |
42 ms |
22300 KB |
Output is correct |
5 |
Correct |
42 ms |
22264 KB |
Output is correct |
6 |
Correct |
42 ms |
22264 KB |
Output is correct |
7 |
Correct |
90 ms |
24952 KB |
Output is correct |
8 |
Correct |
91 ms |
24952 KB |
Output is correct |
9 |
Correct |
91 ms |
24952 KB |
Output is correct |
10 |
Correct |
65 ms |
23160 KB |
Output is correct |
11 |
Correct |
83 ms |
24568 KB |
Output is correct |
12 |
Correct |
56 ms |
22940 KB |
Output is correct |
13 |
Correct |
88 ms |
24956 KB |
Output is correct |
14 |
Correct |
89 ms |
24952 KB |
Output is correct |
15 |
Correct |
88 ms |
24952 KB |
Output is correct |
16 |
Correct |
81 ms |
24672 KB |
Output is correct |
17 |
Correct |
61 ms |
22868 KB |
Output is correct |
18 |
Correct |
54 ms |
23000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2069 ms |
136468 KB |
Output is correct |
2 |
Correct |
2065 ms |
136256 KB |
Output is correct |
3 |
Correct |
2053 ms |
136620 KB |
Output is correct |
4 |
Correct |
662 ms |
50704 KB |
Output is correct |
5 |
Correct |
1784 ms |
103324 KB |
Output is correct |
6 |
Correct |
431 ms |
46356 KB |
Output is correct |
7 |
Correct |
2064 ms |
131988 KB |
Output is correct |
8 |
Correct |
2103 ms |
139440 KB |
Output is correct |
9 |
Correct |
2126 ms |
133932 KB |
Output is correct |
10 |
Correct |
1757 ms |
102004 KB |
Output is correct |
11 |
Correct |
511 ms |
41328 KB |
Output is correct |
12 |
Correct |
380 ms |
43752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2069 ms |
136468 KB |
Output is correct |
2 |
Correct |
2065 ms |
136256 KB |
Output is correct |
3 |
Correct |
2053 ms |
136620 KB |
Output is correct |
4 |
Correct |
662 ms |
50704 KB |
Output is correct |
5 |
Correct |
1784 ms |
103324 KB |
Output is correct |
6 |
Correct |
431 ms |
46356 KB |
Output is correct |
7 |
Correct |
2064 ms |
131988 KB |
Output is correct |
8 |
Correct |
2103 ms |
139440 KB |
Output is correct |
9 |
Correct |
2126 ms |
133932 KB |
Output is correct |
10 |
Correct |
1757 ms |
102004 KB |
Output is correct |
11 |
Correct |
511 ms |
41328 KB |
Output is correct |
12 |
Correct |
380 ms |
43752 KB |
Output is correct |
13 |
Correct |
2158 ms |
135492 KB |
Output is correct |
14 |
Correct |
2110 ms |
136148 KB |
Output is correct |
15 |
Correct |
2064 ms |
136228 KB |
Output is correct |
16 |
Correct |
697 ms |
50916 KB |
Output is correct |
17 |
Correct |
1824 ms |
102100 KB |
Output is correct |
18 |
Correct |
440 ms |
46276 KB |
Output is correct |
19 |
Correct |
2120 ms |
135196 KB |
Output is correct |
20 |
Correct |
2127 ms |
135740 KB |
Output is correct |
21 |
Correct |
2176 ms |
130520 KB |
Output is correct |
22 |
Correct |
1854 ms |
102620 KB |
Output is correct |
23 |
Correct |
510 ms |
41464 KB |
Output is correct |
24 |
Correct |
365 ms |
43776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
22264 KB |
Output is correct |
2 |
Correct |
42 ms |
22236 KB |
Output is correct |
3 |
Correct |
47 ms |
22264 KB |
Output is correct |
4 |
Correct |
42 ms |
22300 KB |
Output is correct |
5 |
Correct |
42 ms |
22264 KB |
Output is correct |
6 |
Correct |
42 ms |
22264 KB |
Output is correct |
7 |
Correct |
90 ms |
24952 KB |
Output is correct |
8 |
Correct |
91 ms |
24952 KB |
Output is correct |
9 |
Correct |
91 ms |
24952 KB |
Output is correct |
10 |
Correct |
65 ms |
23160 KB |
Output is correct |
11 |
Correct |
83 ms |
24568 KB |
Output is correct |
12 |
Correct |
56 ms |
22940 KB |
Output is correct |
13 |
Correct |
88 ms |
24956 KB |
Output is correct |
14 |
Correct |
89 ms |
24952 KB |
Output is correct |
15 |
Correct |
88 ms |
24952 KB |
Output is correct |
16 |
Correct |
81 ms |
24672 KB |
Output is correct |
17 |
Correct |
61 ms |
22868 KB |
Output is correct |
18 |
Correct |
54 ms |
23000 KB |
Output is correct |
19 |
Correct |
2069 ms |
136468 KB |
Output is correct |
20 |
Correct |
2065 ms |
136256 KB |
Output is correct |
21 |
Correct |
2053 ms |
136620 KB |
Output is correct |
22 |
Correct |
662 ms |
50704 KB |
Output is correct |
23 |
Correct |
1784 ms |
103324 KB |
Output is correct |
24 |
Correct |
431 ms |
46356 KB |
Output is correct |
25 |
Correct |
2064 ms |
131988 KB |
Output is correct |
26 |
Correct |
2103 ms |
139440 KB |
Output is correct |
27 |
Correct |
2126 ms |
133932 KB |
Output is correct |
28 |
Correct |
1757 ms |
102004 KB |
Output is correct |
29 |
Correct |
511 ms |
41328 KB |
Output is correct |
30 |
Correct |
380 ms |
43752 KB |
Output is correct |
31 |
Correct |
2158 ms |
135492 KB |
Output is correct |
32 |
Correct |
2110 ms |
136148 KB |
Output is correct |
33 |
Correct |
2064 ms |
136228 KB |
Output is correct |
34 |
Correct |
697 ms |
50916 KB |
Output is correct |
35 |
Correct |
1824 ms |
102100 KB |
Output is correct |
36 |
Correct |
440 ms |
46276 KB |
Output is correct |
37 |
Correct |
2120 ms |
135196 KB |
Output is correct |
38 |
Correct |
2127 ms |
135740 KB |
Output is correct |
39 |
Correct |
2176 ms |
130520 KB |
Output is correct |
40 |
Correct |
1854 ms |
102620 KB |
Output is correct |
41 |
Correct |
510 ms |
41464 KB |
Output is correct |
42 |
Correct |
365 ms |
43776 KB |
Output is correct |
43 |
Correct |
2452 ms |
155588 KB |
Output is correct |
44 |
Correct |
2461 ms |
155680 KB |
Output is correct |
45 |
Correct |
2492 ms |
156220 KB |
Output is correct |
46 |
Correct |
843 ms |
53176 KB |
Output is correct |
47 |
Correct |
2090 ms |
112148 KB |
Output is correct |
48 |
Correct |
446 ms |
45720 KB |
Output is correct |
49 |
Correct |
2489 ms |
160480 KB |
Output is correct |
50 |
Correct |
2467 ms |
158500 KB |
Output is correct |
51 |
Correct |
2483 ms |
162480 KB |
Output is correct |
52 |
Correct |
2083 ms |
109364 KB |
Output is correct |
53 |
Correct |
632 ms |
44700 KB |
Output is correct |