Submission #48439

# Submission time Handle Problem Language Result Execution time Memory
48439 2018-05-13T14:04:10 Z aleksami Vudu (COCI15_vudu) C++14
42 / 140
1000 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 1000005
typedef long long ll;
ll a[MAXN];
int tree[2*MAXN];
vector <ll> v;

void update(int node,int left,int right,int idx,int val)
{
	if(left==right)
	{
		tree[node]+=val;
		return ;
	}
	int mid=left+right>>1;
	if(idx <= mid)update(node*2,left,mid,idx,val);
	if(idx > mid)update(node*2+1,mid+1,right,idx,val);
	tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node,int left,int right,int l,int r)
{
	if(left >= l && right <= r)return tree[node];
	int mid = left+right>>1;
	int ans=0;
	if(l <= mid)ans+=query(node*2,left,mid,l,r);
	if(r > mid)ans+=query(node*2+1,mid+1,right,l,r);
	return ans;
}

set <ll> st;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	ll p;
	cin >> p;
	for(int i = 1; i <= n; i++)
	{
		a[i]-=p;
	}
	//v.push_back(0LL);
	st.insert(0LL);
	for(int i = 1; i <= n; i++)
	{
		a[i]+=a[i-1];
		st.insert(a[i]);//v.push_back(a[i]);
	}
	for(auto x:st)v.push_back(x),st.erase(x);
	//sort(v.begin(),v.end());
	ll ans=0;
	for(int i = 0; i <= n; i++)
	{
		a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
		if(i!=0)update(1,0,v.size()-1,a[i-1],1);
		ans += 1LL*query(1,0,v.size()-1,0,a[i]);
	}
	cout << ans;
	return 0;
}

Compilation message

vudu.cpp: In function 'void update(int, int, int, int, int)':
vudu.cpp:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=left+right>>1;
          ~~~~^~~~~~
vudu.cpp: In function 'int query(int, int, int, int, int)':
vudu.cpp:25:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = left+right>>1;
            ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 5 ms 1044 KB Output is correct
4 Execution timed out 1076 ms 65536 KB Time limit exceeded
5 Incorrect 661 ms 65536 KB Output isn't correct
6 Execution timed out 1070 ms 65536 KB Time limit exceeded
7 Runtime error 912 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Execution timed out 1054 ms 65536 KB Time limit exceeded
9 Execution timed out 1038 ms 65536 KB Time limit exceeded
10 Execution timed out 1078 ms 65536 KB Time limit exceeded