public void Solve() { int N = Reader.Int(), K = Reader.Int(); var S = new long[1].Concat(Reader.IntArray(N).Select(a => (long)a - K)).ToArray(); for (int i = 1; i <= N; i++) { S[i] += S[i - 1]; } var tree = new WaveletTree(S); long ans = Enu.Range(0, N).Sum(i => (long)(N - i) - tree.Rank(i + 1, N + 1, S[i] - 1)); Console.WriteLine(ans); }
public void Solve() { int N = Reader.Int(), K = Reader.Int(); var A = Reader.IntArray(N).Select(a => a - K).ToArray(); var S = new long[N]; for (int i = 0; i < N; i++) { S[i] = (i == 0 ? 0 : S[i - 1]) + A[i]; } var tree = new WaveletTree(S); long ans = 0; long balance = 0; for (int i = 0; i < N; i++) { int len = N - i; ans += len - tree.Rank(i, N, balance - 1); balance += A[i]; } Console.WriteLine(ans); }