Submission #60051

# Submission time Handle Problem Language Result Execution time Memory
60051 2018-07-23T14:09:30 Z Adhyyan1252 Vudu (COCI15_vudu) C++11
56 / 140
1000 ms 66560 KB
#include<bits/stdc++.h>

// 6 47
typedef long long ll;
#define NMAX 1000005
#define SMAX 2300000


using namespace std;

int tree[SMAX];

void upd(int i, int s, int e, int indx){
	if(s == e){
		tree[i] = 1;
		return;
	}
	int m = (s + e)>>1;
	if(indx <= m) upd(i*2, s, m, indx);
	else upd(i*2+1, m+1, e, indx);
	tree[i] = tree[i*2] + tree[i*2+1];
}

ll query(int i, int s, int e, int l, int r){
	if(s >= l && e <= r) return tree[i];
	else if(s > r || e < l) return 0;
	int m = (s + e)>>1;
	return query(i*2, s, m, l, r) + query(i*2+1, m+1, e, l, r);
}

int main(){
	int n; cin>>n;
	ll a[n];
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}	
	ll p; cin>>p;
	vector<pair<ll, int> > vi;
	ll zero = 0;
	for(int i = n-1; i >= 0; i--){
		a[i] -= p;
		zero -= a[i];
		ll cur = zero + a[i];
		//cout<<i<<" PUSH: "<<cur<<endl;
		vi.push_back({cur, i});
	}
	sort(vi.begin(), vi.end());
	vector<int> indx(n);
	for(int i = 0; i < n; i++){
		indx[vi[i].second] = i;
	}
	ll ans = 0; zero = 0;
	for(int i = n-1; i >= 0; i--){
		upd(1, 0, n-1, indx[i]);
		zero -= a[i];
		pair<ll, int>  temp = {zero, 0};
		int index = lower_bound(vi.begin(), vi.end(), temp ) - vi.begin();
		ans += query(1, 0, n-1, index, n-1);
	}
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 764 KB Output is correct
2 Correct 9 ms 780 KB Output is correct
3 Correct 9 ms 880 KB Output is correct
4 Execution timed out 1094 ms 44668 KB Time limit exceeded
5 Correct 872 ms 44668 KB Output is correct
6 Execution timed out 1069 ms 54908 KB Time limit exceeded
7 Execution timed out 1078 ms 61840 KB Time limit exceeded
8 Execution timed out 1069 ms 66088 KB Time limit exceeded
9 Execution timed out 1071 ms 66560 KB Time limit exceeded
10 Execution timed out 1060 ms 66560 KB Time limit exceeded