#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()) {
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
22388 KB |
Output is correct |
2 |
Correct |
43 ms |
22268 KB |
Output is correct |
3 |
Correct |
43 ms |
22264 KB |
Output is correct |
4 |
Correct |
43 ms |
22256 KB |
Output is correct |
5 |
Correct |
43 ms |
22236 KB |
Output is correct |
6 |
Correct |
43 ms |
22288 KB |
Output is correct |
7 |
Correct |
82 ms |
24940 KB |
Output is correct |
8 |
Correct |
82 ms |
24972 KB |
Output is correct |
9 |
Correct |
82 ms |
24924 KB |
Output is correct |
10 |
Correct |
58 ms |
23160 KB |
Output is correct |
11 |
Correct |
78 ms |
24540 KB |
Output is correct |
12 |
Correct |
54 ms |
22940 KB |
Output is correct |
13 |
Correct |
82 ms |
24924 KB |
Output is correct |
14 |
Correct |
83 ms |
24952 KB |
Output is correct |
15 |
Correct |
82 ms |
25032 KB |
Output is correct |
16 |
Correct |
77 ms |
24572 KB |
Output is correct |
17 |
Correct |
56 ms |
22928 KB |
Output is correct |
18 |
Correct |
52 ms |
23000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1911 ms |
136068 KB |
Output is correct |
2 |
Correct |
1906 ms |
136440 KB |
Output is correct |
3 |
Correct |
1927 ms |
136436 KB |
Output is correct |
4 |
Correct |
521 ms |
50860 KB |
Output is correct |
5 |
Correct |
1757 ms |
103044 KB |
Output is correct |
6 |
Correct |
332 ms |
46508 KB |
Output is correct |
7 |
Correct |
1893 ms |
132052 KB |
Output is correct |
8 |
Correct |
1946 ms |
139540 KB |
Output is correct |
9 |
Correct |
1917 ms |
133884 KB |
Output is correct |
10 |
Correct |
1610 ms |
101916 KB |
Output is correct |
11 |
Correct |
390 ms |
41496 KB |
Output is correct |
12 |
Correct |
269 ms |
43868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1911 ms |
136068 KB |
Output is correct |
2 |
Correct |
1906 ms |
136440 KB |
Output is correct |
3 |
Correct |
1927 ms |
136436 KB |
Output is correct |
4 |
Correct |
521 ms |
50860 KB |
Output is correct |
5 |
Correct |
1757 ms |
103044 KB |
Output is correct |
6 |
Correct |
332 ms |
46508 KB |
Output is correct |
7 |
Correct |
1893 ms |
132052 KB |
Output is correct |
8 |
Correct |
1946 ms |
139540 KB |
Output is correct |
9 |
Correct |
1917 ms |
133884 KB |
Output is correct |
10 |
Correct |
1610 ms |
101916 KB |
Output is correct |
11 |
Correct |
390 ms |
41496 KB |
Output is correct |
12 |
Correct |
269 ms |
43868 KB |
Output is correct |
13 |
Correct |
1940 ms |
134756 KB |
Output is correct |
14 |
Correct |
1919 ms |
135736 KB |
Output is correct |
15 |
Correct |
1921 ms |
136080 KB |
Output is correct |
16 |
Correct |
549 ms |
50972 KB |
Output is correct |
17 |
Correct |
1664 ms |
102260 KB |
Output is correct |
18 |
Correct |
342 ms |
46104 KB |
Output is correct |
19 |
Correct |
1911 ms |
134800 KB |
Output is correct |
20 |
Correct |
1930 ms |
134308 KB |
Output is correct |
21 |
Correct |
2075 ms |
129432 KB |
Output is correct |
22 |
Correct |
1621 ms |
102532 KB |
Output is correct |
23 |
Correct |
384 ms |
41296 KB |
Output is correct |
24 |
Correct |
268 ms |
43792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
22388 KB |
Output is correct |
2 |
Correct |
43 ms |
22268 KB |
Output is correct |
3 |
Correct |
43 ms |
22264 KB |
Output is correct |
4 |
Correct |
43 ms |
22256 KB |
Output is correct |
5 |
Correct |
43 ms |
22236 KB |
Output is correct |
6 |
Correct |
43 ms |
22288 KB |
Output is correct |
7 |
Correct |
82 ms |
24940 KB |
Output is correct |
8 |
Correct |
82 ms |
24972 KB |
Output is correct |
9 |
Correct |
82 ms |
24924 KB |
Output is correct |
10 |
Correct |
58 ms |
23160 KB |
Output is correct |
11 |
Correct |
78 ms |
24540 KB |
Output is correct |
12 |
Correct |
54 ms |
22940 KB |
Output is correct |
13 |
Correct |
82 ms |
24924 KB |
Output is correct |
14 |
Correct |
83 ms |
24952 KB |
Output is correct |
15 |
Correct |
82 ms |
25032 KB |
Output is correct |
16 |
Correct |
77 ms |
24572 KB |
Output is correct |
17 |
Correct |
56 ms |
22928 KB |
Output is correct |
18 |
Correct |
52 ms |
23000 KB |
Output is correct |
19 |
Correct |
1911 ms |
136068 KB |
Output is correct |
20 |
Correct |
1906 ms |
136440 KB |
Output is correct |
21 |
Correct |
1927 ms |
136436 KB |
Output is correct |
22 |
Correct |
521 ms |
50860 KB |
Output is correct |
23 |
Correct |
1757 ms |
103044 KB |
Output is correct |
24 |
Correct |
332 ms |
46508 KB |
Output is correct |
25 |
Correct |
1893 ms |
132052 KB |
Output is correct |
26 |
Correct |
1946 ms |
139540 KB |
Output is correct |
27 |
Correct |
1917 ms |
133884 KB |
Output is correct |
28 |
Correct |
1610 ms |
101916 KB |
Output is correct |
29 |
Correct |
390 ms |
41496 KB |
Output is correct |
30 |
Correct |
269 ms |
43868 KB |
Output is correct |
31 |
Correct |
1940 ms |
134756 KB |
Output is correct |
32 |
Correct |
1919 ms |
135736 KB |
Output is correct |
33 |
Correct |
1921 ms |
136080 KB |
Output is correct |
34 |
Correct |
549 ms |
50972 KB |
Output is correct |
35 |
Correct |
1664 ms |
102260 KB |
Output is correct |
36 |
Correct |
342 ms |
46104 KB |
Output is correct |
37 |
Correct |
1911 ms |
134800 KB |
Output is correct |
38 |
Correct |
1930 ms |
134308 KB |
Output is correct |
39 |
Correct |
2075 ms |
129432 KB |
Output is correct |
40 |
Correct |
1621 ms |
102532 KB |
Output is correct |
41 |
Correct |
384 ms |
41296 KB |
Output is correct |
42 |
Correct |
268 ms |
43792 KB |
Output is correct |
43 |
Correct |
2144 ms |
151924 KB |
Output is correct |
44 |
Correct |
2146 ms |
151400 KB |
Output is correct |
45 |
Correct |
2133 ms |
151516 KB |
Output is correct |
46 |
Correct |
616 ms |
50076 KB |
Output is correct |
47 |
Correct |
1872 ms |
108976 KB |
Output is correct |
48 |
Correct |
344 ms |
44820 KB |
Output is correct |
49 |
Correct |
2144 ms |
155864 KB |
Output is correct |
50 |
Correct |
2168 ms |
153496 KB |
Output is correct |
51 |
Correct |
2192 ms |
157796 KB |
Output is correct |
52 |
Correct |
1860 ms |
106248 KB |
Output is correct |
53 |
Correct |
448 ms |
42440 KB |
Output is correct |