include map include cstdio include iostream include iomanip include st

 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
42
43
44
45
46
47
48
49
50
#include <map>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <set>
#include <queue>
#include <ctime>
#include <functional>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag,
tree_order_statistics_node_update> TREE;
#define mp make_pair
const int N = (int)1e5+10;
int I[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, M;
cin >> n >> M;
ll ans = 0;
TREE t1, t2;
t1.insert(mp(0, 0));
t2.insert(mp(0, 0));
for (int i = 1; i <= n; ++i){
cin >> I[i];
I[i] += I[i - 1];
ans += t1.order_of_key(mp(I[i] - M, 0));
ans += t2.order_of_key(mp(-I[i] - M, 0));
t1.insert(mp(I[i], i));
t2.insert(mp(-I[i], i));
}
cout << ans << endl;
return 0;
}