DescriptionSome people use a lot of passwords in social networks, and we convert all forms of information into 01 signals and then convert them into integers, whicha password used by a person for a period of time is treated as a non-negative integer sequence of length n a_1,a_2,..., a_n. A person adjacent several times in social networksThe password used in this is likely to be similar, which makes the password not secure enough. In order to verify that some people may be disturbed during certain time periodseffect, we need to calculate the complexity of the above sequence. value, which will serve as a part of our assessment of the complexity of the password. Because the answer can be large, you just need to give the answer to the value of the 10^9+61 modulo. InputThe first line contains a positive integer t, which indicates that there is a T group of test data. each set of test data is then given in turn. For each set of test data:The first line consists of a positive integer n. the second line contains n non-negative integers, representing a_1,a_2,?, A_n. Ensure that there is exactly one space between each integer in a row, with no additional spaces. 100% of the data meet: 1≤t≤200,1≤n≤10^5,1≤∑n≤10^6,0≤a_i≤10^9Outputfor each set of data output one row, contains an integer that represents the value of the answer to the 10^9+61 modulo.
Using a monotonic stack to preprocess each a[x] as the maximum value (the same value as the comparison position) appears in the interval, the specific form is [L,r] | L in [Ls[x],x], R in [X,rs[x]], so you can bitwise processing then prefix and a bit for each a[x] to calculate the contribution separately
#include <cstdio>typedefLong Longi64;Const intn=100007, p=1000000061;Charbuf[15000007],*ptr=buf-1;int _(){ intx=0, f=1, c=*++ptr; while(c< -) c=='-'&& (f=-1), c=*++ptr; while(c> -) x=x*Ten+c- -, c=*++ptr; returnx*F;}intt,n,a[n],ls[n],rs[n],ss[n],sp=0, S[n],ans;intMain () {Buf[fread (buf,1,sizeof(BUF), stdin)]=0; for(T=_ (); t;--T) {N=_(); for(intI=1; i<=n;++i) a[i]=_(); for(intI=1; i<=n;++i) { while(Sp&&a[ss[sp]]<a[i]) rs[ss[sp--]]=i-1; ss[++sp]=i; } while(SP) rs[ss[sp--]]=N; for(inti=n;i;--i) { while(Sp&&a[ss[sp]]<=a[i]) ls[ss[sp--]]=i+1; ss[++sp]=i; } while(SP) ls[ss[sp--]]=1; Ans=0; for(intI=0;i< -;++i) { intsum=0; for(intj=1; j<=n;++j) s[j+1]=s[j]^ (a[j]>>i&1); for(intj=1; j<=n;++j) s[j+1]+=S[j]; for(intj=1, v1,v2;j<=n;++j) {V1=s[rs[j]+1]-S[j]; V2=s[j]-s[ls[j]-1]; Sum= (sum+ (i64 (v1) * (j+1-LS[J]-V2) +i64 (v2) * (rs[j]+1-J-V1))%p*a[j])%P; } ans= (ans+ (i64 (sum) <<i)%P)%Q; } printf ("%d\n", ans); } return 0;}
bzoj4750: Password Safe