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<bits/stdc++.h>
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
using namespace std;
const int maxn = 1e5;
int N, Q, S[maxn], T[maxn], x, A[maxn], B[maxn], C[maxn], Ans[maxn];
vector <int> vs, vt[maxn + 1], ft[maxn + 1];
array<int, 2> D[maxn], E[maxn];
int main() {
// freopen("cc.inp", "r", stdin);
// freopen("cc.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
for (int i = 0; i < N; ++i) {
cin >> S[i] >> T[i];
S[i] = -S[i]; T[i] = -T[i];
vs.push_back(S[i]);
D[i] = {S[i] + T[i], i};
}
sort(vs.begin(), vs.end());
vs.resize(x = unique(vs.begin(), vs.end()) - vs.begin());
for (int i = 0; i < N; ++i) {
S[i] = lower_bound(vs.begin(), vs.end(), S[i]) - vs.begin();
for (int j = S[i] + 1; j <= x; j += j & -j)
vt[j].push_back(T[i]);
}
for (int i = 1; i <= x; ++i) {
sort(vt[i].begin(), vt[i].end());
vt[i].resize(unique(vt[i].begin(), vt[i].end()) - vt[i].begin());
ft[i].resize(vt[i].size() + 1);
}
sort(D, D + N);
for (int i = 0; i < Q; ++i) {
cin >> A[i] >> B[i] >> C[i];
A[i] = -A[i];
B[i] = -B[i];
C[i] = -C[i];
E[i] = {C[i], i};
}
sort(E, E + Q);
for (int i1 = 0, i2 = 0; i1 < Q; ++i1) {
while (i2 < N && D[i2][0] <= E[i1][0]) {
for (int i = S[D[i2][1]] + 1; i <= x; i += i & -i)
for (int j = lower_bound(vt[i].begin(), vt[i].end(), T[D[i2][1]]) - vt[i].begin() + 1; j <= vt[i].size(); j += j & -j)
ft[i][j]++;
++i2;
}
for (int i = upper_bound(vs.begin(), vs.end(), A[E[i1][1]]) - vs.begin(); i; i -= i & -i) {
for (int j = upper_bound(vt[i].begin(), vt[i].end(), B[E[i1][1]]) - vt[i].begin(); j; j -= j & -j)
Ans[E[i1][1]] += ft[i][j];
}
}
for (int i = 0; i < Q; ++i)
cout << Ans[i] << '\n';
}
Compilation message (stderr)
examination.cpp: In function 'int main()':
examination.cpp:47:98: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j = lower_bound(vt[i].begin(), vt[i].end(), T[D[i2][1]]) - vt[i].begin() + 1; j <= vt[i].size(); j += j & -j)
| ~~^~~~~~~~~~~~~~~
# | 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... |