Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define NMAX 100005
- using namespace std;
- ifstream fin("maxime.in");
- ofstream fout("maxime.out");
- int n, m, maxim, premaxim, pozmaxim, pozpremaxim, p, rep, i, varf;
- int a[NMAX], CNT[NMAX], PZ[NMAX], st[NMAX], DR[NMAX], OK[NMAX];
- int main()
- {
- fin>>n;
- premaxim=-1;
- maxim=-1;
- pozpremaxim=-1;
- premaxim = -1;
- a[n+1]=NMAX+1;
- for(i=1; i<=n+1; ++i)
- {
- if(i<= n)
- fin>>a[i];
- if(a[i]>maxim)
- {
- premaxim=maxim;
- pozpremaxim=pozmaxim;
- maxim=a[i];
- pozmaxim=i;
- if(PZ[pozpremaxim]==-1)
- PZ[pozpremaxim]=i;
- PZ[pozmaxim]=-1;
- CNT[i]=1;
- }
- else
- {
- if(PZ[pozmaxim]==-1 && a[i]>=premaxim)
- {
- PZ[pozmaxim]=i;
- if(a[i]==premaxim)
- OK[pozmaxim]=1;
- }
- if(a[i] == maxim)
- {
- CNT[i]=2;
- rep++;
- }
- }
- }
- st[0] = n+1;
- DR[st[0]] = 0;
- varf = 0;
- for(i=n;i>=1;i--)
- {
- while(a[i]>a[st[varf]])
- varf--;
- if(a[i]==a[st[varf]])
- DR[i]=1+DR[st[varf]];
- else
- DR[i]=DR[st[varf]];
- st[++varf]=i;
- }
- fin>>m;
- for(i=1;i<=m;i++)
- {
- fin>>p;
- if(CNT[p]==0)
- fout<<rep<<" ";
- else
- if(CNT[p]==2)
- fout<<rep-1<<" ";
- else
- if(CNT[p]==1)
- {
- if(OK[p])
- fout<<1+rep-DR[p]+DR[PZ[p]]<<" ";
- else
- fout<<rep-DR[p]+DR[PZ[p]]<<" ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement