이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
//const int iris = 1e9+7;
const int iris = 998244353;
using namespace std;
const int N=3e5;
struct sagiri
{
vector<int> st;
sagiri()
{
st.resize(N*4, 0);
}
void mdf(int i,int l,int r,int p,int x)
{
int m=l+(r-l)/2;
if(l==r)
{
st[i]=x;
return;
}
if(p<=m)
mdf(i*2,l,m,p,x);
else
mdf(i*2+1,m+1,r,p,x);
st[i]=max(st[i*2], st[i*2+1]);
}
int qry(int i,int l,int r,int L,int R)
{
int m=l+(r-l)/2;
if(L<=l && r<=R)
return st[i];
else if(R<=m)
return qry(i*2,l,m,L,R);
else if(L>m)
return qry(i*2+1,m+1,r,L,R);
else
return max(qry(i*2,l,m,L,r), qry(i*2+1,m+1,r,L,R) );
}
}dis, dp;
void solve()
{
int n,d;
cin>>n>>d;
vector<matsuri> arr;
for(int i=1;i<=n;i++)
{
int a;
cin>>a;
arr.emplace_back(a,-i);
}
sort(arr.begin(), arr.end());
set<int> s;
dp.mdf(1,0,n,0,0);
s.insert(0);
dis.mdf(1,0,n,0,n);
int ii=0;
for(auto [a,i]:arr)
{
i*=-1;
while(ii<n && arr[ii].first==a)
{
//cout<<ii<<'\n';
int j=arr[ii++].second*-1;
s.insert(j);
auto it=s.find(j);
it--;
dis.mdf(1,0,n,*it,j-*it);
//cout<<" . "<<*it<<' '<<j<<'\n';
it=s.upper_bound(j);
if(it==s.end())
dis.mdf(1,0,n,j,n-j);
else
dis.mdf(1,0,n,j,*it-j);
}
int l=0, r=i;
//cout<<i<<' '<<a<<'\n';
while(l<r)
{
int m=l+(r-l)/2;
//cout<<" - "<<m<<' '<<dis.qry(1,0,n,m,i-1)<<'\n';
//for(int j=m;j<=i;j++)
// cout<<" "<<dis.qry(1,0,n,j,j)<<'\n';
if(dis.qry(1,0,n,m,i-1)<=d)
r=m;
else
l=m+1;
}
//cout<<' '<<l<<' '<<i<<' '<<dp.qry(1,0,n,l,i)<<'\n';
dp.mdf(1,0,n,i,dp.qry(1,0,n,l,i)+1);
}
cout<<dp.qry(1,0,n,0,n)<<'\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T=1;
//cin>>T;
while(T--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:64:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
64 | for(auto [a,i]:arr)
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |