Submission #380261

# Submission time Handle Problem Language Result Execution time Memory
380261 2021-03-20T18:07:39 Z saarang123 Vudu (COCI15_vudu) C++17
140 / 140
365 ms 19948 KB
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1000 * 1000 + 2;
int bit[mxn], n, p;

void upd(int x) {
	for(; x <= n; x += (x & -x))
		bit[x]++;
}

long long qry(int x) {
	long long res = 0;
	for(; x > 0; x -= (x & -x))
		res += bit[x];
	return res;
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    cin >> n;
    vector<long long> a(n), b(n);
    for(int i = 0; i < n; i++)
    	cin >> a[i];
    cin >> p;
    for(int i = 0; i < n; i++) {
    	a[i] -= p;
    	if(i)
    		a[i] += a[i - 1];
    	b[i] = a[i];
    }
    sort(b.begin(), b.end());
    b.resize(unique(b.begin(), b.end()) - b.begin());
    upd(lower_bound(b.begin(), b.end(), 0LL) - b.begin() + 1);
    long long ans = 0;
    for(int i = 0; i < n; i++) {
    	int id = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
    	ans += qry(id);
    	upd(id);
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 500 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 365 ms 19308 KB Output is correct
5 Correct 190 ms 11036 KB Output is correct
6 Correct 311 ms 17132 KB Output is correct
7 Correct 304 ms 17772 KB Output is correct
8 Correct 270 ms 15596 KB Output is correct
9 Correct 357 ms 19948 KB Output is correct
10 Correct 299 ms 17260 KB Output is correct