#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int BL = 317;
const int N = 100005;
struct Queries {
int a, b, c, id;
bool operator < (const Queries& other) {
if (a / BL != other.a / BL) {
return a < other.a;
}
return b < other.b;
};
};
int tree[N];
inline void upd (int id, int v) {
id++;
while (id < N) {
tree[id] += v;
id += id & -id;
}
}
inline int qry (int id) {
id++;
int ret = 0;
while (id) {
ret += tree[id];
id -= id & -id;
}
return ret;
}
inline int qry (int l, int r) {
return qry(r) - qry(l - 1);
}
pair<int, int> a[N], b[N];
int c[N], A[N], B[N], C[N];
Queries qs[N];
int ans[N];
int cnt[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; ++i) {
cin >> a[i].first >> b[i].first;
a[i].second = i;
b[i].second = i;
c[i] = a[i].first + b[i].first;
A[i] = a[i].first;
B[i] = b[i].first;
C[i] = c[i];
}
sort(a, a + n);
sort(A, A + n);
sort(b, b + n);
sort(B, B + n);
sort(C, C + n);
for (int i = 0; i < n; ++i) {
a[i].first = i;
b[i].first = i;
c[i] = lower_bound(C, C + n, c[i]) - C;
}
for (int i = 0; i < q; ++i) {
cin >> qs[i].a >> qs[i].b >> qs[i].c;
qs[i].a = lower_bound(A, A + n, qs[i].a) - A;
qs[i].b = lower_bound(B, B + n, qs[i].b) - B;
qs[i].c = lower_bound(C, C + n, qs[i].c) - C;
qs[i].id = i;
}
sort(qs, qs + q);
int pA = n, pB = n;
for (int i = 0; i < q; ++i) {
while (pA - 1 >= 0 && a[pA - 1].first >= qs[i].a) {
pA--;
++cnt[a[pA].second];
if (cnt[a[pA].second] == 2) {
upd(c[a[pA].second], 1);
}
}
while (pA < n && a[pA].first < qs[i].a) {
--cnt[a[pA].second];
if (cnt[a[pA].second] == 1) {
upd(c[a[pA].second], -1);
}
pA++;
}
while (pB - 1 >= 0 && b[pB - 1].first >= qs[i].b) {
pB--;
++cnt[b[pB].second];
if (cnt[b[pB].second] == 2) {
upd(c[b[pB].second], 1);
}
}
while (pB < n && b[pB].first < qs[i].b) {
--cnt[b[pB].second];
if (cnt[b[pB].second] == 1) {
upd(c[b[pB].second], -1);
}
pB++;
}
ans[qs[i].id] = qry(qs[i].c, n - 1);
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
608 KB |
Output is correct |
9 |
Correct |
13 ms |
828 KB |
Output is correct |
10 |
Correct |
10 ms |
664 KB |
Output is correct |
11 |
Correct |
8 ms |
660 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
10 ms |
596 KB |
Output is correct |
14 |
Correct |
10 ms |
608 KB |
Output is correct |
15 |
Correct |
10 ms |
688 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
9 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1687 ms |
9180 KB |
Output is correct |
2 |
Correct |
1686 ms |
9180 KB |
Output is correct |
3 |
Correct |
1674 ms |
9180 KB |
Output is correct |
4 |
Correct |
1105 ms |
8444 KB |
Output is correct |
5 |
Correct |
159 ms |
8560 KB |
Output is correct |
6 |
Correct |
112 ms |
7648 KB |
Output is correct |
7 |
Correct |
503 ms |
9088 KB |
Output is correct |
8 |
Correct |
548 ms |
9092 KB |
Output is correct |
9 |
Correct |
408 ms |
9184 KB |
Output is correct |
10 |
Correct |
113 ms |
8244 KB |
Output is correct |
11 |
Correct |
1182 ms |
8296 KB |
Output is correct |
12 |
Correct |
59 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1687 ms |
9180 KB |
Output is correct |
2 |
Correct |
1686 ms |
9180 KB |
Output is correct |
3 |
Correct |
1674 ms |
9180 KB |
Output is correct |
4 |
Correct |
1105 ms |
8444 KB |
Output is correct |
5 |
Correct |
159 ms |
8560 KB |
Output is correct |
6 |
Correct |
112 ms |
7648 KB |
Output is correct |
7 |
Correct |
503 ms |
9088 KB |
Output is correct |
8 |
Correct |
548 ms |
9092 KB |
Output is correct |
9 |
Correct |
408 ms |
9184 KB |
Output is correct |
10 |
Correct |
113 ms |
8244 KB |
Output is correct |
11 |
Correct |
1182 ms |
8296 KB |
Output is correct |
12 |
Correct |
59 ms |
7040 KB |
Output is correct |
13 |
Correct |
1727 ms |
9616 KB |
Output is correct |
14 |
Correct |
1703 ms |
9564 KB |
Output is correct |
15 |
Correct |
1668 ms |
9188 KB |
Output is correct |
16 |
Correct |
1139 ms |
8836 KB |
Output is correct |
17 |
Correct |
175 ms |
8816 KB |
Output is correct |
18 |
Correct |
116 ms |
7584 KB |
Output is correct |
19 |
Correct |
1693 ms |
9696 KB |
Output is correct |
20 |
Correct |
1717 ms |
9596 KB |
Output is correct |
21 |
Correct |
859 ms |
9608 KB |
Output is correct |
22 |
Correct |
110 ms |
8292 KB |
Output is correct |
23 |
Correct |
1110 ms |
8292 KB |
Output is correct |
24 |
Correct |
75 ms |
6988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
608 KB |
Output is correct |
9 |
Correct |
13 ms |
828 KB |
Output is correct |
10 |
Correct |
10 ms |
664 KB |
Output is correct |
11 |
Correct |
8 ms |
660 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
10 ms |
596 KB |
Output is correct |
14 |
Correct |
10 ms |
608 KB |
Output is correct |
15 |
Correct |
10 ms |
688 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
9 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
1687 ms |
9180 KB |
Output is correct |
20 |
Correct |
1686 ms |
9180 KB |
Output is correct |
21 |
Correct |
1674 ms |
9180 KB |
Output is correct |
22 |
Correct |
1105 ms |
8444 KB |
Output is correct |
23 |
Correct |
159 ms |
8560 KB |
Output is correct |
24 |
Correct |
112 ms |
7648 KB |
Output is correct |
25 |
Correct |
503 ms |
9088 KB |
Output is correct |
26 |
Correct |
548 ms |
9092 KB |
Output is correct |
27 |
Correct |
408 ms |
9184 KB |
Output is correct |
28 |
Correct |
113 ms |
8244 KB |
Output is correct |
29 |
Correct |
1182 ms |
8296 KB |
Output is correct |
30 |
Correct |
59 ms |
7040 KB |
Output is correct |
31 |
Correct |
1727 ms |
9616 KB |
Output is correct |
32 |
Correct |
1703 ms |
9564 KB |
Output is correct |
33 |
Correct |
1668 ms |
9188 KB |
Output is correct |
34 |
Correct |
1139 ms |
8836 KB |
Output is correct |
35 |
Correct |
175 ms |
8816 KB |
Output is correct |
36 |
Correct |
116 ms |
7584 KB |
Output is correct |
37 |
Correct |
1693 ms |
9696 KB |
Output is correct |
38 |
Correct |
1717 ms |
9596 KB |
Output is correct |
39 |
Correct |
859 ms |
9608 KB |
Output is correct |
40 |
Correct |
110 ms |
8292 KB |
Output is correct |
41 |
Correct |
1110 ms |
8292 KB |
Output is correct |
42 |
Correct |
75 ms |
6988 KB |
Output is correct |
43 |
Correct |
1703 ms |
11572 KB |
Output is correct |
44 |
Correct |
1708 ms |
11572 KB |
Output is correct |
45 |
Correct |
1722 ms |
11516 KB |
Output is correct |
46 |
Correct |
1170 ms |
9992 KB |
Output is correct |
47 |
Correct |
198 ms |
9956 KB |
Output is correct |
48 |
Correct |
115 ms |
7356 KB |
Output is correct |
49 |
Correct |
522 ms |
11424 KB |
Output is correct |
50 |
Correct |
572 ms |
11396 KB |
Output is correct |
51 |
Correct |
442 ms |
11324 KB |
Output is correct |
52 |
Correct |
131 ms |
9824 KB |
Output is correct |
53 |
Correct |
1144 ms |
9084 KB |
Output is correct |