Submission #67220

# Submission time Handle Problem Language Result Execution time Memory
67220 2018-08-13T16:29:28 Z zetapi Dancing Elephants (IOI11_elephants) C++14
100 / 100
4648 ms 94056 KB
#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr ::iterator 

typedef pair<int,int>  pii;

const int MAX=2e6;
const int len=400;

ll N,K,qcnt,pos[MAX],lol[MAX];

struct data
{
	int size;
	ll  arr[1000],dp[1000],right[1000];
	data()
	{
		size=0;
	}
	void cal()
	{
		int ptr=size;
		for(int A=size-1;A>=0;A--)
		{
			while(arr[ptr-1]-arr[A]>K)
				--ptr;
			if(ptr==size)
			{
				dp[A]=1;
				right[A]=arr[A]+K;
			}
			else
			{
				dp[A]=1+dp[ptr];
				right[A]=right[ptr];
			}
		}
		return ;
	}
	void insert(int val)
	{
		int B=0;
		for(int A=size-1;A>=0;A--)
		{
			if(arr[A]<=val)
			{
				B=A+1;
				break;
			}
		}
		for(int C=size;C>B;C--)
			arr[C]=arr[C-1];
		arr[B]=val;
		++size;
		return ;
	}
	void remove(int val)
	{
		for(int A=0;A<size;A++)
		{
			if(arr[A]==val)
			{
				for(int B=A;B<size-1;B++)
					arr[B]=arr[B+1];
				break;
			}
		}
		--size;
		return ;
	}
}	block[400];

void init(int n,int l,int X[])
{
	N=n;
	K=l;
	for(int A=0;A<N;A++)
	{
		pos[A]=X[A];
		block[A/len].arr[block[A/len].size]=X[A];
		block[A/len].size++;
	}
	for(int A=0;block[A].size>0;A++)
		block[A].cal();
	return ;
}

int update(int idx,int val)
{
	++qcnt;
	int B;
	for(B=0;block[B].size>0;B++)
	{
		if(block[B].arr[0]>pos[idx])
			break;
	}
	if(B)
		B--;
	block[B].remove(pos[idx]);
	block[B].cal();
	pos[idx]=val;
	for(B=0;block[B].size>0;B++)
	{
		if(block[B].arr[0]>pos[idx])
			break;
	}
	if(B)
		B--;
	block[B].insert(pos[idx]);
	block[B].cal();
	ll covered=-1,res=0;
	for(int A=0;block[A].size>0;A++)
	{
		int cur=upper_bound(block[A].arr,block[A].arr+block[A].size,covered)-block[A].arr;
		if(cur==block[A].size)
			continue;
		res+=block[A].dp[cur];
		covered=block[A].right[cur];
	}
	if(qcnt==len-2)
	{
		int cur=0;
		for(int A=0;block[A].size>0;A++)
		{
			for(int B=0;B<block[A].size;B++)
				lol[cur++]=block[A].arr[B];
			block[A].size=0;
		}
		for(int A=0;A<cur;A++)
		{
			block[A/len].arr[block[A/len].size]=lol[A];
			block[A/len].size++;
		}
		for(int A=0;block[A].size>0;A++)
			block[A].cal();
		qcnt=0;
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
3 Correct 3 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
3 Correct 3 ms 2128 KB Output is correct
4 Correct 5 ms 2128 KB Output is correct
5 Correct 4 ms 2128 KB Output is correct
6 Correct 4 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
3 Correct 3 ms 2128 KB Output is correct
4 Correct 5 ms 2128 KB Output is correct
5 Correct 4 ms 2128 KB Output is correct
6 Correct 4 ms 2128 KB Output is correct
7 Correct 299 ms 3492 KB Output is correct
8 Correct 305 ms 3792 KB Output is correct
9 Correct 431 ms 5964 KB Output is correct
10 Correct 383 ms 5980 KB Output is correct
11 Correct 473 ms 5980 KB Output is correct
12 Correct 626 ms 6104 KB Output is correct
13 Correct 483 ms 6104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
3 Correct 3 ms 2128 KB Output is correct
4 Correct 5 ms 2128 KB Output is correct
5 Correct 4 ms 2128 KB Output is correct
6 Correct 4 ms 2128 KB Output is correct
7 Correct 299 ms 3492 KB Output is correct
8 Correct 305 ms 3792 KB Output is correct
9 Correct 431 ms 5964 KB Output is correct
10 Correct 383 ms 5980 KB Output is correct
11 Correct 473 ms 5980 KB Output is correct
12 Correct 626 ms 6104 KB Output is correct
13 Correct 483 ms 6104 KB Output is correct
14 Correct 404 ms 6104 KB Output is correct
15 Correct 514 ms 6104 KB Output is correct
16 Correct 1109 ms 6424 KB Output is correct
17 Correct 1077 ms 7852 KB Output is correct
18 Correct 1210 ms 7852 KB Output is correct
19 Correct 844 ms 7852 KB Output is correct
20 Correct 1109 ms 7852 KB Output is correct
21 Correct 1063 ms 7852 KB Output is correct
22 Correct 752 ms 7852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
3 Correct 3 ms 2128 KB Output is correct
4 Correct 5 ms 2128 KB Output is correct
5 Correct 4 ms 2128 KB Output is correct
6 Correct 4 ms 2128 KB Output is correct
7 Correct 299 ms 3492 KB Output is correct
8 Correct 305 ms 3792 KB Output is correct
9 Correct 431 ms 5964 KB Output is correct
10 Correct 383 ms 5980 KB Output is correct
11 Correct 473 ms 5980 KB Output is correct
12 Correct 626 ms 6104 KB Output is correct
13 Correct 483 ms 6104 KB Output is correct
14 Correct 404 ms 6104 KB Output is correct
15 Correct 514 ms 6104 KB Output is correct
16 Correct 1109 ms 6424 KB Output is correct
17 Correct 1077 ms 7852 KB Output is correct
18 Correct 1210 ms 7852 KB Output is correct
19 Correct 844 ms 7852 KB Output is correct
20 Correct 1109 ms 7852 KB Output is correct
21 Correct 1063 ms 7852 KB Output is correct
22 Correct 752 ms 7852 KB Output is correct
23 Correct 3437 ms 13676 KB Output is correct
24 Correct 3671 ms 18668 KB Output is correct
25 Correct 2787 ms 23612 KB Output is correct
26 Correct 3093 ms 28696 KB Output is correct
27 Correct 3049 ms 33604 KB Output is correct
28 Correct 1672 ms 33604 KB Output is correct
29 Correct 1608 ms 33604 KB Output is correct
30 Correct 1602 ms 33604 KB Output is correct
31 Correct 1450 ms 36340 KB Output is correct
32 Correct 3126 ms 49872 KB Output is correct
33 Correct 3189 ms 53692 KB Output is correct
34 Correct 2919 ms 58320 KB Output is correct
35 Correct 2727 ms 63240 KB Output is correct
36 Correct 2958 ms 67704 KB Output is correct
37 Correct 3618 ms 73408 KB Output is correct
38 Correct 3089 ms 76336 KB Output is correct
39 Correct 3069 ms 81040 KB Output is correct
40 Correct 3219 ms 84728 KB Output is correct
41 Correct 4232 ms 89500 KB Output is correct
42 Correct 4648 ms 94056 KB Output is correct