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;
#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;
const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type, greater<pii>, rb_tree_tag,tree_order_statistics_node_update>
typedef array<int,5> arr;
int N,Q;
vector<arr> A;
ll ans[MAX];
void dnc(int l, int r) {
if (l==r) return;
int m=(l+r)>>1;
dnc(l,m), dnc(m+1,r);
vector<arr> le,ri;
for (int i=l; i<=m; i++) le.pb(A[i]);
for (int i=m+1; i<=r; i++) ri.pb(A[i]);
sort(all(le),[](auto a, auto b){
if (a[1]==b[1]) return a[3]<b[3];
return a[1]>b[1];
});
sort(all(ri),[](auto a, auto b){
if (a[1]==b[1]) return a[3]<b[3];
return a[1]>b[1];
});
ordered_set os;
int i=0;
for (auto [x,y,z,q,idx]:ri) {
while (i<sz(le) && le[i][1]>=y) {
if (le[i][3]==0) os.insert({le[i][2],idx});
i++;
}
if (q) {
ll t=os.order_of_key({z,INF});
ans[idx]+=t;
}
}
}
int main() {
fio();
cin>>N>>Q;
for (int i=0; i<N; i++) {
int s,t; cin>>s>>t;
A.pb({s,t,s+t,0,i});
}
for (int i=0; i<Q; i++) {
int x,y,z; cin>>x>>y>>z;
A.pb({x,y,z,1,i});
}
sort(all(A),[](auto a, auto b){
if (a[0]==b[0]) return a[3]<b[3];
return a[0]>b[0];
});
dnc(0,N+Q-1);
for (int i=0; i<Q; i++) cout<<ans[i]<<endl;
return 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... |