#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn = 2e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, q, a[maxn], b[maxn];
int t[maxn * 4];
int upos;
void update(int i, int l, int r)
{
if(l == r)
{
t[i] ++;
return;
}
int mid = (l + r)/2;
if(upos <= mid)update(2*i, l, mid);
else update(2*i+1, mid+1, r);
t[i] = (t[2*i] + t[2*i+1]);
}
int ql, qr;
int query(int i, int l, int r)
{
if(qr < l || ql > r)return 0;
if(ql <= l && r <= qr)return t[i];
int mid = (l + r)/2;
return (query(2*i, l, mid) + query(2*i+1, mid+1, r));
}
struct que
{
int qa, qb, qc, i;
que(){};
que(int _qa, int _qb, int _qc, int _i)
{
qa = _qa;
qb = _qb;
qc = _qc;
i = _i;
}
};
int ans[maxn];
bool cmp(que q1, que q2)
{
if(q1.qa != q2.qa)return (q1.qa < q2.qa);
else return (q1.qb < q2.qb);
}
int main()
{
speed();
cin >> n >> q;
int maxn = 2e5;
vector < pair < int, int > > g;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i] >> b[i];
g.pb(make_pair(a[i], b[i]));
}
sort(g.begin(), g.end());
reverse(g.begin(), g.end());
vector < que > qq;
int qa, qb, qc;
for (int i = 1; i <= q; ++ i)
{
cin >> qa >> qb >> qc;
qq.pb(que(qa, qb, qc, i));
}
sort(qq.begin(), qq.end(), cmp);
reverse(qq.begin(), qq.end());
int j = -1;
for (auto &[qa, qb, qc, qpos]: qq)
{
while(j+1 < g.size() && g[j+1].first >= qa)
{
upos = g[j+1].second;
update(1, 0, maxn);
j ++;
}
ql = qb;
qr = maxn;
ans[qpos] = query(1, 0, maxn);
}
for (int i = 1; i <= q; ++ i)
cout << ans[i] << endl;
return 0;
}
/**
5 6
1 2
3 4
5 3
2 10
1 11
1 1 0
2 2 0
4 4 0
4 3 0
0 0 0
0 0 0
*/
| # | 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... |