func_code_string: #include <bits/stdc++.h>   const int oo = 2139063143;   const int N = 101000;   const int P = 1000000007;   using namespace std;   inline void sc(int &x) {     x = 0;     static int p;     p = 1;     static char c;     c = getchar();     while (!isdigit(c)) {       if (c ==  - ) p = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c - 48);       c = getchar();     }     x *= p;   }   inline void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   inline void pr(int x) { print(x), putchar(  n ); }   int n, k;   int vis[N], cl = 1, cr = 0, ans = 0;   int a[N];   void add(int w, int d) {     if (!vis[w] && d == 1)       ++ans;     else if (vis[w] == 1 && d == -1)       --ans;     vis[w] += d;   }   int calc(int l, int r) {     while (cr < r) ++cr, add(a[cr], 1);     while (cl > l) --cl, add(a[cl], 1);     while (cr > r) add(a[cr], -1), --cr;     while (cl < l) add(a[cl], -1), ++cl;     return ans;   }   int f[N], g[N];   void solve(int wl, int wr, int l, int r) {     int mid = (l + r) >> 1, pos = 0;     f[mid] = 0;     for (int i = wl; i <= min(wr, mid - 1); i++) {       int sb = g[i] + calc(i + 1, mid);       if (sb > f[mid]) f[mid] = sb, pos = i;     }     if (l == r) return;     if (l < mid) solve(wl, pos, l, mid - 1);     if (r > mid) solve(pos, wr, mid + 1, r);   }   int las[N];   int main() {     sc(n), sc(k);     for (int i = 1; i <= n; i++) sc(a[i]);     for (int i = 1; i <= k; i++) {       solve(0, n, 1, n);       memcpy(g, f, sizeof(int) * (n + 1));     }     pr(f[n]);     return 0;   }   