比赛 “Asm.Def战记之夏威夷”杯 评测结果 AAAAAAATTT
题目名称 Asm.Def的验证码 最终得分 70
用户昵称 dydxh 运行时间 3.012 s
代码语言 C++ 内存使用 2.98 MiB
提交时间 2015-11-06 10:41:21
显示代码纯文本
/*
Problem:cogs2099;
Language:c++;
by dydxh;
2015.11.06;
*/
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<utility>
#include<ctime>
#include<cstdlib>
#include<string>
#define ll long long
#define ull unsigned long long
using namespace std;
const int maxn=100005;
const int oo=2000000000;
const int mod=1000000007;
int n,cnt;
struct Pointer{
	int Col;
	ll Num;
}A[maxn];
ll suffix[maxn],prefix[maxn],ans;
inline int read(){
	int x=0;bool flag=0;char ch=getchar();
	while(ch>'9' || ch<'0') {if(ch=='-') flag=1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return flag?-x:x;
}
int main(){
    freopen("asm_code.in","r",stdin);
    freopen("asm_code.out","w",stdout);
	n=read();
	A[++cnt].Col=read(),A[cnt].Num=1;
	for(int i=2;i<=n;i++){
		int C=read();
		if(C==A[cnt].Col) A[cnt].Num++;
		else A[++cnt].Col=C,A[cnt].Num=1;
	}
	for(int i=1;i<=cnt;i++){
		if(A[i].Col==A[1].Col) prefix[i]=prefix[i-1]+A[i].Num;
		else prefix[i]=prefix[i-1];
	}
	for(int i=cnt;i>=1;i--){
		if(A[i].Col==A[1].Col) suffix[i]=suffix[i+1]+A[i].Num;
		else suffix[i]=suffix[i+1];
	}
	for(int i=2;i<=cnt;i+=2)
		for(int j=i+2;j<=cnt;j+=2){
			ll Total=A[i].Num*A[j].Num%mod;
			Total=Total*(suffix[j]+prefix[i])%mod;
			Total=Total*(prefix[j]-prefix[i])%mod;
			ans=(ans+Total)%mod;
		}
	printf("%d\n",ans);
	//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
    return 0;
}