2020 3.31 10.30 Tencent side

10.15 scene, such as the interviewer wait until 11 o'clock, I cry

Q The problem is the result of a year of the original title a little lucky, finished four minutes, side drifting, waiting two faces GG

Shopping

Small Q on weekends and his little friends came to the big city shopping, a pedestrian street there are a lot of tall buildings, there are n high-rise in a row.
Small Q from the first building all the way to the last one, small Q have never seen so many buildings, so he wondered if he could see how many buildings at the location of each building it? (Current floor surface is greater than the height of the floor is equal to the back, behind the building will be blocked) 
 
Monotone stack, the front and rear sides run ok.
CV is estimated surface, a second surface after the plant is a real goose interview QAQ
 
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
int ans[maxn],val[maxn],res[maxn];
int main() { 
    long long int n,top=0;
    cin>>n;
    for(int i=1;i<=n;++i)cin>>val[i];
    for(int i=1;i<=n;++i){
        res[i]=top;
        while(top&&val[i]>=ans[top])--top;
        ans[++top]=val[i];
    }
    top = 0;
    memset(ans,0,sizeof(ans));
    for(int i=n;i>=1;--i){
        res[i]+=top;
        while(top&&val[i]>=ans[top])--top;
        ans[++top]=val[i];
    }
    for(int i=1;i<=n;++i)cout<<res[i]+1<<' ';
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/DreamKill/p/12604066.html