Submission #1035947

# Submission time Handle Problem Language Result Execution time Memory
1035947 2024-07-26T20:20:43 Z pera K blocks (IZhO14_blocks) C++17
0 / 100
5 ms 9864 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 100 , K = 1e2 + 1 , LOG = 18;
int n , k , a[N] , l[N] , dp[N] , ndp[N];
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 - 1];
      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]);
}
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;
   }
   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;
}

Compilation message

blocks.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9724 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Incorrect 3 ms 9820 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9728 KB Output is correct
5 Correct 3 ms 9864 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 3 ms 9856 KB Output is correct
8 Correct 5 ms 9820 KB Output is correct
9 Incorrect 3 ms 9820 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9724 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Incorrect 3 ms 9820 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9724 KB Output is correct
5 Correct 3 ms 9820 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Incorrect 3 ms 9820 KB Output isn't correct
10 Halted 0 ms 0 KB -