Submission #1867979


Source Code Expand

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

const int N = 200005;

int n, k;
long long a[N];
vector<long long> z;
long long ans;

// BIT
int T[N];
void upd(int x) { for (; x < N; x += x & -x) T[x]++; }
int get(int x) { int res = 0; for (; x > 0; x -= x & -x) res += T[x]; return res; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i], a[i] -= k;
		a[i] += a[i-1]; // a[] indicates prefix sums now
		z.push_back(a[i]);
	}
	z.push_back(0);
	sort(z.begin(), z.end());
	z.resize(distance(z.begin(), unique(z.begin(), z.end())));

	// solve
	upd(lower_bound(z.begin(), z.end(), 0) - z.begin() + 1);
	for (int i = 1; i <= n; ++i) {
		int pos = lower_bound(z.begin(), z.end(), a[i]) - z.begin() + 1;
		int cur = get(pos);
		ans += cur;
		upd(pos);
	}

	cout << ans << endl;
}

Submission Info

Submission Time
Task E - Meaningful Mean
User cheater2k
Language C++14 (GCC 5.4.1)
Score 600
Code Size 883 Byte
Status AC
Exec Time 61 ms
Memory 4720 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 33 ms 3568 KB
b06 AC 56 ms 4720 KB
b07 AC 55 ms 3952 KB
b08 AC 54 ms 3952 KB
b09 AC 41 ms 4336 KB
b10 AC 48 ms 4336 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 384 KB
b13 AC 20 ms 1912 KB
b14 AC 55 ms 4336 KB
b15 AC 33 ms 3952 KB
b16 AC 55 ms 4336 KB
b17 AC 61 ms 4336 KB
b18 AC 55 ms 4336 KB
b19 AC 43 ms 4336 KB
b20 AC 37 ms 3568 KB
b21 AC 34 ms 3568 KB
b22 AC 56 ms 4336 KB
b23 AC 53 ms 4336 KB