#include #include #define nmax 50001 #define maxint 900001 #define f cin using namespace std; //ifstream f("date.in"); int n,v[nmax],b[nmax],a[4*nmax],val,pos,maxim,l,r,nr; void actualizare(int nod,int st,int dr) { if (st==dr) { a[nod]=val; } else { int m=(st+dr)/2; if (m>=pos) { actualizare(2*nod,st,m); } else { actualizare(2*nod+1,m+1,dr); } a[nod]=max(a[2*nod],a[2*nod+1]); } } void citire() { f>>n; for (int i=1;i<=n;i++) { f>>v[i]; val=v[i]; pos=i; actualizare(1,1,n); } } void cautare(int nod,int st,int dr) { if (l<=st && dr<=r) { maxim=max(maxim,a[nod]); } else { int m=(st+dr)/2; if (l<=m) { cautare(2*nod,st,m); } if (m+1<=r) { cautare(2*nod+1,m+1,dr); } } } void rez() { nr=0; for (int k=0;k