이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N=3e5+5,mod=1e9+7;
int t,n,d,a[N],ans_[N],ans[N],lazy[4*N],tree[4*N],R[N],L[N],par[N];
vector<int> V[N];
pair<int,int>c[N];
set<int>s;
void update(int u,int start,int end,int l,int r,int val){
if(lazy[u]){
tree[u] = max(tree[u],lazy[u]);
if(l!=r){
lazy[2*u] = max(lazy[2*u],lazy[u]);
lazy[2*u+1] = max(lazy[2*u+1],lazy[u]);
}
lazy[u]=0;
}
if(end<l || r<start) return;
if(start<=l && r<=end){
lazy[u] = val;
if(lazy[u]){
tree[u] = max(tree[u],lazy[u]);
if(l!=r){
lazy[2*u] = max(lazy[2*u],lazy[u]);
lazy[2*u+1] = max(lazy[2*u+1],lazy[u]);
}
lazy[u]=0;
}
return;
}
int mid=(l+r)/2;
update(2*u,start,end,l,mid,val);
update(2*u+1,start,end,mid+1,r,val);
tree[u] = max(tree[2*u],tree[2*u+1]);
}
int getans(int u,int start,int end,int l,int r){
if(lazy[u]){
tree[u] = max(tree[u],lazy[u]);
if(l!=r){
lazy[2*u] = max(lazy[2*u],lazy[u]);
lazy[2*u+1] = max(lazy[2*u+1],lazy[u]);
}
lazy[u]=0;
}
if(end<l || r<start) return 0;
if(start<=l && r<=end){
return tree[u];
}
int mid=(l+r)/2;
return max(getans(2*u,start,end,l,mid),getans(2*u+1,start,end,mid+1,r));
}
void merge(int u,int v){
u = par[u];
v = par[v];
if(V[u].size() < V[v].size()) swap(u,v);
L[u] = min(L[u],L[v]);
R[u] = max(R[u],R[v]);
for(int i=0;i<V[v].size();i++) {
V[u].push_back(V[v][i]);
par[V[v][i]] = u;
}
}
main(){
cin>>n>>d;
for(int i=1;i<=n;i++){
cin>>a[i];
par[i] = i;
V[i].push_back(i);
L[i]=R[i]=i;
c[i] = {a[i],i};
}
sort(c+1,c+n+1);
for(int i=1;i<=n;i++){
int j = i-1;
while(c[j+1].f==c[i].f){
j++; s.insert(c[j].s);
ans[c[j].s] = getans(1,L[par[c[j].s]],c[j].s,1,n) + 1;
}
int J = j,I = i;
while(j>=i){
for(int k = R[par[c[j].s]];k<=min(n-1,c[j].s+d-1);k++){
if(par[k+1] == par[k]) break;
merge(k+1,k);
}
j--;
}
j = J;
while(I<=j){
update(1,c[j].s,c[j].s,1,n,ans[c[j].s]);
j--;
}
i = J;
}
cout<<getans(1,1,n,1,n);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void merge(int, int)':
Main.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<V[v].size();i++) {
| ~^~~~~~~~~~~~
Main.cpp: At global scope:
Main.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
64 | main(){
| ^~~~
# | 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... |