This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'
int n , q;
vector<arr(3)> a;
vector<int> seg[3][2400001] , cmp;
vector<arr(4)> ops;
int seginf[2400001][2] , is[600000];
void cmpInt(){
sort(cmp.bg() , cmp.end());
cmp.resize(int(unique(cmp.bg() , cmp.end()) - cmp.bg()));
for(auto &el : a){
el[0] = int(lb(cmp.bg() , cmp.end() , el[0]) - cmp.bg());
el[1] = int(lb(cmp.bg() , cmp.end() , el[1]) - cmp.bg());
el[2] = int(lb(cmp.bg() , cmp.end() , el[2]) - cmp.bg());
}
for(auto &op : ops){
op[0] = int(lb(cmp.bg() , cmp.end() , op[0]) - cmp.bg());
op[1] = int(lb(cmp.bg() , cmp.end() , op[1]) - cmp.bg());
op[2] = int(lb(cmp.bg() , cmp.end() , op[2]) - cmp.bg());
}
}
void buildSeg(int l = 0 , int r = int(6e5) - 1 , int i = 1){
seginf[i][0] = l , seginf[i][1] = r;
if(l == r) is[l] = i;
else{
int c = (r + l - 1) >> 1;
buildSeg(l , c , i << 1) , buildSeg(c + 1 , r , (i << 1) | 1);
}
}
void addSeg(int md , int i , int val){
while(i >= 1) seg[md][i].pb(val) , i >>= 1;
}
void drawSeg(){
for(int j = 0 ; j < 3 ; j++) for(int i = 1 ; i < int(2400001) ; i++) sort(seg[j][i].bg() , seg[j][i].end());
}
int getSeg(int l , int r , int md , int i , int x , int y){
if(seginf[i][0] >= l and seginf[i][1] <= r){
if(md == 0){
return int(seg[0][i].size()) - int(lb(seg[0][i].bg() , seg[0][i].end() , x) - seg[0][i].bg());
}
int res = int(seg[1][i].size());
res -= int(ub(seg[1][i].bg() , seg[1][i].end() , x) - seg[1][i].bg());
res -= int(ub(seg[2][i].bg() , seg[2][i].end() , y) - seg[2][i].bg());
return res;
}
if(seginf[i][1] >= l and seginf[i][0] <= r){
return getSeg(l , r , md , i << 1 , x , y) + getSeg(l , r , md , (i << 1) | 1 , x , y);
}
return 0;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for(int i = 0 ; i < n ; i++){
arr(2) d;
cin >> d[0] >> d[1];
a.pb({d[0] , d[1] , d[0] + d[1]}) , cmp.pb(d[0]) , cmp.pb(d[1]) , cmp.pb(d[0] + d[1]);
}
for(int i = 0 ; i < q ; i++){
int x , y , z;
cin >> x >> y >> z;
ops.pb({x , y , z , int(z <= x + y)}) , cmp.pb(x) , cmp.pb(y) , cmp.pb(z);
}
cmpInt() , buildSeg();
for(int i = 0 ; i < n ; i++){
addSeg(0 , is[a[i][0]] , a[i][1]);
addSeg(1 , is[a[i][2]] , a[i][0]) , addSeg(2 , is[a[i][2]] , a[i][1]);
}
drawSeg();
for(int i = 0 ; i < q ; i++){
if(ops[i][3]) cout << getSeg(ops[i][0] , 600000 - 1 , 0 , 1 , ops[i][1] , -1) << endl;
else cout << getSeg(ops[i][2] , 600000 - 1 , 1 , 1 , ops[i][0] , ops[i][1]) << endl;
}
}
# | 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... |