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>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
const int inf = 2e9 + 5;
struct OS{
vector<int> a;
void add(int x){
a.pb(x);
}
int get(int x){
int out = 0;
for (int i: a) out += (i < x);
return out;
}
void clear(){
a.clear();
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
struct data{
int x, y, z, i;
};
auto cmp = [&](data& a, data& b){
return a.x < b.x;
};
int n, q; cin>>n>>q;
vector<pii> t(n + 1);
for (int i = 1; i <= n; i++){
cin>>t[i].ff>>t[i].ss;
}
sort(t.begin() + 1, t.end());
vector<data> qs(q + 1);
for (int i = 1; i <= q; i++){
cin>>qs[i].x>>qs[i].y>>qs[i].z;
qs[i].i = i;
}
sort(qs.begin() + 1, qs.end(), cmp);
vector<data> all = {{}};
int j = n, cur = 1;
for (int i = q; i > 0; i--){
while (j > 0 && t[j].ff >= qs[i].x){
all.pb({cur++, t[j].ss, t[j].ff + t[j].ss, 0});
// cout<<t[j].ss<<" "<<t[j].ff + t[j].ss<<"\n";
j--;
}
// cout<<qs[i].y<<" "<<qs[i].z<<"\n";
all.pb({cur, inf, inf, qs[i].i});
all.pb({cur, qs[i].y, inf, -qs[i].i});
all.pb({cur, inf, qs[i].z, -qs[i].i});
all.pb({cur++, qs[i].y, qs[i].z, qs[i].i});
}
sort(all.begin() + 1, all.end(), cmp);
vector<int> out(q + 1), cnt(all.size());
OS T;
function<void(int, int)> solve = [&](int l, int r){
if (l == r) return;
int m = (l + r) / 2;
solve(l, m);
solve(m + 1, r);
vector<data> arr;
for (int i = l; i <= m; i++){
if (all[i].i == 0) arr.pb({all[i].y, all[i].z, 0, 0});
}
for (int i = m + 1; i <= r; i++){
if (all[i].i != 0) arr.pb({all[i].y, all[i].z, 0, i});
}
sort(arr.begin(), arr.end(), cmp);
int i = 0, j = 0;
while (i < arr.size()){
while (j < arr.size() && arr[j].x < arr[i].x){
if (arr[j].i == 0) T.add(arr[j].y);
j++;
}
if (arr[i].i) cnt[arr[i].i] += T.get(arr[i].y);
i++;
}
T.clear();
};
solve(1, (int) all.size() - 1);
for (int i = 1; i < all.size(); i++){
if (all[i].i == 0) continue;
out[abs(all[i].i)] += (2 * (all[i].i > 0) - 1) * cnt[i];
}
for (int i = 1; i <= q; i++){
cout<<out[i]<<"\n";
}
}
Compilation message (stderr)
examination.cpp: In lambda function:
examination.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | while (i < arr.size()){
| ~~^~~~~~~~~~~~
examination.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | while (j < arr.size() && arr[j].x < arr[i].x){
| ~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 1; i < all.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |