Submission #7509

# Submission time Handle Problem Language Result Execution time Memory
7509 2014-08-10T04:55:51 Z woqja125 Holiday (IOI14_holiday) C++
24 / 100
5000 ms 19328 KB
#include<algorithm>
#include<functional>
#include"holiday.h"

long long r1[400000];
long long r2[400000];
long long l1[400000];
long long l2[400000];

struct node
{
	long long sum;
	int cnt;
}IT[300001];

std::pair<int, int> comp[100001];
int S, N, *at;
int b;

void initIT()
{
	for (int i = 0; i < b * 2; i++) IT[i].sum = IT[i].cnt = 0;
}

void update(int x)
{
	long long s = comp[x].first;
	IT[x+=b].sum = s;
	IT[x].cnt = 1;
	while(x/=2)
	{
		IT[x].sum = IT[2*x].sum + IT[2*x+1].sum;
		IT[x].cnt = IT[2*x].cnt + IT[2*x+1].cnt;
	}
}

long long MaxKSum(int k)
{
	int x = 1;
	while(x<b)
	{
		if(k <= IT[2*x].cnt) x = 2*x;
		else
		{
			k -= IT[2*x].cnt;
			x = 2*x+1;
		}
	}
	int f = b, r = x;
	long long ans = 0;
	while(f<r)
	{
		if(f%2 == 1) ans += IT[f++].sum;
		if(r%2 == 0) ans += IT[r--].sum;
		f/=2;r/=2;
	}
	if(f==r) ans += IT[f].sum;
	return ans;
}

void setTable(int D, int dir, int dpd, long long *T)
{
	int i, j;
	for(i=0; i<=D; i++)
	{
		long long max = 0;
		initIT();
		for(j=0; j<N; j++)
		{
			if(j==0 && dir == 1) continue;
			int l = S+j*dir;
			if(l<0 || l>=N) break;
			update(at[l]);
			int t = i - j*dpd;
			if(t<=0) continue;
			long long sum = MaxKSum(t);
			if(max < sum) max = sum;
		}
		T[i] = max;
	}
}

long long findMaxAttraction(int _N, int _S, int d, int _at[])
{
	S = _S; N = _N; at = _at;
	int i;
	for(i=0; i<N; i++)
	{
		comp[i].first = at[i];
		comp[i].second = i;
	}
	std::sort(comp, comp+i, std::greater<std::pair<int, int> >() );
	for(i=0; i<N; i++)	at[comp[i].second] = i;
	for(b=1; b<N; b*=2);
	
	setTable(d, 1, 1, r1);
	setTable(d, 1, 2, r2);
	setTable(d, -1, 1, l1);
	setTable(d, -1, 2, l2);

	long long t, ans = 0;
	for(i=0; i<=d; i++)
	{
		t = r1[i] + l2[d-i];
		if(ans < t) ans = t;
		t = l1[i] + r2[d-i];
		if(ans < t) ans = t;
	}
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19328 KB Output is correct
2 Correct 0 ms 19328 KB Output is correct
3 Correct 0 ms 19320 KB Output is correct
4 Correct 0 ms 19324 KB Output is correct
5 Correct 0 ms 19324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5000 ms 19316 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4988 ms 19324 KB Output is correct
2 Correct 4808 ms 19324 KB Output is correct
3 Correct 4796 ms 19320 KB Output is correct
4 Correct 2184 ms 19324 KB Output is correct
5 Correct 1924 ms 19328 KB Output is correct
6 Correct 136 ms 19324 KB Output is correct
7 Correct 68 ms 19328 KB Output is correct
8 Correct 68 ms 19324 KB Output is correct
9 Correct 68 ms 19320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5000 ms 19320 KB Program timed out
2 Halted 0 ms 0 KB -