Submission #410109

#TimeUsernameProblemLanguageResultExecution timeMemory
410109rqiVudu (COCI15_vudu)C++14
112 / 140
659 ms65540 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define ins insert
#define mp make_pair

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ook order_of_key

const int mx = 1000005;
int N;
ll a[mx];
ll P;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}
	cin >> P;
	for(int i = 1; i <= N; i++){
		a[i]-=P;
	}
	for(int i = 1; i <= N; i++){
		a[i]+=a[i-1];
	}

	Tree<pair<ll, int>> t;
	t.ins(mp(0, 0));
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		ll val = ll(t.ook(mp(a[i], N+5)));
		//cout << "i, val: " << i << " " << val << "\n";
		ans+=val;
		t.ins(mp(a[i], i));

	}
	cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...