Cattle improve customer network CSP-S group before training camp
Tags (separated by spaces): problem solution algorithm simulation game
topic | description | practice |
---|---|---|
\ (BSOJ6377 \) | Seeking by the \ (n-\) Copies the array length \ (K \) times in each successive array of digital sub-type sequence occurs and | Calculate the contribution of each color range |
\ (BSOJ6378 \) | Two lengths are seeking tree \ (P \) , \ (Q \) disjoint path on | Backpack transducer root \ (DP ~ or ~ \) \ (the LCA \) + Difference |
\ (BSOJ6379 \) |
\ (T1 \)
Has a length \ (n × k \) array, which is a length \ (n-\) array \ (A_1 \) , \ (A_2 \) , ..., \ (A_n \) is repeated k times owned.
This array defines a right section different value of the counted number in it, now you need to obtain the weighted sum for each non-empty and the interval of the array.
The answer to \ (9 + 10 ^ 7 \) modulo.
Notes that calculate the effect of each section is difficult, because we can express a method of interval number of types of color is the fastest \ (O (lenlog_2len) \) of
And this question \ (len \ le 10 ^ { 14} \) let us give up
This is a routine, since we are not directly ask, then split the problem
Examples similar to a
Seeking \ (a_1, a_2 \ cdots, a_n \) twenty-two XOR and
Certainly it does not make a positive, but considering this issue in \ (a_i \ in \ {0,2 ^ k \} \) when you do well
So think of the demolition site
For this question, too, consider the calculation of the contribution of each color range
If not good to do, but it is difficult being anti-calculate the contribution of each color range is not simple
That's all interval between two adjacent colors
For \ (n-\) sequences, we can use easily scan \ (O (n) \) through the recording position of the last occurrence of each color \ (last_i \) using the number of combinations obtained
But \ (n * k \) it is
Consider some parts of the repeat request
Red part of the intermediate zone is sandwiched are \ (K \) th
Green Blue have \ (1 \) a
Pushed together with a green and blue \ (K-1 \) one
So we simply requires \ (n / 2n \) interval to put together blocks of color on it
Finally, explain
Length \ (\ le len \) the number of interval \ (\ frac {len (len + 1)} {2} \)
#include<bits/stdc++.h>
#define re register
#define N 100001
#define INF 0x3f3f3f3f
#define mod 1000000007ll
using namespace std;
inline char nc(){
static char buf[1048576],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1048576,stdin),p1==p2)?EOF:*p1++;
}
#define getchar nc
template<typename _int>
inline void read(re _int& x){
re char opt;re _int flag=1,res=0;
while((opt=getchar())<'0'||opt>'9')if(opt=='-')flag=-1;
while(opt>='0'&&opt<='9'){res=(res<<3)+(res<<1)+opt-'0';opt=getchar();}
x=res*flag;
}
typedef long long ll;
int a[N<<1],pos[N],t[N],tot,l[N<<1];
ll ans,n,k;
inline ll f(re ll x){return x*(x+1)%mod*500000004ll%mod;}
inline void Read(void){
re int i;read(n);read(k);
for(i=1;i<=n;++i){read(a[i]);t[i]=a[i];}
sort(t+1,t+n+1);tot=unique(t+1,t+n+1)-(t+1);
for(i=1;i<=n;++i){a[i]=lower_bound(t+1,t+tot+1,a[i])-t;a[i+n]=a[i];}
}
inline void Solve(void){
re int i;re ll self,sum,len,left,right;
ans=f(1ll*n*k%mod)*tot%mod;
self=0;
for(i=1;i<=n;++i){
l[i]=pos[a[i]];pos[a[i]]=i;
if(l[i]+1==i||!l[i])continue;len=1ll*i-l[i]-1ll;
self=(self+f(len))%mod;
}
for(i=1;i<=tot;++i)pos[i]=0;
left=0;
for(i=1;i<=n;++i){
l[i]=pos[a[i]];pos[a[i]]=i;
if(l[i]||l[i]+1==i)continue;len=1ll*i-l[i]-1ll;
left=(left+(1ll*len*(len+1ll)>>1ll))%mod;
}
for(i=1;i<=tot;++i)pos[i]=n+1;
right=0;
for(i=n;i>=1;--i){
l[i]=pos[a[i]];pos[a[i]]=i;
if(l[i]!=n+1||l[i]-1==i)continue;len=1ll*l[i]-i-1ll;
right=(right+(1ll*len*(len+1ll)>>1ll))%mod;
}
for(i=1;i<=tot;++i)pos[i]=0;
sum=0;
for(i=1;i<=(n<<1);++i){
l[i]=pos[a[i]];pos[a[i]]=i;
if(l[i]+1==i)continue;len=1ll*i-l[i]-1ll;
sum=(sum+(1ll*len*(len+1ll)>>1ll))%mod;
}
sum=((sum-self*2ll%mod-left)%mod+mod)%mod;
ans=(((ans-1ll*k*self%mod+mod)%mod-sum*(k-1ll)%mod-left-right)%mod+mod)%mod;
printf("%lld\n",(ans%mod+mod)%mod);
}
int main(void){
Read();Solve();
return 0;
}
\ (T2 \)
\ (N points have a tree and two integers p, q, the number required to meet the four-tuple (a, b, c, d ) of the following conditions: \)
\ (1.1≤a, B, C, d≤n. \)
\ (2. point a to point b through the number of sides of P. \)
\ the number of sides (3 passes the point c to point d for Q. \)
\ (. 4. absent a point both on the path of the point a to point b, point c and point d the path. \)
Notes that too often disjoint (write transducer root on my examination room to write crazy)
First, consider the reverse problem, disjoint path number = number of all paths - the number of paths intersect
Consider what circumstances intersection
We reversed and the third color becomes a second
We found that the green chain always had black chain \ (lca \) of
We consider this enumeration \ (lca \)
He may be the only two chains or a subtree and a daughter strand in the sub-tree from the tree (may not enter) to the outer chain subtree
Therefore, we only need to count through a point \ (X \) chain length in the sub-tree \ (p / q \) Program Number \ (f_ {x, p / q} \) and from the sub-tree (may not enter ) to the outer subtree chain length \ (p / q \) number of program \ (g_ {x, p / q} \)
Consider a chain split into two
Provided from \ (X \) depart, the number of sub-length single chain \ (K \) scheme \ (sf_ {x, k} \)
则\(\displaystyle{sf_{x,k}=\sum_{y\in son_x}}sf_{y,k-1}\)
Provided from \ (X \) starting exon singular chain length \ (K \) scheme \ (gf_ {x, k} \)
则\(\displaystyle{sg_{x,k}=sg_{fa_x,k-1}+sf_{fa_x,k-1}-sf_{x,k-2}}\)
That is, following his father from his father, but above
When the merger is similar to the backpack, we put in front of his son ( \ (SF '\) ) and \ (y (sf) \) merger
Thus \ (\ displaystyle {f_ {x , p / q} = \ sum_ {k \ in [0, p / q)} sf '_ {x, k} \ times sf_ {x, p / qk-1}} \)
\ (g \) easier
\(\displaystyle{g_{x,p/q}=\sum_{k\in[0,p/q]}sf_{x,k}\times sg_{x,p/q-k}}\)
\ (T3 \)
Stay pit