이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 998244353;
const int N = 1e5 + 10;
const int Inf = 2000000100;
const ll Log = 30;
typedef pair<int, int> pii;
struct Segment {
int n = 0;
vector<pii> V;
vector<int> seg[N << 2];
void Add(pii X){
V.pb(X);
return ;
}
void Build(int id, int L, int R){
for(int i = L; i < R; i++) seg[id].pb(V[i].S);
sort(all(seg[id]));
if(L + 1 == R) return ;
int mid = (L + R) >> 1;
Build(id << 1, L, mid);
Build(id<<1|1, mid, R);
}
int Get(int id, int l, int r, int lw, int hg, int L, int R){
if(r <= L || R <= l) return 0;
if(l <= L && R <= r){
return lower_bound(all(seg[id]), hg + 1) - lower_bound(all(seg[id]), lw);
}
int mid = (L + R) >> 1;
return Get(id << 1, l, r, lw, hg, L, mid) + Get(id << 1 | 1, l, r, lw, hg, mid, R);
}
int GetRect(int lx, int rx, int ly, int ry){ // [], []
// lx = lower_bound(all(V), pii(lx, -Inf)) - V.begin();
// rx = lower_bound(all(V), pii(rx, Inf)) - V.begin();
int sm = 0;
for(auto [x, y] : V)
if(lx <= x && x <= rx && ly <= y && y <= ry) sm ++;
return sm;
return Get(1, lx, rx, ly, ry, 0, n);
}
void init(){
n = V.size();
sort(all(V));
Build(1, 0, n);
}
};
Segment SX, SY, XY;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
int x, y;
vector<int> U;
for(int i = 0; i < n; i++){
cin >> x >> y;
SX.Add({x + y, x});
SY.Add({x + y, y});
XY.Add({x, y});
U.pb(x + y);
}
sort(all(U));
SX.init();
SY.init();
XY.init();
int a, b, c;
for(int i = 0; i < q; i++){
cin >> a >> b >> c;
if(a + b >= c){
cout << XY.GetRect(a, Inf, b, Inf) << '\n';
continue;
}
int und = lower_bound(all(U), c) - U.begin();
int lf = SX.GetRect(c, Inf, 0, a - 1);
int rt = SY.GetRect(c, Inf, 0, b - 1);
cout << n - und - lf - rt << '\n';
}
return 0;
}
/*
5 1
1 2
2 3
3 4
1 5
*/
# | 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... |