#include <iostream>
#include <algorithm>
#include <vector>
#define pii pair<int, int>
#define fst first
#define snd second
#define pip pair<int, pii>
#define ppp pair<pii, pii>
using namespace std;
const int INF = 1e9;
struct DS
{
vector<int> C, A;
DS() {C.push_back(-1);}
void addPoint(int x) {C.push_back(x);}
void prepDS()
{
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
A.resize(C.size());
}
void update(int x, int v)
{
auto it = prev(upper_bound(C.begin(), C.end(), x)) - C.begin();
for (; it < A.size(); it += it & (-it)) {A[it] += v;}
}
int query(int x)
{
auto it = prev(upper_bound(C.begin(), C.end(), x)) - C.begin(); int ret = 0;
for (; it; it -= it & (-it)) {ret += A[it];}
return ret;
}
};
namespace DS2
{
vector<int> C;
DS A[100001];
void addPoint(int x) {C.push_back(x);}
void prepDS()
{
C.push_back(-1);
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
}
void addPoint2(int x, int y)
{
auto it = prev(upper_bound(C.begin(), C.end(), x)) - C.begin();
for (; it < C.size(); it += it & (-it)) {A[it].addPoint(y);}
}
void prepDS2()
{
for (int i = 0; i < C.size(); i++) {A[i].prepDS();}
}
void update(int x, int y, int v)
{
auto it = prev(upper_bound(C.begin(), C.end(), x)) - C.begin();
for (; it < C.size(); it += it & (-it)) {A[it].update(y, v);}
}
int query(int x, int y)
{
auto it = prev(upper_bound(C.begin(), C.end(), x)) - C.begin(); int ret = 0;
for (; it; it -= it & (-it)) {ret += A[it].query(y);}
return ret;
}
}
int N, Q;
pip A[100001];
ppp B[100001];
int ans[100001];
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> Q;
DS2 :: addPoint(-1);
for (int i = 0; i < N; i++)
{
cin >> A[i].snd.fst >> A[i].snd.snd;
A[i].fst = -(A[i].snd.fst + A[i].snd.snd);
DS2 :: addPoint(A[i].snd.fst);
}
DS2 :: prepDS();
for (int i = 0; i < N; i++)
{
DS2 :: addPoint2(A[i].snd.fst, A[i].snd.snd);
}
DS2 :: prepDS2();
sort(A, A + N);
for (int i = 0; i < Q; i++)
{
cin >> B[i].snd.fst >> B[i].snd.snd >> B[i].fst.fst;
B[i].fst.snd = i;
B[i].fst.fst = -B[i].fst.fst;
}
sort(B, B + Q);
int j = 0;
for (int i = 0; i < Q; i++)
{
for (; j < N && A[j].fst <= B[i].fst.fst; j++)
{
DS2 :: update(A[j].snd.fst, A[j].snd.snd, 1);
}
ans[B[i].fst.snd] += DS2 :: query(INF, INF);
ans[B[i].fst.snd] -= DS2 :: query(B[i].snd.fst - 1, INF);
ans[B[i].fst.snd] -= DS2 :: query(INF, B[i].snd.snd - 1);
ans[B[i].fst.snd] += DS2 :: query(B[i].snd.fst - 1, B[i].snd.snd - 1);
}
for (int i = 0; i < Q; i++)
{
cout << ans[i] << "\n";
}
return 0;
}
Compilation message
examination.cpp: In member function 'void DS::update(int, int)':
examination.cpp:27:13: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (; it < A.size(); it += it & (-it)) {A[it] += v;}
| ~~~^~~~~~~~~~
examination.cpp: In function 'void DS2::addPoint2(int, int)':
examination.cpp:51:13: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (; it < C.size(); it += it & (-it)) {A[it].addPoint(y);}
| ~~~^~~~~~~~~~
examination.cpp: In function 'void DS2::prepDS2()':
examination.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < C.size(); i++) {A[i].prepDS();}
| ~~^~~~~~~~~~
examination.cpp: In function 'void DS2::update(int, int, int)':
examination.cpp:60:13: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (; it < C.size(); it += it & (-it)) {A[it].update(y, v);}
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
10 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8192 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
20 ms |
8652 KB |
Output is correct |
8 |
Correct |
19 ms |
8704 KB |
Output is correct |
9 |
Correct |
20 ms |
8704 KB |
Output is correct |
10 |
Correct |
16 ms |
8576 KB |
Output is correct |
11 |
Correct |
17 ms |
8448 KB |
Output is correct |
12 |
Correct |
13 ms |
8448 KB |
Output is correct |
13 |
Correct |
20 ms |
8680 KB |
Output is correct |
14 |
Correct |
19 ms |
8700 KB |
Output is correct |
15 |
Correct |
20 ms |
8704 KB |
Output is correct |
16 |
Correct |
14 ms |
8448 KB |
Output is correct |
17 |
Correct |
14 ms |
8648 KB |
Output is correct |
18 |
Correct |
12 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
633 ms |
22600 KB |
Output is correct |
2 |
Correct |
626 ms |
22240 KB |
Output is correct |
3 |
Correct |
661 ms |
22256 KB |
Output is correct |
4 |
Correct |
304 ms |
19604 KB |
Output is correct |
5 |
Correct |
206 ms |
15912 KB |
Output is correct |
6 |
Correct |
108 ms |
14828 KB |
Output is correct |
7 |
Correct |
535 ms |
22240 KB |
Output is correct |
8 |
Correct |
604 ms |
22332 KB |
Output is correct |
9 |
Correct |
516 ms |
22408 KB |
Output is correct |
10 |
Correct |
115 ms |
14448 KB |
Output is correct |
11 |
Correct |
238 ms |
19184 KB |
Output is correct |
12 |
Correct |
68 ms |
13424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
633 ms |
22600 KB |
Output is correct |
2 |
Correct |
626 ms |
22240 KB |
Output is correct |
3 |
Correct |
661 ms |
22256 KB |
Output is correct |
4 |
Correct |
304 ms |
19604 KB |
Output is correct |
5 |
Correct |
206 ms |
15912 KB |
Output is correct |
6 |
Correct |
108 ms |
14828 KB |
Output is correct |
7 |
Correct |
535 ms |
22240 KB |
Output is correct |
8 |
Correct |
604 ms |
22332 KB |
Output is correct |
9 |
Correct |
516 ms |
22408 KB |
Output is correct |
10 |
Correct |
115 ms |
14448 KB |
Output is correct |
11 |
Correct |
238 ms |
19184 KB |
Output is correct |
12 |
Correct |
68 ms |
13424 KB |
Output is correct |
13 |
Correct |
679 ms |
22256 KB |
Output is correct |
14 |
Correct |
649 ms |
23020 KB |
Output is correct |
15 |
Correct |
643 ms |
22760 KB |
Output is correct |
16 |
Correct |
328 ms |
20080 KB |
Output is correct |
17 |
Correct |
214 ms |
16368 KB |
Output is correct |
18 |
Correct |
106 ms |
14836 KB |
Output is correct |
19 |
Correct |
671 ms |
23152 KB |
Output is correct |
20 |
Correct |
653 ms |
23024 KB |
Output is correct |
21 |
Correct |
616 ms |
23024 KB |
Output is correct |
22 |
Correct |
115 ms |
14572 KB |
Output is correct |
23 |
Correct |
238 ms |
19184 KB |
Output is correct |
24 |
Correct |
81 ms |
13424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
10 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8192 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
20 ms |
8652 KB |
Output is correct |
8 |
Correct |
19 ms |
8704 KB |
Output is correct |
9 |
Correct |
20 ms |
8704 KB |
Output is correct |
10 |
Correct |
16 ms |
8576 KB |
Output is correct |
11 |
Correct |
17 ms |
8448 KB |
Output is correct |
12 |
Correct |
13 ms |
8448 KB |
Output is correct |
13 |
Correct |
20 ms |
8680 KB |
Output is correct |
14 |
Correct |
19 ms |
8700 KB |
Output is correct |
15 |
Correct |
20 ms |
8704 KB |
Output is correct |
16 |
Correct |
14 ms |
8448 KB |
Output is correct |
17 |
Correct |
14 ms |
8648 KB |
Output is correct |
18 |
Correct |
12 ms |
8320 KB |
Output is correct |
19 |
Correct |
633 ms |
22600 KB |
Output is correct |
20 |
Correct |
626 ms |
22240 KB |
Output is correct |
21 |
Correct |
661 ms |
22256 KB |
Output is correct |
22 |
Correct |
304 ms |
19604 KB |
Output is correct |
23 |
Correct |
206 ms |
15912 KB |
Output is correct |
24 |
Correct |
108 ms |
14828 KB |
Output is correct |
25 |
Correct |
535 ms |
22240 KB |
Output is correct |
26 |
Correct |
604 ms |
22332 KB |
Output is correct |
27 |
Correct |
516 ms |
22408 KB |
Output is correct |
28 |
Correct |
115 ms |
14448 KB |
Output is correct |
29 |
Correct |
238 ms |
19184 KB |
Output is correct |
30 |
Correct |
68 ms |
13424 KB |
Output is correct |
31 |
Correct |
679 ms |
22256 KB |
Output is correct |
32 |
Correct |
649 ms |
23020 KB |
Output is correct |
33 |
Correct |
643 ms |
22760 KB |
Output is correct |
34 |
Correct |
328 ms |
20080 KB |
Output is correct |
35 |
Correct |
214 ms |
16368 KB |
Output is correct |
36 |
Correct |
106 ms |
14836 KB |
Output is correct |
37 |
Correct |
671 ms |
23152 KB |
Output is correct |
38 |
Correct |
653 ms |
23024 KB |
Output is correct |
39 |
Correct |
616 ms |
23024 KB |
Output is correct |
40 |
Correct |
115 ms |
14572 KB |
Output is correct |
41 |
Correct |
238 ms |
19184 KB |
Output is correct |
42 |
Correct |
81 ms |
13424 KB |
Output is correct |
43 |
Correct |
717 ms |
27068 KB |
Output is correct |
44 |
Correct |
719 ms |
26864 KB |
Output is correct |
45 |
Correct |
700 ms |
26992 KB |
Output is correct |
46 |
Correct |
360 ms |
23920 KB |
Output is correct |
47 |
Correct |
223 ms |
17524 KB |
Output is correct |
48 |
Correct |
106 ms |
14576 KB |
Output is correct |
49 |
Correct |
596 ms |
27120 KB |
Output is correct |
50 |
Correct |
674 ms |
26908 KB |
Output is correct |
51 |
Correct |
558 ms |
26992 KB |
Output is correct |
52 |
Correct |
134 ms |
16364 KB |
Output is correct |
53 |
Correct |
288 ms |
22764 KB |
Output is correct |