제출 #1272100

#제출 시각아이디문제언어결과실행 시간메모리
1272100ahmd_ibraaaVudu (COCI15_vudu)C++20
42 / 140
1067 ms131072 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define double long double
#define medal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define sec second
#define endl '\n'

map<ll,int> mp;

signed main(){
	medal
	int n;
	cin>>n;
	ordered_set ms;
	ll a[n+1];
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	ll p; cin>>p;
	ll pref[n+1];
	pref[0] = 0;
	set<ll> s;
	for(int i=1; i<=n; i++){
		a[i]-=p;
		pref[i] = pref[i-1] + a[i];
		s.insert(pref[i]);
	}
	s.insert(0);
	int ptr = 0;
	for(auto itr: s){
		mp[itr] = ptr;
		ptr++;
	}
	
	ll ans = 0;
	ordered_set os;
	os.insert(mp[0]);
	
	for(int i=1; i<=n; i++){
		int num = os.order_of_key(mp[pref[i]]+1);
		ans += num;
		os.insert(mp[pref[i]]);
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...