hiho week 283 register

Ended

Participants:78

Verdict:Accepted
Score:100 / 100
Submitted:2019-12-07 10:31:23

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 <iostream>
#include <unordered_map>
#include <cstring>
using namespace std;
const int MAXN = 1e5 + 10;
int N;
unordered_map<long long, int> cnt;
long long arr[MAXN], ans;
int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> arr[i];
        arr[i] += arr[i-1];
    }
    
    if (N < 3) cout << 0 << endl;
    else {
        for (int q = 3; q <= N; ++q) {
            ++cnt[arr[q - 2]];
            long long third = arr[N] - arr[q - 1];
            for (long long first = third - 1; first <= third + 1; ++first) {
                if (cnt.count(first)) {
                    long long second = arr[N] - third - first;
                    if (abs(first - second) <= 1 && abs(third - second) <= 1) {
                        ans += cnt[first];
                    }
                }
            }
        }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX