比赛 |
“Asm.Def战记之夏威夷”杯 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Asm.Def的验证码 |
最终得分 |
100 |
用户昵称 |
---- |
运行时间 |
0.036 s |
代码语言 |
C++ |
内存使用 |
1.46 MiB |
提交时间 |
2015-11-06 11:37:09 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
typedef long long int i64;
const int maxn = 100333;
int n, S[maxn], A[maxn], dd[maxn];
int main()
{
freopen("asm_code.in", "r", stdin);
#ifndef debug
freopen("asm_code.out", "w", stdout);
#endif
scanf("%d", &n); int cnt = 0;
for (int i = 1; i <= n; ++i)
{
int ty; scanf("%d", &ty);
if (ty == 2) ++S[i];
else dd[cnt++] = i;
}
for (int i = 1; i <= n; ++i) S[i] += S[i - 1];
for (int i = 0; i < cnt; ++i) A[i] = S[dd[i]];
int M = S[n], ans2 = 0, l1 = 0, l2 = 0;;
for (int i = cnt - 1; i >= 0; --i)
{
(ans2 += (i64(cnt - i - 1) * (mo - M - A[i]) % mo * A[i] % mo + l1 + 2LL * A[i] * l2) % mo) %= mo;
(l1 += i64(M - A[i]) * A[i] % mo ) %= mo;
(l2 += A[i]) %= mo;
}
printf("%d\n", ans2);
}