| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1282269 | quan606303 | K개의 묶음 (IZhO14_blocks) | C++20 | 1042 ms | 6544 KiB |
/*
* @Author: RMQuan
* @Date: 2025-10-22 23:48:40
* @Last Modified by: RMQuan
* @Last Modified time: 2025-10-23 01:49:09
*/
/*idea :
*/
#include <bits/stdc++.h>
bool M1;
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define TASK "TEST"
#define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
using namespace std;
const int MOD=1e9+7;
const int maxn=1e5+7;
const int LOG=16;
const int inf=1e9;
int a[maxn],n,k;
int rmq[maxn][LOG+1];
struct query
{
int pos,val,type;
};
bool cmp(const query &x,const query &y)
{
if (x.pos!=y.pos)return x.pos<y.pos;
return x.type<y.type;
}
void build(const vector<pair<int,pair<int,int> > > &qr)
{
for (int i=0;i<=n;i++)rmq[i][0]=inf;
vector<query> vt;
for (auto i:qr)
{
vt.push_back({i.se.fi,i.fi,1});
vt.push_back({i.se.se+1,i.fi,-1});
}
for (int i=0;i<=n;i++)vt.push_back({i,0,2});
sort(vt.begin(),vt.end(),cmp);
multiset<int> mt;
for (auto i:vt)
{
if (i.type==-1)
{
auto it=mt.lower_bound(i.val);
if (it!=mt.end())mt.erase(it);
}
else if (i.type==1)mt.insert(i.val);
else if (i.type==2)
{
if (mt.empty())rmq[i.pos][0]=inf;
else rmq[i.pos][0]=*(mt.begin());
}
}
for (int j=1;j<=LOG;j++)
{
for (int i=0;i+(1<<j)-1<=n;i++)rmq[i][j]=min(rmq[i][j-1],rmq[i+(1<<(j-1))][j-1]);
}
}
int get(int l,int r)
{
int k=__lg(r-l+1);
return min(rmq[l][k],rmq[r-(1<<k)+1][k]);
}
int L[maxn],R[maxn];
int dp[maxn];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
file();
cin>>n>>k;
for (int i=1;i<=n;i++)cin>>a[i];
stack<int> st;
for (int i=1;i<=n;i++)
{
while (st.size()&&a[st.top()]<=a[i])st.pop();
if (st.size())L[i]=st.top()+1;
else L[i]=1;
st.push(i);
}
while (st.size())st.pop();
for (int i=n;i>=1;i--)
{
while(st.size()&&a[st.top()]<=a[i])st.pop();
if (st.size())R[i]=st.top()-1;
else R[i]=n;
st.push(i);
}
vector<pair<int,pair<int,int> > >qr;
qr.push_back({0,{0,0}});
build(qr);
for (int j=1;j<=k;j++)
{
qr.clear();
for (int i=1;i<=n;i++)
{
int l=L[i]-1;
int r=i-1;
int u=i;
int v=R[i];
int val=get(l,r);
qr.push_back({val+a[i],{u,v}});
cerr<<val+a[i]<<" "<<u<<" "<<v<<endl;
}
build(qr);
}
cout<<get(n,n);
bool M2;
cerr<<"-------------------------------------------------"<<endl;
cerr<<"Time : "<<clock()<<" ms"<<endl;
cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl;
cerr<<"-------------------------------------------------"<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
