Submission #410112

#TimeUsernameProblemLanguageResultExecution timeMemory
410112rqiVudu (COCI15_vudu)C++14
140 / 140
287 ms25668 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define ins insert
#define mp make_pair
#define pb push_back

#define all(x) begin(x), end(x)

#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 bt[mx];
void upd(int pos, int val){
	for(int i = pos; i < mx; i+=i&-i){
		bt[i]+=val;
	}
}
int sum(int pos){
	int res = 0;
	for(int i = pos; i > 0; i-=i&-i){
		res+=bt[i];
	}
	return res;
}

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];
	}

	vi v;
	for(int i = 0; i <= N; i++){
		v.pb(i);
	}

	auto sort_func = [&](const int i, const int j){
		return mp(a[i], i) < mp(a[j], j);
	};
	sort(all(v), sort_func);

	ll ans = 0;
	for(auto u: v){
		//cout << u << "\n";
		ans+=ll(sum(u+1));
		upd(u+1, 1);
	}	
	cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...