Submission #256582

# Submission time Handle Problem Language Result Execution time Memory
256582 2020-08-02T21:46:27 Z ElyesChaabouni Vudu (COCI15_vudu) C++14
0 / 140
276 ms 65540 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000001
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	//cout << n << '\n';
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int p;
	vector<pair<long long, int> >v;
	cin >> p;
	long long sum=0, cu=0, ans=0;
	for(int i = n-1; i >= 0; i--)
	{
		sum+=a[i];
		v.push_back(make_pair(sum-cu, i));
		//cout << here[i] << ' ';
		cu+=p;
	}
	//cout << '\n';
	sort(v.begin(), v.end());
	int m[n];
	for(int i = 0; i < n; i++)
	{
		m[v[i].second]=i;
	}
	int pp=1;
	while(pp <= n)
		pp*=2;
	cu=0;
	int tree[2*p+1];
	for(int i = 0; i  <2*p+1; i++)
		tree[i]=0;
	for(int i = p; i <= p+n-1; i++)
		tree[i]=1;
	for(int i = p-1; i >= 1; i--)
		tree[i]=tree[2*i]+tree[2*i+1];
	sum=0;
	for(int i = n-1; i >= 0; i--)
	{
		vector<pair<long long, int> >::iterator it=lower_bound(v.begin(), v.end(), make_pair(p+sum-cu, -1));
		if(it!=v.end())
		{
			int x=(it-v.begin())+p, y=n-1+p;
			while(x <= y)
			{
				if(x%2==1)
				{
					ans+=tree[x];
					x++;
				}
				if(y%2==0)
				{
					ans+=tree[y];
					y--;
				}
				x/=2;
				y/=2;
			}
		}
		//cout << s.order_of_key(*s.lower_bound(make_pair(p+pr-cu, -1))) << '\n';
		sum+=a[i];
		int x=m[i]+p;
		while(x >= 1)
		{
			tree[x]--;
			x/=2;
		}
		cu+=p;
	}
	cout << ans << '\n';
	//printf("%lld", ans);
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Incorrect 2 ms 640 KB Output isn't correct
3 Incorrect 3 ms 640 KB Output isn't correct
4 Runtime error 263 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 168 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 239 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 258 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 223 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 276 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 235 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)