이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
struct ev {
int a,b,c;
int is_q;
int id;
};
int ans[100001];
void dc2(vector<ev>& t, int L, int R) {
if(L>=R) return ;
int mid=(L+R)/2;
vector<int> lst;
for(int i=mid+1;i<=R;++i) {
if(!t[i].is_q) lst.pb(t[i].c);
}
sort(lst.begin(),lst.end());
for(int i=L;i<=mid;++i) {
if(t[i].is_q) {
auto it=lower_bound(lst.begin(), lst.end(), t[i].c);
ans[t[i].id]+=lst.end()-it;
}
}
dc2(t, L, mid);
dc2(t, mid+1, R);
}
void dc1(vector<ev>& t, int L, int R) {
if(L>=R) return ;
int mid=(L+R)/2;
vector<ev> arr;
for(int i=L;i<=mid;++i) {
if(t[i].is_q) arr.pb(t[i]);
}
for(int i=mid+1;i<=R;++i) {
if(!t[i].is_q) arr.pb(t[i]);
}
sort(arr.begin(),arr.end(), [&](ev a, ev b) -> bool {
if(a.b==b.b) return a.is_q>b.is_q;
return a.b<b.b;
});
dc2(arr, 0, (int)arr.size()-1);
dc1(t, L, mid);
dc1(t, mid+1, R);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,q;
cin>>n>>q;
vector<ev> lst;
for(int i=0;i<n;++i) {
int a,b;
cin>>a>>b;
lst.push_back({a,b,a+b,0,-1});
}
for(int i=0;i<q;++i) {
int a,b,c;
cin>>a>>b>>c;
lst.push_back({a,b,c,1,i});
}
sort(lst.begin(), lst.end(), [&](ev a, ev b) -> bool {
if(a.a==b.a) return a.is_q>b.is_q;
return a.a<b.a;
});
dc1(lst, 0, (int)lst.size()-1);
for(int i=0;i<q;++i) cout<<ans[i]<<"\n";
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... |