Submission #920098

#TimeUsernameProblemLanguageResultExecution timeMemory
920098Sir_Ahmed_ImranGlobal Warming (CEOI18_glo)C++17
100 / 100
1139 ms94028 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define nl '\n' #define ff first #define ss second #define ll long long #define append push_back #define all(x) (x).begin(),(x).end() #define pii pair<int,int> #define N 200001 #define M 1000000001 int a[N]; int Q[N]; struct Node{ int val; Node *L,*R; }; Node* getnode(){ Node* temp=new Node; temp->val=0; temp->L=NULL; temp->R=NULL; return temp; } class ST{ public: Node* root=getnode(); void update(int i,int x,Node* v,int s=0,int e=M){ if(e-s==1){ v->val=x; return; } int mid=(s+e)/2; if(v->L==NULL) v->L=getnode(); if(v->R==NULL) v->R=getnode(); if(i<mid) update(i,x,v->L,s,mid); else update(i,x,v->R,mid,e); v->val=max(v->L->val,v->R->val); if(v->L->val==0){ delete v->L; v->L=NULL; } if(v->R->val==0){ delete v->R; v->R=NULL; } } int get(int l,int r,Node* v,int s=0,int e=M){ if(r<=s || e<=l || l>=r || v->val==0) return 0; if(l<=s && e<=r) return v->val; int mid=(s+e)/2; if(v->L==NULL) v->L=getnode(); if(v->R==NULL) v->R=getnode(); int o=max(get(l,r,v->L,s,mid),get(l,r,v->R,mid,e)); if(v->L->val==0){ delete v->L; v->L=NULL; } if(v->R->val==0){ delete v->R; v->R=NULL; } return o; } }; void solve(){ int n,m,o,p,q,r; cin>>n>>m; ST x,y; for(int i=o=1;i<=n;i++) cin>>a[i]; for(int i=n;i>0;i--){ Q[i]=y.get(a[i],a[i]+1,y.root); y.update(a[i],y.get(a[i]+1,M,y.root)+1,y.root); } for(int i=1;i<=n;i++){ p=x.get(0,a[i],x.root)+1; y.update(a[i],Q[i],y.root); x.update(a[i],p,x.root); o=max(o,p+y.get(max(a[i]-m+1,0),M,y.root)); } cout<<o; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }

Compilation message (stderr)

glo.cpp: In function 'void solve()':
glo.cpp:68:17: warning: unused variable 'q' [-Wunused-variable]
   68 |     int n,m,o,p,q,r;
      |                 ^
glo.cpp:68:19: warning: unused variable 'r' [-Wunused-variable]
   68 |     int n,m,o,p,q,r;
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...