제출 #785985

#제출 시각아이디문제언어결과실행 시간메모리
785985Cyber_Wolf코끼리 (Dancing Elephants) (IOI11_elephants)C++17
50 / 100
9044 ms3404 KiB
// Problem: P5 - Dancing Elephants
// Contest: DMOJ - IOI '11
// URL: https://dmoj.ca/problem/ioi11p5
// Memory Limit: 256 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

using namespace std;

int n, l;
int x[150000], o[150000];
// int idx[150000];

void init(int N, int L, int X[])
{
	n = N, l = L;
	for(int i = 0; i < N; i++)
	{
		x[i] = X[i];	
		o[i] = x[i];
	}
	return;
}

int update(int i, int y)
{
	int p = lower_bound(x, x+n, o[i])-x;
	x[p] = y;
	o[i] = y;
	while(p && x[p] < x[p-1])	
	{
		swap(x[p], x[p-1]);
		p--;
	}
	while(p+1 < n && x[p] > x[p+1])
	{
		swap(x[p], x[p+1]);
		p++;
	}
	int beg = x[0];
	int ans = 1;
	for(int j = 0; j < n; j++)
	{
		if(x[j]-beg > l)
		{
			beg = x[j];
			ans++;
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...