#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
struct T{
int data, sl, sr, tl, tr, next;
};
int N, Q, s[100000], t[100000], x, y, z;
vector<int>svec, tvec;
vector<T>tree;
void update(int k, int s, int t) {
if (tree[k].sl <= s&&s <= tree[k].sr&&tree[k].tl <= t&&t <= tree[k].tr) {
if (tree[k].sl == tree[k].sr&&tree[k].tl == tree[k].tr) {
++tree[k].data;
}
else {
if (tree[k].next == -1) {
tree[k].next = tree.size();
tree.push_back({ 0,tree[k].sl,(tree[k].sl + tree[k].sr) / 2,tree[k].tl,(tree[k].tl + tree[k].tr) / 2,-1 });
tree.push_back({ 0,tree[k].sl,(tree[k].sl + tree[k].sr) / 2,(tree[k].tl + tree[k].tr) / 2 + 1,tree[k].tr,-1 });
tree.push_back({ 0,(tree[k].sl + tree[k].sr) / 2 + 1,tree[k].sr,tree[k].tl,(tree[k].tl + tree[k].tr) / 2,-1 });
tree.push_back({ 0,(tree[k].sl + tree[k].sr) / 2 + 1,tree[k].sr,(tree[k].tl + tree[k].tr) / 2 + 1,tree[k].tr,-1 });
}
update(tree[k].next, s, t);
update(tree[k].next + 1, s, t);
update(tree[k].next + 2, s, t);
update(tree[k].next + 3, s, t);
tree[k].data = tree[tree[k].next].data + tree[tree[k].next + 1].data + tree[tree[k].next + 2].data + tree[tree[k].next + 3].data;
}
}
}
int calc(int k) {
if (tree[k].data == 0)return 0;
if (svec[tree[k].sr] < x || tvec[tree[k].tr] < y || svec[tree[k].sr] + tvec[tree[k].tr] < z)return 0;
if (x <= svec[tree[k].sl] && y <= tvec[tree[k].tl] && z <= svec[tree[k].sl] + tvec[tree[k].tl])return tree[k].data;
return calc(tree[k].next) + calc(tree[k].next + 1) + calc(tree[k].next + 2) + calc(tree[k].next + 3);
}
int main() {
scanf("%d%d", &N, &Q);
for (int i = 0; i < N; ++i) {
scanf("%d%d", &s[i], &t[i]);
svec.push_back(s[i]);
tvec.push_back(t[i]);
}
sort(svec.begin(), svec.end());
svec.erase(unique(svec.begin(), svec.end()), svec.end());
sort(tvec.begin(), tvec.end());
tvec.erase(unique(tvec.begin(), tvec.end()), tvec.end());
tree.push_back({ 0,0,(int)svec.size() - 1,0,(int)tvec.size() - 1,-1 });
for (int i = 0; i < N; ++i) {
update(0, lower_bound(svec.begin(), svec.end(), s[i]) - svec.begin(), lower_bound(tvec.begin(), tvec.end(), t[i]) - tvec.begin());
}
for (int i = 0; i < Q; ++i) {
scanf("%d%d%d", &x, &y, &z);
printf("%d\n", calc(0));
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:48: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:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &s[i], &t[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:63: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
29 ms |
3712 KB |
Output is correct |
8 |
Correct |
29 ms |
3712 KB |
Output is correct |
9 |
Correct |
37 ms |
3712 KB |
Output is correct |
10 |
Correct |
16 ms |
2180 KB |
Output is correct |
11 |
Correct |
19 ms |
2052 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
42 ms |
3712 KB |
Output is correct |
14 |
Correct |
35 ms |
3584 KB |
Output is correct |
15 |
Correct |
31 ms |
3584 KB |
Output is correct |
16 |
Correct |
10 ms |
972 KB |
Output is correct |
17 |
Correct |
10 ms |
972 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
100728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
100728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
29 ms |
3712 KB |
Output is correct |
8 |
Correct |
29 ms |
3712 KB |
Output is correct |
9 |
Correct |
37 ms |
3712 KB |
Output is correct |
10 |
Correct |
16 ms |
2180 KB |
Output is correct |
11 |
Correct |
19 ms |
2052 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
42 ms |
3712 KB |
Output is correct |
14 |
Correct |
35 ms |
3584 KB |
Output is correct |
15 |
Correct |
31 ms |
3584 KB |
Output is correct |
16 |
Correct |
10 ms |
972 KB |
Output is correct |
17 |
Correct |
10 ms |
972 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Execution timed out |
3032 ms |
100728 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |