Submission #1035946

# Submission time Handle Problem Language Result Execution time Memory
1035946 2024-07-26T20:18:27 Z pera K blocks (IZhO14_blocks) C++17
0 / 100
3 ms 5156 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100 , K = 1e2 + 1 , LOG = 18;
int n , k , a[N] , l[N] , mx[N][LOG] , dp[N] , ndp[N];
int GET(int L , int R){
   int sz = __lg(R - L + 1);
   return max(mx[L][sz] , mx[R - (1 << sz) + 1][sz]);
}
struct node{
   int dp_min , mn , lz;
};
vector<node> t(4 * N);
node merge(node x , node y){
   x.dp_min = min(x.dp_min , y.dp_min);
   x.mn = min(x.mn , y.mn);
   return x;
}
void push(int u){
   if(t[u].lz == -1){
      return;
   }
   t[u * 2].mn = t[u].lz + t[u * 2].dp_min;
   t[u * 2 + 1].mn = t[u].lz + t[u * 2 + 1].mn;
   t[u * 2].lz = t[u].lz;
   t[u * 2 + 1].lz = t[u].lz;
   t[u].lz = -1;
}
void build(int u , int l , int r){
   if(l == r){
      t[u].dp_min = t[u].mn = dp[l];
      t[u].lz = -1;
      return;
   }
   int m = (l + r) / 2;
   build(u * 2 , l , m);
   build(u * 2 + 1 , m + 1 , r);
   t[u] = merge(t[u * 2] , t[u * 2 + 1]);
}
void upd(int u , int l , int r , int L , int R , int x){
   if(l > r || r < L || l > R){
      return;
   }
   if(L <= l && r <= R){
      t[u].mn = t[u].dp_min + x;
      t[u].lz = x;
      return;
   }
   int m = (l + r) / 2;
   upd(u * 2 , l , m , L , R , x);
   upd(u * 2 + 1 , m + 1 , r , L , R , x);
   t[u] = merge(t[u * 2] , t[u * 2 + 1]);
}
/*
void solve(int l , int r , int L , int R){
   if(l > r){
      return;
   }
   int m = (l + r) / 2 , id;
   dp[m] = -1;
   for(int x = L;x <= min(m , R);x ++){
      if(dp[m] == -1 || dp[m] > ndp[x - 1] + GET(x , m)){
         dp[m] = ndp[x - 1] + GET(x , m);
         id = x;
      }
   }
   solve(l , m - 1 , L , id);
   solve(m + 1 , r , id , R);
}*/
int main(){
   cin >> n >> k;
   int _mx = 0;
   dp[0] = 1e9;
   for(int i = 1;i <= n;i ++){
      cin >> a[i];
      l[i] = i - 1;
      while(l[i] > 0 && a[i] > a[l[i]]){
         l[i] = l[l[i]];
      }
      _mx = max(_mx , a[i]);
      dp[i] =_mx;
      mx[i][0] = a[i];
   }
   /*
   for(int bit = 1;bit < LOG;bit ++){
      for(int i = 1;i + (1 << bit) - 1 <= n;i ++){
         mx[i][bit] = max(mx[i][bit - 1] , mx[i + (1 << (bit - 1))][bit - 1]);
      }
   }*/
   for(int x = 1;x < k;x ++){
      for(int i = 0;i <= n;i ++){
         ndp[i] = dp[i];
      }
      build(1 , 1 , n);
      for(int i = 1;i <= n;i ++){
         upd(1 , 1 , n , l[i] + 1 , i , a[i]);
         dp[i] = t[1].mn;
      }
   }
   cout << dp[n] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5156 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5156 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Incorrect 2 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Incorrect 2 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5156 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5156 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Incorrect 2 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5156 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5156 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Incorrect 2 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -