# Arrays(问题转化)

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (1000100)
#define MAXLog (20)
int a[MAXN],a2[MAXN];
int logg2[MAXN];
class RMQ
{
public:
int n,a[MAXN];
void mem(int* _a,int _n=0){n=_n;memcpy(a,_a,sizeof(int)*_n);    }
int d[MAXN][MAXLog],s[MAXN][MAXLog];
void RMQ_init()
{
Rep(i,n) d[i][0]=s[i][0]=a[i];
for(int j=1;(1<<j)<=n;j++)
for(int i=0;i + (1<<j) -1 < n; i++)
{
d[i][j]=min(d[i][j-1],d[i+(1<<(j-1))][j-1]);
s[i][j]=max(s[i][j-1],s[i+(1<<(j-1))][j-1]);
}
}
int query(int L,int R)
{
int k=logg2[R-L+1];
return min(d[L][k],d[R-(1<<k)+1][k]);
}
int query2(int L,int R)
{
int k=logg2[R-L+1];
return max(s[L][k],s[R-(1<<k)+1][k]);
}
}S;
int lp[MAXN],rp[MAXN],n;
struct BIT{
ll f[MAXN];
for(int i=x;i<=n;i+=i&(-i))
f[i]+=v;
}
ll qur(int x) {
ll v=0;
for(int i=x;i;i-=i&(-i))
v+=f[i];
return v;
}
}T;
pi p[MAXN];
int main()
{
//  freopen("A_data.in","r",stdin);
//  freopen(".out","w",stdout);
int cnt=0;
for(int i=0,j=1;cnt<=n;i++,j*=2) {
for(int p=1;p<=j&&cnt<=n;++p) logg2[++cnt]=i;
}

S.mem(a,n);
S.RMQ_init();

Rep(i,n){
int l=i,r=n-1,ans=n;
while(l<=r) {
int m=l+r>>1;
if (S.query(i,m)<a[i]) ans=m,r=m-1;else l=m+1;
}
lp[i]=ans;
}

Rep(i,n){
int l=0,r=i-1,ans=-1;
while(l<=r) {
int m=l+r>>1;
if (S.query2(m,i)>a[i]) ans=m,l=m+1;else r=m-1;
}
rp[i]=ans;
}

Rep(i,n)  p[i]=mp(rp[i],i);
sort(p,p+n);

ll ans=0;
int nowl=-1;
MEM(T.f)
Rep(i,n) {
int id=p[i].se,nowi=p[i].fi;
while(nowl<nowi) {
++nowl;
if(lp[nowl]==n) continue;
}
int c=T.qur(id+1) ;
ans +=c;
}
cout<<ans+1<<endl;

return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120