Sponsors

Codeforces Round #381 (Div. 1), problem: (C) Alyona and towers Solution C/C++

Hi guys , I just solved the third problem of round 381 , Hope you like it , feel free to comment any better solution .

 

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const int inf=1e9+99;

const int N=1<<19;
struct dat {
ll d;
int ans;
int dL,dR;
int lenL,lenR,len;

void inc(ll dd) {
d += dd;
dL=dR=(d>0)-(d<0);
lenL=lenR=ans=!!d;
len=1;
}
void merge(const dat &L,const dat &R) {
ans=max(L.ans,R.ans);
dL=L.dL;
dR=R.dR;
len=L.len+R.len;
lenL=L.lenL;
lenR=R.lenR;
if(L.dR >= R.dL && L.dR && R.dL) {
ans=max(ans,L.lenR+R.lenL);
if(lenL==L.len) lenL += R.lenL;
if(lenR==R.len) lenR += L.lenR;
}
}
} rmq[N+N];

void inc(int x,ll d) {
x+=N;
rmq[x].inc(d);
for(;x>>=1;) rmq[x].merge(rmq[x+x],rmq[x+x+1]);
}

int main() {
int n; scanf(“%d”,&n);
int pr=-1;
for(int i=1;i<=n;i++) {
int a;
scanf(“%d”,&a);
if(i>1) inc(i-1,a-pr);
pr=a;
}

int m; scanf(“%d”,&m); for(;m–;) {
int l,r,d; scanf(“%d%d%d”,&l,&r,&d);
if(l>1) inc(l-1,d);
if(r<n) inc(r,-d);
printf(“%d\n”,rmq[1].ans+1);
}
}

Which scientist born in...

Ernst Öpik: The Legendary Astrophysicist Born on November 13th In...

Master Chief voice actor...

Master Chief Voice Actor Steve Downes Slams Unauthorized AI...

Hotel software maker Mews...

Mews Secures Massive $300M Series D Round, Hitting $2.5...

Lagos forum launches scholarship...

Lagos Gentry Forum Launches Crucial Scholarship Drive for Indigent...

Quick News: Red, Custom,...

President Claremont and King James III Return: 'Red, White...

AGI Needs World Models...

Demis Hassabis: AGI Requires 'World Models,' LLMs Alone Are...

Which scientist born in 13 november?

Ernst Öpik: The Legendary Astrophysicist Born on November 13th In the vast calendar of scientific history, certain dates mark the beginning of groundbreaking lives. November...

Master Chief voice actor Steve Downes says AI voice cloning crosses a line and wants it to stop

Master Chief Voice Actor Steve Downes Slams Unauthorized AI Voice Cloning The iconic voice behind the legendary Master Chief of the Halo series, Steve Downes,...

Hotel software maker Mews nabs $300M at $2.5B valuation

Mews Secures Massive $300M Series D Round, Hitting $2.5 Billion Valuation The landscape of hospitality technology is rapidly evolving, and few companies are making a...

Lagos forum launches scholarship drive for indigent secondary students

Lagos Gentry Forum Launches Crucial Scholarship Drive for Indigent Students In a significant move aimed at democratizing access to tertiary education, the Lagos Gentry Forum...

Quick News: Red, Custom, Fix, Bambo, Kenan

President Claremont and King James III Return: 'Red, White & Royal Wedding' Sequel Confirmed Fans of the beloved romantic comedy Red, White & Royal Blue...

AGI Needs World Models and State of World Models

Demis Hassabis: AGI Requires 'World Models,' LLMs Alone Are Not Enough In the fiercely competitive race toward Artificial General Intelligence (AGI), the CEOs of leading...

PM gives management masterclass in the lexicology of Luxonese

The Art of Obfuscation: Deconstructing the Lexicology of ‘Luxonese’ In the high-stakes arena of modern governance, the way a leader communicates is often as important...

Drew Gill Wins MLF Bass Pro Tour B&W Trailer Hitches Stage 1 on Lake Guntersville Presented by Mercury

Drew Gill Dominates Lake Guntersville, Securing MLF Bass Pro Tour Stage 1 Victory The 2026 Major League Fishing (MLF) season kicked off with a stunning...

San Francisco firefighters rally for retiree denied cancer treatment by Blue Shield as more patients come forward

San Francisco Firefighters Rally Against Blue Shield for Denying Cancer Care to Retired Colleague The steps of San Francisco City Hall recently became the stage...