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 ll long long
using namespace std;
const int MAX = 1e5;
int bit[MAX + 1];
void update(int pos, int val){
for(int i = pos; i <= MAX; i = i | (i + 1)){
bit[i] += val;
}
}
int ask(int pos){
int res = 0;
for(int i = pos; i >= 0; i = (i & (i + 1)) - 1){
res += bit[i];
}
return res;
}
int ask(int l, int r){
if(l == 0) return ask(r);
return ask(r) - ask(l - 1);
}
struct query{
int x, y, idx;
bool operator<(query other){
return x < other.x;
}
};
int n, m;
void solve2(){
vector<pair<int, int>> p;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
p.push_back({x, y});
}
sort(p.begin(), p.end());
vector<query> queries;
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
queries.push_back({x, y, i});
}
sort(queries.begin(), queries.end());
int ans[m];
int idx = n - 1;
for (int i = m - 1; i >= 0; i--)
{
while(idx >= 0 && queries[i].x <= p[idx].first){
update(p[idx].second, 1);
idx--;
}
ans[queries[i].idx] = ask(queries[i].y, MAX);
}
for (int i = 0; i < m; i++) cout<<ans[i]<<endl;
}
void solve1(){
vector<pair<int, int>> p;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
p.push_back({x, y});
}
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
int cnt = 0;
for(int i = 0; i < n; i++){
if(p[i].first >= x && p[i].second >= y && p[i].first + p[i].second >= z) cnt++;
}
cout<<cnt<<endl;
}
}
int main(){
cin>>n>>m;
if(n <= 3000 && m <= 3000) solve1();
else solve2();
}
# | 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... |