func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 35050;   const int inf = 1e9;   int t[2 * N], lz[N], n, h, k;   int dp[55][N], val[N];   pair<int, int> up[N];   int pv[N];   inline void carrot() {     for (int i = int(0); i < int(n + 1); ++i) pv[i] = n;     for (int i = int(n - 1); i >= int(0); i--) {       up[i].first = i + 1;       up[i].second = pv[val[i]];       pv[val[i]] = i + 1;     }   }   inline void clear_trees() {     memset(t, 0, sizeof(t));     memset(lz, 0, sizeof(lz));   }   inline void build_trees(int row) {     for (int i = int(0); i < int(n); ++i) t[i + n] = dp[row][i];     for (int i = int(n - 1); i >= int(1); i--)       t[i] = max(t[i << 1], t[i << 1 | 1]);   }   inline void apply(int p, int val) {     t[p] += val;     if (p < n) lz[p] += val;   }   inline void build(int p) {     while (p > 1) p >>= 1, t[p] = max(t[p << 1], t[p << 1 | 1]) + lz[p];   }   inline void modify(int lo, int ro) {     lo += n, ro += n;     for (int l = lo, r = ro; l < r; l >>= 1, r >>= 1) {       if (l & 1) apply(l++, 1);       if (r & 1) apply(--r, 1);     }     build(lo);     build(ro);   }   inline void push(int p) {     for (int s = int(h); s >= int(1); s--) {       int i = p >> s;       if (lz[i] != 0) {         apply(i << 1, lz[i]);         apply(i << 1 | 1, lz[i]);         lz[i] = 0;       }     }   }   inline int query(int l, int r) {     push(l + n);     push(r + n - 1);     int res = -inf;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l++]);       if (r & 1) res = max(res, t[--r]);     }     return res;   }   inline int solve() {     memset(dp, 0, sizeof(dp));     carrot();     set<int> s;     for (int i = int(n - 1); i >= int(0); i--) {       s.insert(val[i]);       dp[1][i] = int(s.size());     }     for (int num = int(2); num < int(k + 1); ++num) {       clear_trees();       build_trees(num - 1);       for (int i = int(n - num); i >= int(0); i--) {         modify(up[i].first, up[i].second);         dp[num][i] = query(i + 1, n);       }     }     return dp[k][0];   }   inline void input_random() {     n = (rand() % 10) + 1;     k = (rand() % n) + 1;     for (int i = int(0); i < int(n); ++i) val[i] = (rand() % n) + 1;   }   int dp2[15][15];   inline int brute() {     memset(dp2, 0, sizeof(dp2));     for (int i = int(0); i < int(n); ++i) dp2[1][i] = dp[1][i];     for (int num = int(2); num < int(k + 1); ++num) {       for (int i = int(n - num); i >= int(0); i--) {         set<int> s;         s.insert(val[i]);         for (int j = int(i + 1); j < int(n); ++j) {           if (dp[num - 1][j] == 0) continue;           dp2[num][i] = max(dp2[num][i], dp2[num - 1][j] + int(s.size()));           s.insert(val[j]);         }       }     }     for (int num = int(1); num < int(k + 1); ++num) {       for (int i = int(0); i < int(n); ++i) cout << dp[num][i] <<    ;       cout << endl;     }     return dp2[k][0];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = int(0); i < int(n); ++i) cin >> val[i];     h = sizeof(int) * 8 - __builtin_clz(n);     int ans = solve();     cout << ans << endl;     return 0;   }   