参考代码

#include <bits/stdc++.h>
using namespace std;

#define n_max 1000000

int64_t t, ans;
int64_t a[n_max + 1], s[n_max + 1], tmp[n_max + 1];

void merge(int64_t* a, int left, int mid, int right) {
int i, j, k;
// count
i = left, j = mid + 1;
while (i <= mid && j <= right) {
if (a[i] + t < a[j]) {
i++;
// ordered pair counted here
ans += right - j + 1;
} else {
j++;
// inversion pair counted here
}
}

// merge
i = left, j = mid + 1, k = left;
while (i <= mid && j <= right) {
if (a[i] < a[j]) {
tmp[k++] = a[i++];
} else {
tmp[k++] = a[j++];
}
}
while (i <= mid) tmp[k++] = a[i++];
while (j <= right) tmp[k++] = a[j++];
for (int i = left; i <= right; ++i) a[i] = tmp[i];
}

void mergesort(int64_t* a, int left, int right) {
if (left >= right) return;
int mid = (left + right) / 2;
mergesort(a, left, mid);
mergesort(a, mid + 1, right);
merge(a, left, mid, right);
}

int main() {
int n;
scanf("%d%lld", &n, &t);
/*
Calculate s[i] to be the presum of a, then sum(a[i..j])=s[j] - s[i-1]
Problem (rephrase): find i<j, s[j] - s[i-1] > t
*/
s[0] = 0;
for (int i = 0; i < n; ++i) {
scanf("%lld", a + i);
s[i + 1] = a[i] + s[i];
}

// Solve
/*
Inspired by calculating inversion in array by mergesort (i<j, a[j]>a[i])
*/
mergesort(s, 0, n);

// Write
printf("%lld\n", ans);

return 0;
}