-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps468.cpp
More file actions
41 lines (30 loc) · 775 Bytes
/
Copy pathneps468.cpp
File metadata and controls
41 lines (30 loc) · 775 Bytes
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
32
33
34
35
36
37
38
39
40
41
/*
* Contest : OBI 2019 - Fase 1
* Problem : Soma
* Link : https://neps.academy/br/exercise/468
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
ll n, k, cnt = 0;
cin >> n >> k;
vector<ll> v(n), pref(n + 1);
map<ll, ll> pref_cnt;
for (int i = 0; i < n; i++) {
cin >> v[i];
pref[i + 1] = pref[i] + v[i];
}
for (int i = 1; i <= n; i++) fprintf(stderr, "%i ", pref[i]);
fprintf(stderr, "\n");
for (int i = 0; i <= n; i++) { // O(n)
cnt += pref_cnt[pref[i] - k];
pref_cnt[pref[i]] += 1;
}
for (auto p : pref_cnt) fprintf(stderr, "%lli %lli\n", p.first, p.second);
fprintf(stderr, "\n");
printf("%i\n", cnt);
return 0;
}