Submission #140836

#TimeUsernameProblemLanguageResultExecution timeMemory
140836rzbtGlobal Warming (CEOI18_glo)C++14
0 / 100
911 ms26724 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 200005 typedef long long ll; using namespace std; int n,d; int niz[MAXN]; set<int> s; map<int,int> m; int tren=0; int seg1[MAXN*4],seg2[MAXN*4]; void dodaj(int l,int d,int p,int x,int k,int *seg){ //if(seg==seg2)printf(" %d %d kek\n",p,x); //else printf(" %d %d lel\n",p,x); if(l==d){ seg[k]=max(seg[k],x); return; } int mid=(l+d)/2; if(p<=mid)dodaj(l,mid,p,x,k+k,seg); else dodaj(mid+1,d,p,x,k+k+1,seg); seg[k]=max(seg[k+k],seg[k+k+1]); } int dobij(int l,int d,int tl,int td,int k,int *seg){ if(l>td || d<tl)return 0; if(l>=tl && d<=td)return seg[k]; int mid=(l+d)/2; return max(dobij(l,mid,tl,td,k+k,seg),dobij(mid+1,d,tl,td,k+k+1,seg)); } int dp[MAXN][2]; int main() { scanf("%d %d", &n, &d); for(int i=1;i<=n;i++) scanf("%d",niz+i); for(int i=1;i<=n;i++) s.insert(niz[i]); for(auto x:s){ tren++; m[x]=tren; } for(int i=1;i<=n;i++){ int tren=m[niz[i]]; if(tren==1){ dp[i][0]=1; dp[i][1]=1+dobij(1,n,1,m[*(--s.lower_bound(niz[i]+d))],1,seg1); dodaj(1,n,tren,dp[i][0],1,seg1); dodaj(1,n,tren,dp[i][1],1,seg2); //printf(" %d %d\n",niz[i],*(--s.lower_bound(niz[i]+d))); }else{ dp[i][0]=1+dobij(1,n,1,tren-1,1,seg1); dp[i][1]=max(1+dobij(1,n,1,m[*(--s.lower_bound(niz[i]+d))],1,seg1), 1+dobij(1,n,1,tren-1,1,seg2)); dodaj(1,n,tren,dp[i][0],1,seg1); dodaj(1,n,tren,dp[i][1],1,seg2); //printf(" %d %d\n",niz[i],*(--s.lower_bound(niz[i]+d))); } //printf(" %d %d\n",dp[i][0],dp[i][1]); } printf("%d",dp[n][1]); return 0; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &d);
     ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",niz+i);
         ~~~~~^~~~~~~~~~~~
#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...