Menu

Nested Ranges Count | CSES - Algoritmit ongelmanratkaisussa
📰

Nested Ranges Count | CSES - Algoritmit ongelmanratkaisussa

DEV Community: cpp·Guhan M·6 days ago
#dCnDr0pS
#devtocpp#devto#dev#include#tree
Long article (646 words) — no AI summary yet.
Reading 0:00
15s threshold

Problem: https://cses.fi/alon/task/2169

#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <set> #include <tuple>

using namespace std ;

typedef struct SegmentTree { int n ; vector < int > tree ;

SegmentTree ( int n ) { this -> n = n ; tree . assign ( 2 * ( n + 1 ) , 0 ) ; }

void increment ( int k , long long x ) { k += n ; tree [ k ] += x ; for ( k /= 2 ; k >= 1 ; k /= 2 ) { tree [ k ] = tree [ 2 * k ] + tree [ 2 * k + 1 ] ; } }

long long query ( int a , int b ) { a += n ; b += n ; long long sum = 0 ; while ( a <= b ) { if ( a % 2 == 1 ) sum += tree [ a ++ ] ; if ( b % 2 == 0 ) sum += tree [ b -- ] ; a /= 2 ; b /= 2 ; } return sum ; }

} SegmentTree ;

int main ( ) { int n ; cin >> n ;

vector < tuple < long long , long long , int >> arr ; set < long long > uniquePoints ; unordered_map < long long , int > pointId ;

for ( int i = 0 ; i < n ; i ++ ) { long long x , y ; cin >> x >> y ; arr . push_back ( { x , y , i } ) ; uniquePoints .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.