Submission #836925

#TimeUsernameProblemLanguageResultExecution timeMemory
836925groshiMoney (IZhO17_money)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int pot=1; int drzewo[3000000]; int lazy[3000000]; int t[3000000]; void propaguj(int x,int l,int r) { drzewo[x*2]+=lazy[x]*(r-l+1)/2; drzewo[x*2+1]+=lazy[x]*(r-l+1)/2; lazy[x*2]+=lazy[x]; lazy[x*2+1]+=lazy[x]; lazy[x]=0; } int suma(int x,int l,int r,int a,int b) { if(b<a) return 0; if(r<a || l>b) return 0; propaguj(x,l,r); if(a<=l && r<=b) return drzewo[x]; int mid=(l+r)/2; int L=suma(x*2,l,mid,a,b); int R=suma(x*2+1,mid+1,r,a,b); drzewo[x]=drzewo[x*2]+drzewo[x*2+1]; return L+R; } void dodaj(int x,int l,int r,int a,int b) { if(r<a || l>b) return; propaguj(x,l,r); if(a<=l && r<=b) { drzewo[x]+=(r-l+1); lazy[x]++; return; } int mid=(l+r)/2; dodaj(x*2,l,mid,a,b); dodaj(x*2+1,mid+1,r,a,b); drzewo[x]=drzewo[x*2]+drzewo[x*2+1]; } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; while(pot<=n) pot*=2; pot--; for(int i=1;i<=n;i++) cin>>t[i]; int wynik=0; for(int i=1;i<=n;i++) { int j=i; while(j+1<=n && t[j+1]>t[j] && suma(1,pot+1,pot*2+1,t[i]+pot+1,pot+t[j+1]-1)==0) j++; for(int e=i;e<=j;e++) dodaj(1,pot+1,pot*2+1,t[e]+pot,t[e]+pot); i=j; wynik++; } cout<<wynik; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...