hiho week 299 register

Ended

Participants:71

Verdict:Accepted
Score:100 / 100
Submitted:2020-03-25 16:09:26

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 100010;
typedef long long LL;
int n;
int a[N];
int one[N], three[N];
int main(void) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        one[i] = one[i - 1];
        three[i] = three[i - 1];
        if (a[i] == 1) one[i] += 1;
        if (a[i] == 3) three[i] += 1;
    }
    LL ret = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == 2) {
            ret += (one[i] * (three[n] - three[i]));
        }
    }
    printf("%lld\n", ret);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX