Skip to content

Instantly share code, notes, and snippets.

@behitek
Last active November 23, 2020 09:39
Show Gist options
  • Save behitek/15719b137ff163480ec97bf8ffd54b81 to your computer and use it in GitHub Desktop.
Save behitek/15719b137ff163480ec97bf8ffd54b81 to your computer and use it in GitHub Desktop.
// https://luyencode.net/problem/PTIT032
#include<bits/stdc++.h>
using namespace std;
#define FTB(i,a,b) for(LL i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(LL i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(LL i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(LL i=a,_b=b;i>_b;i--)
#define endl "\n"
#define PB push_back
#define mp make_pair
#define fi first
#define se second
#define debug cout<<"VL\n"
#define coYES cout<<"YES\n"
#define coNO cout<<"NO\n"
#define coyes cout<<"yes\n"
#define cono cout<<"no\n"
#define coYes cout<<"Yes\n"
#define coNo cout<<"No\n"
#define PI 3.1415926535897
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define y1 aghksdmlsjdfjavljvlckdfmg
#define lamtron(n) fixed<<setprecision(n)
#define ALL(s) s.begin(),s.end()
#define ONLINE_JUDGE gshysrthrrthbd
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
template<class T> inline T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
typedef double DB;
typedef long long LL;
typedef unsigned long long UL;
typedef long double LD;
typedef pair<LL,LL> II;
typedef vector<LL> VI;
typedef vector<II> VII;
typedef vector<bool> VB;
LL n,a[100005],l[100005],r[100005];
stack<LL> s;
int main(int argc, char *argv[]){
freopen(argv[1],"r",stdin);
cin>>n;
FTB(i,1,n) cin>>a[i];
FTB(i,1,n){
l[i]=1;
if(s.size()&&s.top()<a[i]) l[i]+=s.size();
else while(s.size()) s.pop();
s.push(a[i]);
}
while(s.size()) s.pop();
cout << "\n" << n << "\n";
FGB(i,n,1){
r[i]=1;
if(s.size()&&s.top()<a[i]) r[i]+=s.size();
else while(s.size()) s.pop();
s.push(a[i]);
}
FTB(i,1,n) cout<<r[i]+l[i]-1<<" ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment