Skip to content

Commit

Permalink
Adding CSES solution
Browse files Browse the repository at this point in the history
  • Loading branch information
AK-I-RA committed Feb 4, 2021
1 parent a9723b2 commit 13508a4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CSES/Nested Ranges Count.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define ar array
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;

signed main(){
int n ; cin >> n ;
oset<ar<int,2>>b,c;
vector<ar<int,3>>a(n) ;
vector<int>A(n),B(n) ;
for(int i=0;i<n;i++)
cin >> a[i][0] >> a[i][1],a[i][2]=i ;

sort(a.begin(),a.end(),[&](const ar<int,3> i,const ar<int,3>j){
return ((i[0]<j[0])||(i[0]==j[0]&&i[1]>j[1])) ;
}) ;

for(int i=0,j=n-1;i<n;i++,j--){
A[a[i][2]]=i-b.order_of_key({a[i][1],-1}) ;
B[a[j][2]]=c.order_of_key({a[j][1]+1,-1}) ;
b.insert({a[i][1],i}) ;c.insert({a[j][1],i}) ;
}
for(int i=0;i<n;i++){
cout << B[i] <<' ' ;
}
cout << '\n' ;

for(int i=0;i<n;i++){
cout << A[i]<< ' ' ;
}
}

0 comments on commit 13508a4

Please sign in to comment.