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>
using namespace std;
pair<pair<long long, long long>, pair<long long, long long> > b[100005];
pair<long long, pair<long long, long long> > a[100005];
map<pair<long long, long long>, long long> mp;
long long ans[100005];
void upd(long long x, long long y)
{
for (long long i=x; i<=(1<<30); i+=i&(-i))
for (long long j=y; j<=(1<<30); j+=j&(-j))
mp[{i, j}]++;
}
long long qry(long long x, long long y)
{
long long res=0;
for (long long i=x; i; i-=i&(-i))
for (long long j=y; j; j-=j&(-j))
res+=mp[{i, j}];
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, ind;
cin >> n >> m;
for (long long i=1; i<=n; i++)
{
long long x, y;
cin >> x >> y;
a[i]={x+y+2, {x+1, y+1}};
}
for (long long i=1; i<=m; i++)
{
long long x, y, z;
cin >> x >> y >> z;
b[i]={{z+2, i}, {x+1, y+1}};
}
sort(a+1, a+n+1);
sort(b+1, b+m+1);
ind=n;
for (long long i=m; i>=1; i--)
{
while (ind && a[ind].first>=b[i].first.first)
{
upd(a[ind].second.first, a[ind].second.second);
ind--;
}
ans[b[i].first.second]=qry(1<<30, 1<<30)-qry(1<<30, b[i].second.second-1)-qry(b[i].second.first-1, 1<<30)+qry(b[i].second.first-1, b[i].second.second-1);
}
for (long long i=1; i<=m; i++)
cout << ans[i] << '\n';
}
# | 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... |