This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |