#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>
using namespace std;
bool START_ALLOC;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
const int MAX = 5e5 + 15;
//vector, set, bit
struct BIT{
int n;
vector<int> bit;
BIT(int n) : n(n), bit(n + 15, 0) {}
void update(int idx, int v){
for(;idx <= n; idx += idx & -idx) bit[idx] += v;
}
int query(int idx){
int res = 0;
for(;idx; idx -= idx & -idx) res += bit[idx];
return res;
}
int query(int l, int r){
if(l > r) return 0;
return query(r) - query(l-1);
}
};
struct node{
int x, y, id;
node() : x(0), y(0), id(0) {}
node(int x, int y, int id) : x(x), y(y), id(id) {}
bool operator < (const node& a) const{
return x == a.x ? y > a.y : x < a.x;
}
};
int n, q, m;
node a[MAX];
vector<int> vec;
node qu[MAX];
void update(int x){
int pos = upper_bound(all(vec), x) - vec.begin();
if(pos == sz(vec)) vec.push_back(x);
else vec[pos] = x;
}
int query(int x){
int l = 0, r = sz(vec)-1, res = -1;
while(l <= r){
int mid = (l+r) >> 1;
if(vec[mid] <= x){
res = mid;
l = mid+1;
}
else{
r = mid-1;
}
}
return res + 1;
}
int ans[MAX];
void solve(){
cin >> n >> q;
for(int i = 1; i <= n; i++){
int x, y; cin >> x >> y;
a[i] = node(x, y, -1);
}
for(int i = 1; i <= q; i++){
int x, y; cin >> x >> y;
qu[i] = node(x, y, i);
}
sort(a + 1, a + 1 + n);
sort(qu + 1, qu + 1 + q);
for(int i = q, j = n; i >= 1; i--){
while(j > 0 && a[j].x >= qu[i].x){
update(a[j].y);
j--;
}
ans[qu[i].id] = query(qu[i].y);
}
for(int i = 1; i <= q; i++) cout << ans[i] << endl;
}
bool END_ALLOC;
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
cerr << "[Static Memory : " << fixed << setprecision(2) << (((&END_ALLOC) - (&START_ALLOC)) / (1024.0 * 1024.0)) << "mb]\n";
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message (stderr)
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
126 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |