#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int nax = 1e5 + 111;
const int pod = (1 << 17);
int n, q;
pair<int, int> t[nax];
struct gao {
int x, y, z, id;
bool operator <(gao a) const {
return z < a.z;
}
};
vector <gao> qu;
vector <int> val[2];
int daj(int x, int k) {
return (int) (lower_bound(val[k].begin(), val[k].end(), x) - val[k].begin()) + 1;
}
struct nod {
nod *l, *r;
int sum;
};
nod T[30000000];
nod *wsk = T;
nod* aloc() {
nod *r = wsk++;
r->sum = 0;
return r;
}
#define mak(x) x ? x : x = aloc()
void add(int x, nod *u, int l = 0, int r = pod - 1) {
if(l == r) {
u->sum++;
return;
}
int m = (l + r) / 2;
if(x <= m)
add(x, mak(u->l), l, m);
else
add(x, mak(u->r), m + 1, r);
u->sum = (u->l ? u->l->sum : 0) + (u->r ? u->r->sum : 0);
}
int query(int x, int y, nod *u, int l = 0, int r = pod - 1) {
if(!u) return 0;
if(x <= l && r <= y)
return u->sum;
int m = (l + r) / 2;
int res = 0;
if(x <= m)
res += query(x, y, u->l, l, m);
if(m < y)
res += query(x, y, u->r, m + 1, r);
return res;
}
nod *root[nax];
void addfen(int x, int y) {
for(int i = x; i < nax; i += i & -i)
add(y, root[i]);
}
int queryfen(int x, int y) {
int res = 0;
for(int i = x; 0 < i; i -= i & -i)
res += query(y, pod - 1, root[i]);
return res;
}
int qq(int x, int y) {
return queryfen(nax - 1, y) - queryfen(x - 1, y);
}
int ans[nax];
int main() {
scanf("%d %d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%d %d", &t[i].fi, &t[i].se);
val[0].pb(t[i].fi);
val[1].pb(t[i].se);
}
sort(t + 1, t + n + 1, [](pair<int,int> a, pair<int,int> b) {
return a.fi + a.se < b.fi + b.se;
});
for(int i = 1; i <= q; ++i) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
qu.pb({x, y, z, i});
}
for(int i = 0; i < 2; ++i) {
sort(val[i].begin(), val[i].end());
val[i].erase(unique(val[i].begin(), val[i].end()), val[i].end());
}
sort(qu.begin(), qu.end());
for(int i = 1; i < nax; ++i)
root[i] = aloc();
int wsk = n;
for(int i = q - 1; 0 <= i; --i) {
while(wsk >= 1 && qu[i].z <= t[wsk].fi + t[wsk].se) {
addfen(daj(t[wsk].fi, 0), daj(t[wsk].se, 1));
wsk--;
}
ans[qu[i].id] = qq(daj(qu[i].x, 0), daj(qu[i].y, 1));
}
for(int i = 1; i <= q; ++i)
printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:99:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &t[i].fi, &t[i].se);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:110:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &x, &y, &z);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3452 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
4 ms |
3484 KB |
Output is correct |
5 |
Correct |
5 ms |
3420 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
23 ms |
8056 KB |
Output is correct |
8 |
Correct |
23 ms |
8028 KB |
Output is correct |
9 |
Correct |
23 ms |
8028 KB |
Output is correct |
10 |
Correct |
16 ms |
5140 KB |
Output is correct |
11 |
Correct |
17 ms |
6136 KB |
Output is correct |
12 |
Correct |
13 ms |
3704 KB |
Output is correct |
13 |
Correct |
24 ms |
7928 KB |
Output is correct |
14 |
Correct |
24 ms |
7924 KB |
Output is correct |
15 |
Correct |
23 ms |
8036 KB |
Output is correct |
16 |
Correct |
16 ms |
6136 KB |
Output is correct |
17 |
Correct |
15 ms |
4984 KB |
Output is correct |
18 |
Correct |
12 ms |
3740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1411 ms |
179996 KB |
Output is correct |
2 |
Correct |
1416 ms |
182128 KB |
Output is correct |
3 |
Correct |
1438 ms |
182352 KB |
Output is correct |
4 |
Correct |
551 ms |
42340 KB |
Output is correct |
5 |
Correct |
469 ms |
63660 KB |
Output is correct |
6 |
Correct |
273 ms |
8904 KB |
Output is correct |
7 |
Correct |
1123 ms |
182312 KB |
Output is correct |
8 |
Correct |
1365 ms |
182240 KB |
Output is correct |
9 |
Correct |
929 ms |
182128 KB |
Output is correct |
10 |
Correct |
411 ms |
59748 KB |
Output is correct |
11 |
Correct |
502 ms |
34660 KB |
Output is correct |
12 |
Correct |
266 ms |
8420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1411 ms |
179996 KB |
Output is correct |
2 |
Correct |
1416 ms |
182128 KB |
Output is correct |
3 |
Correct |
1438 ms |
182352 KB |
Output is correct |
4 |
Correct |
551 ms |
42340 KB |
Output is correct |
5 |
Correct |
469 ms |
63660 KB |
Output is correct |
6 |
Correct |
273 ms |
8904 KB |
Output is correct |
7 |
Correct |
1123 ms |
182312 KB |
Output is correct |
8 |
Correct |
1365 ms |
182240 KB |
Output is correct |
9 |
Correct |
929 ms |
182128 KB |
Output is correct |
10 |
Correct |
411 ms |
59748 KB |
Output is correct |
11 |
Correct |
502 ms |
34660 KB |
Output is correct |
12 |
Correct |
266 ms |
8420 KB |
Output is correct |
13 |
Correct |
1172 ms |
182672 KB |
Output is correct |
14 |
Correct |
1448 ms |
182748 KB |
Output is correct |
15 |
Correct |
1477 ms |
182288 KB |
Output is correct |
16 |
Correct |
451 ms |
42812 KB |
Output is correct |
17 |
Correct |
449 ms |
63972 KB |
Output is correct |
18 |
Correct |
280 ms |
8772 KB |
Output is correct |
19 |
Correct |
1192 ms |
182712 KB |
Output is correct |
20 |
Correct |
1302 ms |
182776 KB |
Output is correct |
21 |
Correct |
995 ms |
183000 KB |
Output is correct |
22 |
Correct |
408 ms |
59880 KB |
Output is correct |
23 |
Correct |
467 ms |
34564 KB |
Output is correct |
24 |
Correct |
268 ms |
8548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3452 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
4 ms |
3484 KB |
Output is correct |
5 |
Correct |
5 ms |
3420 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
23 ms |
8056 KB |
Output is correct |
8 |
Correct |
23 ms |
8028 KB |
Output is correct |
9 |
Correct |
23 ms |
8028 KB |
Output is correct |
10 |
Correct |
16 ms |
5140 KB |
Output is correct |
11 |
Correct |
17 ms |
6136 KB |
Output is correct |
12 |
Correct |
13 ms |
3704 KB |
Output is correct |
13 |
Correct |
24 ms |
7928 KB |
Output is correct |
14 |
Correct |
24 ms |
7924 KB |
Output is correct |
15 |
Correct |
23 ms |
8036 KB |
Output is correct |
16 |
Correct |
16 ms |
6136 KB |
Output is correct |
17 |
Correct |
15 ms |
4984 KB |
Output is correct |
18 |
Correct |
12 ms |
3740 KB |
Output is correct |
19 |
Correct |
1411 ms |
179996 KB |
Output is correct |
20 |
Correct |
1416 ms |
182128 KB |
Output is correct |
21 |
Correct |
1438 ms |
182352 KB |
Output is correct |
22 |
Correct |
551 ms |
42340 KB |
Output is correct |
23 |
Correct |
469 ms |
63660 KB |
Output is correct |
24 |
Correct |
273 ms |
8904 KB |
Output is correct |
25 |
Correct |
1123 ms |
182312 KB |
Output is correct |
26 |
Correct |
1365 ms |
182240 KB |
Output is correct |
27 |
Correct |
929 ms |
182128 KB |
Output is correct |
28 |
Correct |
411 ms |
59748 KB |
Output is correct |
29 |
Correct |
502 ms |
34660 KB |
Output is correct |
30 |
Correct |
266 ms |
8420 KB |
Output is correct |
31 |
Correct |
1172 ms |
182672 KB |
Output is correct |
32 |
Correct |
1448 ms |
182748 KB |
Output is correct |
33 |
Correct |
1477 ms |
182288 KB |
Output is correct |
34 |
Correct |
451 ms |
42812 KB |
Output is correct |
35 |
Correct |
449 ms |
63972 KB |
Output is correct |
36 |
Correct |
280 ms |
8772 KB |
Output is correct |
37 |
Correct |
1192 ms |
182712 KB |
Output is correct |
38 |
Correct |
1302 ms |
182776 KB |
Output is correct |
39 |
Correct |
995 ms |
183000 KB |
Output is correct |
40 |
Correct |
408 ms |
59880 KB |
Output is correct |
41 |
Correct |
467 ms |
34564 KB |
Output is correct |
42 |
Correct |
268 ms |
8548 KB |
Output is correct |
43 |
Correct |
1280 ms |
209308 KB |
Output is correct |
44 |
Correct |
1316 ms |
209368 KB |
Output is correct |
45 |
Correct |
1569 ms |
209476 KB |
Output is correct |
46 |
Correct |
533 ms |
58740 KB |
Output is correct |
47 |
Correct |
490 ms |
92032 KB |
Output is correct |
48 |
Correct |
261 ms |
8536 KB |
Output is correct |
49 |
Correct |
1195 ms |
209496 KB |
Output is correct |
50 |
Correct |
1084 ms |
209332 KB |
Output is correct |
51 |
Correct |
965 ms |
209208 KB |
Output is correct |
52 |
Correct |
467 ms |
90724 KB |
Output is correct |
53 |
Correct |
582 ms |
50080 KB |
Output is correct |