Sponsors

Codeforces Round #415 (Div. 1), problem: (D) Hitchhiking in the Baltic States Solution In C/C++

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define nMax 300010
#define INF 2000000100
using namespace std;
int n;
struct Node
{
int v,siz,add;
Node *son[2];
Node(){v=INF; siz=1; son[0]=son[1]=NULL; add=0;}
void update()
{
siz=1;
if(son[0]!=NULL) siz+=son[0]->siz;
if(son[1]!=NULL) siz+=son[1]->siz;
}
void add_add(int a)
{
add+=a; v+=a;
}
void push_down()
{
if(son[0]!=NULL) son[0]->add_add(add);
if(son[1]!=NULL) son[1]->add_add(add);
add=0;
}
}*ll[20];
Node *merge(Node *a,Node *b)
{
if(a==NULL) return b;
if(b==NULL) return a;
if((rand()%2))
{
a->push_down();
a->son[1]=merge(a->son[1],b);
a->update();
return a;
} else
{
b->push_down();
b->son[0]=merge(a,b->son[0]);
b->update();
return b;
}
}
void split(Node *r,int k,Node *&L,Node *&R)
{
if(k==0) {L=NULL; R=r; return;}
if(k==r->siz) {L=r; R=NULL; return;}
r->push_down();
int lsiz=0;
if(r->son[0]!=NULL) lsiz=r->son[0]->siz;
if(lsiz>=k)
{
split(r->son[0],k,L,R); r->son[0]=NULL; r->update();
R=merge(R,r);
} else
{
split(r->son[1],k-lsiz-1,L,R); r->son[1]=NULL; r->update();
L=merge(r,L);
}
}
Node *root;
int find(Node *r,int k)
{
if(r==NULL) return 0;
r->push_down();
if(r->v>k) return find(r->son[0],k);
int cnt=1;
if(r->son[0]!=NULL) cnt+=r->son[0]->siz;
return cnt+find(r->son[1],k);
}
Node *l1,*l2,*l3,*l4;
int main()
{
scanf(“%d”,&n);
root=new Node;
root->v=0;
for(int i=1;i<=n;i++) root=merge(root,new Node());
for(int i=1;i<=n;i++)
{
int a,b;
scanf(“%d%d”,&a,&b);
int la=find(root,b-1);
split(root,la+1,l1,l4); split(l1,l1->siz-1,l1,l2);
la=find(l1,a-1);
split(l1,la,l1,l3);
l2->v=a;
if(l3!=NULL) l3->add_add(1);
root=merge(merge(l1,l2),merge(l3,l4));
}
printf(“%d\n”,find(root,2000000000)-1);
return 0;
}

One to watch: Macquarie...

Macquarie Predicts Double-Digit Returns for ASX Healthcare Stock Macquarie Group,...

THE FREEPER CANTEEN –...

The Freeper Canteen: A Look That Up, It Must...

215% PENGU Rally Incoming?...

215% PENGU Rally Incoming? Analyst Predicts Imminent Breakout The cryptocurrency...

Junk is the new...

Junk is the New Punk: Why We're Falling Back...

Are weighted vests good...

Unlocking the Power of AI-Generated Content for SEO In today's...

Are weighted vests good...

Unlocking the Power of AI-Generated Content: A Boon or...

One to watch: Macquarie tips double-digit returns for this ASX healthcare stock

Macquarie Predicts Double-Digit Returns for ASX Healthcare Stock Macquarie Group, a prominent Australian financial services company, has issued a bullish prediction for a specific ASX-listed...

THE FREEPER CANTEEN – The Look That Up, It Must Be On My Bucket List Quiz – Wednesday, August 27, 2025

The Freeper Canteen: A Look That Up, It Must Be On My Bucket List The Freeper Canteen, a unique online community, has recently launched a...

215% PENGU Rally Incoming? Analyst Says Token ‘Inches’ From Next Leg Up

215% PENGU Rally Incoming? Analyst Predicts Imminent Breakout The cryptocurrency market is constantly fluctuating, and predicting the next big move is a challenge. However, one...

Junk is the new punk: Why we’re falling back in love with retro tech

Junk is the New Punk: Why We're Falling Back in Love with Retro Tech In a world dominated by sleek, minimalist designs and cutting-edge technology,...

Are weighted vests good for bones and muscle? Fact-checking a fitness trend – NPR

Unlocking the Power of AI-Generated Content for SEO In today's digital landscape, search engine optimization (SEO) is paramount for online success. But creating high-quality,...

Are weighted vests good for bones and muscle? Fact-checking a fitness trend – NPR

Unlocking the Power of AI-Generated Content: A Boon or Bane for SEO? The world of search engine optimization (SEO) is constantly evolving, and the recent...

TSMC cuts Chinese tools from cutting-edge chip production to avoid US ire – Nikkei Asia

TSMC Ditches Chinese Tools for Cutting-Edge Chip Production Taiwan Semiconductor Manufacturing Company (TSMC), the world's leading chipmaker, is reportedly phasing out Chinese-made equipment from its...

Google Messages beta rolling out QR code key verification – 9to5Google

Google Messages Adds QR Code Key Verification for Enhanced Security Google is bolstering the security of its Messages app with a new feature rolling out...

A Secretive US Space Plane Will Soon Test Quantum Navigation Technology

## US Space Plane to Test Revolutionary Quantum Navigation Technology The United States is on the cusp of a significant leap forward in space navigation....