Codeforces Round #426 (Div. 2), problem: (D) The Bakery Solution In C/C++

#include <bits/stdc++.h>
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i–)
#define dream_hyojooslh

using namespace std;
const int N=200000+1067,T=67;
int f[N][T],it[T][N],lz[T][N],trai[N],phai[N],a[N];

void build(int x,int l,int r) {
trai[x]=l;
phai[x]=r;
if (l==r) return;
int mid =(l+r)/2;
build(x*2,l,mid);
build(x*2+1,mid+1,r);
}

void down(int t,int x) {
lz[t][x*2]+=lz[t][x];
it[t][x*2]+=lz[t][x];
lz[t][x*2+1]+=lz[t][x];
it[t][x*2+1]+=lz[t][x];
lz[t][x]=0;
}

void update(int t,int x,int l,int r,int c) {
if (l>phai[x]||r<trai[x]) return;
if (trai[x]>=l&&phai[x]<=r) {
it[t][x]+=c;
lz[t][x]+=c;
return;
}
down(t,x);
update(t,x*2,l,r,c);
update(t,x*2+1,l,r,c);
it[t][x]=max(it[t][x*2],it[t][x*2+1]);
}
int last[N];
map <long long,long long> mp;
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
//freopen(“dream_hyojooslh.inp”,”r”,stdin);
int n,k;
cin>>n>>k;;
For(i,1,n) cin>>a[i];
build(1,0,n);
For(i,1,n) {
For(j,0,k-1) update(j,1,last[a[i]],i-1,1);
last[a[i]]=i;
For(j,1,k) {
f[i][j]=it[j-1][1];
update(j,1,i,i,f[i][j]);
}
}
cout<<f[n][k]<<endl;
return 0;
}

Is Desk Productivity Tools...

📢 As an Amazon Associate, I earn from qualifying...

The Outer Worlds 2...

Gamers and RPG enthusiasts have reason to celebrate as...

Why Travel Organization Gear...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Is Desk Productivity Tools Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Desk Productivity Tools?The Desk Productivity Tools...

The Outer Worlds 2 v1.2.0.1-TENOKE

Gamers and RPG enthusiasts have reason to celebrate as Obsidian Entertainment's acclaimed franchise returns with new developments. The highly anticipated sequel to the award-winning...

Why Travel Organization Gear Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Car Detailing Essentials

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Car Detailing Essentials?The Car Detailing Essentials...

Why Everyone Is Talking About the Smart Home Hacks

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Smart Home Hacks?The Smart Home Hacks...

Why Everyone Is Talking About the Viral Kitchen Gadgets

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Viral Kitchen Gadgets?The Viral Kitchen Gadgets...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

GLP-1 Drugs Like Ozempic Carry Elevated Risks of Muscle Loss and Malnutrition in Adults Over 65

Understanding the Risks of GLP-1 Drugs for Older Adults GLP-1 receptor agonists, such as Ozempic, Wegovy, and Mounjaro, have transformed the landscape of weight management...