标签:包含 sig long 处理 通过 while std ret rev
#include<bits/stdc++.h>
#define get bluesky
typedef unsigned long long ull;
using namespace std;
const int maxn = 3e5+10;
ull hs[maxn],get[maxn],sum[maxn];
int n,a[maxn];
ull ans;
ull calc(int pos) {
int r = pos,len = 1;
int ret = 0;
while(r<n&&a[r+1]!=1) {
++r;
len=max(len,a[r]);
if(r-len>=0) {
if((sum[r]^sum[r-len])==hs[len])
++ret;
}
}
return ret;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;++i) {
get[i]|=rand();
get[i]<<=32;
get[i]|=rand();
get[i]<<=32;
get[i]|=rand();
get[i]<<=32;
get[i]|=rand();
}
for(int i=1;i<=n;++i) hs[i]=hs[i-1]^get[i];
for(int i=1;i<=n;++i)
scanf("%d",a+i);
for(int i=1;i<=n;++i) sum[i]=sum[i-1]^get[a[i]];
int flag = 1;
for(int i=1;i<=n;++i) {
if(a[i]==1) {
ans+=calc(i);
ans+=flag;
}
}
flag^=1;
reverse(a+1,a+1+n);
for(int i=1;i<=n;++i) sum[i]=sum[i-1]^get[a[i]];
for(int i=1;i<=n;++i) {
if(a[i]==1) {
ans+=calc(i);
ans+=flag;
}
}
printf("%llu\n",ans);
return 0;
}
【文文殿下】CF1175F The Number of Subpermutations
标签:包含 sig long 处理 通过 while std ret rev
原文地址:https://www.cnblogs.com/Syameimaru/p/10992398.html