Submission #1129639

#TimeUsernameProblemLanguageResultExecution timeMemory
1129639alecurseGlobal Warming (CEOI18_glo)C++20
0 / 100
150 ms6392 KiB
#include <iostream> #include <vector> #include <algorithm> #include <assert.h> using namespace std; int reals=1; vector<int> tree; void add(int k, int x, int y, int l, int r, int val) { if(y<=l||x>=r) return; if(x>=l&&y<=r) { tree[k]=val; return; } int d = (x+y)/2; add(k*2,x,d,l,r,val); add(k*2+1,d,y,l,r,val); tree[k]=max(tree[k*2],tree[k*2+1]); } int getmax(int k, int x, int y, int l, int r) { if(y<=l||x>=r) return 0; if(x>=l&&y<=r) { return tree[k]; } int d = (x+y)/2; return max(getmax(k*2,x,d,l,r),getmax(k*2+1,d,y,l,r)); } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int N,X; cin>>N>>X; assert(X==0); vector<int> dp(N); vector<int> v(N); vector<pair<int,int> > vtosort(N); for(int i=0;i<N;i++) { cin>>v[i]; vtosort[i].first=v[i]; vtosort[i].second=i; } sort(vtosort.begin(),vtosort.end()); vector<int> indexes(N); for(int i=0;i<N;i++) { indexes[vtosort[i].second]=i; } while(reals<N) reals*=2; tree.resize(reals*2); for(int i=0;i<N;i++) { int maxbef = getmax(1,0,reals,0,indexes[i]+1); dp[i]=maxbef+1; add(1,0,reals,indexes[i],indexes[i]+1,dp[i]); } int maxres=0; for(int i=0;i<N;i++) { maxres=max(maxres,dp[i]); } cout<<maxres; }
#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...