이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
long long gcd(long long a, long long b){ return b? gcd(b, a%b) : a; }
long long lcm(long long a, long long b){ return (!a or !b)? 0 : a * b / gcd(a,b); }
long long poww(long long a, long long b){
long long res = 1;
while(b){
if(b%2) res = res * a ;
a = a * a; b>>=1;
} return res;
}
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using li = long long;
using vi = vc<int>;
using ii = pair<int,int>;
// ('-')7
struct ST{
#define mid (l+r)/2
#define left(u) (u+1)
#define right(u) (u+((mid-l+1)<<1))
vi st;
ST(int n):st(2*n,0){}
int f(int a, int b){
return max(a,b);
}
void update(int u, int l, int r, int pos, int val){
if(l>r)return;
if(l==r){st[u]=val; return;}
if(pos<=mid)update(left(u),l,mid,pos,val);
else update(right(u),mid+1,r,pos,val);
st[u]=f(st[left(u)],st[right(u)]);
}
int query(int u, int l, int r, int ll, int rr){
if(l>r or rr<l or ll>r)return 0;
if(l>=ll and r<=rr)return st[u];
return f(query(left(u),l,mid,ll,rr),query(right(u),mid+1,r,ll,rr));
}
};
int main(){_
auto solve=[&](){
int n,m; cin>>n>>m;
vi v(n);
fore(i,0,n)cin>>v[i];
vc<ii>ord(n);
fore(i,0,n)ord[i]={v[i],-i};
sort(all(ord),greater<ii>());
ST st(n);
vi g(n,-1);
vi r(n,n-1);
multiset<int>s;
fore(i,0,n){
s.insert(v[i]);
if(sz(s)==m){
g[i]=*s.begin();
s.erase(s.lower_bound(v[i-m+1]));
}
}
//fore(i,0,n)cout<<g[i]<<" ";cout<<ENDL;
priority_queue<ii,vc<ii>,greater<ii>>q;
fore(i,0,n){
while(i+m-1<n and !q.empty() and q.top().f<g[i+m-1]){
r[q.top().s]=i+m-1;
q.pop();
}
q.push({v[i],i});
}
//fore(i,0,n)cout<<r[i]<<" ";
vi dp(n,1);
fore(j,0,n){
int i = -ord[j].s;
dp[i]=max(st.query(0,0,n-1,i+1,r[i])+1,dp[i]);
//cout<<dp[i]<<" ";
st.update(0,0,n-1,i,dp[i]);
}
int mx = 1;
fore(i,0,n)mx = max(mx,dp[i]);
cout<<mx<<ENDL;
};
//int t; cin>>t; while(t--)
solve();
}
# | 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... |