답안 #198284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198284 2020-01-25T11:38:18 Z dennisstar 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
3525 ms 12592 KB
#include "elephants.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define sq(X) ((X)*(X))
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int N, L, X[150010], im[150010], Q;
int A[410][810], sz[410];
int B[410][810], C[410][810];
 
void myinit() {
	for (int i=0, k=0; i<=N/400; i++) for (int j=0; j<sz[i]; j++) im[k++]=A[i][j];
	memset(sz, 0, sizeof(sz));
	for (int i=0; i<N; i++) A[i/400][sz[i/400]++]=im[i];
	for (int i=0; i<=N/400; i++) for (int j=sz[i]-1, k=sz[i]-1; j>=0; j--) {
		while (k&&A[i][k-1]>A[i][j]+L) k--;
		if (A[i][j]+L>=A[i][k]) B[i][j]=A[i][j], C[i][j]=1;
		else B[i][j]=B[i][k], C[i][j]=C[i][k]+1;
	}
}

void init(int N_, int L_, int X_[]) {
	N=N_; L=L_; for (int i=0; i<N; i++) { X[i]=X_[i]; A[i/400][sz[i/400]++]=X[i]; }
	for (int i=0; ; i++) if (!sz[i]) { A[i][0]=(1<<30); break; }
	myinit();
}

void del(int I, int J) {
	for (int i=J+1; i<sz[I]; i++) A[I][i-1]=A[I][i];
	sz[I]--;
	if (!sz[I]) A[I][0]=(1<<30);
	for (int i=sz[I]-1, j=sz[I]-1; i>=0; i--) {
		while (j&&A[I][j-1]>A[I][i]+L) j--;
		if (A[I][i]+L>=A[I][j]) B[I][i]=A[I][i], C[I][i]=1;
		else B[I][i]=B[I][j], C[I][i]=C[I][j]+1;
	}
}

void ins(int I, int V) {
	int k; for (k=sz[I]-1; k>=0; k--) {
		if (A[I][k]<=V) { A[I][k+1]=V; break; }
		A[I][k+1]=A[I][k];
	}
	if (k<0) A[I][0]=V;
	sz[I]++;
	for (int i=sz[I]-1, j=sz[I]-1; i>=0; i--) {
		while (j&&A[I][j-1]>A[I][i]+L) j--;
		if (A[I][i]+L>=A[I][j]) B[I][i]=A[I][i], C[I][i]=1;
		else B[I][i]=B[I][j], C[I][i]=C[I][j]+1;
	}
}

int update(int I, int Y) {
	Q++;
	if (Q%399==0) myinit();
	for (int i=0; i<=N/400; i++) if (sz[i] && X[I]<A[i+1][0]) {
		del(i, lower_bound(A[i], A[i]+sz[i], X[I])-A[i]);
		break;
	}
	for (int i=0; i<=N/400; i++) if (sz[i] && Y<=A[i+1][0]) {
		ins(i, Y);
		break;
	}
	X[I]=Y;
	int lst=-L-10, ans=0;
	for (int i=0; i<=N/400; i++) if (sz[i]) {
		int ub=upper_bound(A[i], A[i]+sz[i], lst+L)-A[i];
		if (ub>=sz[i]) continue;
		ans+=C[i][ub]; lst=B[i][ub];
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 320 ms 1400 KB Output is correct
8 Correct 339 ms 1656 KB Output is correct
9 Correct 382 ms 2776 KB Output is correct
10 Correct 362 ms 2780 KB Output is correct
11 Correct 374 ms 2812 KB Output is correct
12 Correct 604 ms 2808 KB Output is correct
13 Correct 367 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 320 ms 1400 KB Output is correct
8 Correct 339 ms 1656 KB Output is correct
9 Correct 382 ms 2776 KB Output is correct
10 Correct 362 ms 2780 KB Output is correct
11 Correct 374 ms 2812 KB Output is correct
12 Correct 604 ms 2808 KB Output is correct
13 Correct 367 ms 2808 KB Output is correct
14 Correct 349 ms 1852 KB Output is correct
15 Correct 531 ms 2064 KB Output is correct
16 Correct 1010 ms 3068 KB Output is correct
17 Correct 1046 ms 3804 KB Output is correct
18 Correct 1123 ms 3756 KB Output is correct
19 Correct 636 ms 3728 KB Output is correct
20 Correct 1042 ms 3896 KB Output is correct
21 Correct 991 ms 3704 KB Output is correct
22 Correct 610 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 320 ms 1400 KB Output is correct
8 Correct 339 ms 1656 KB Output is correct
9 Correct 382 ms 2776 KB Output is correct
10 Correct 362 ms 2780 KB Output is correct
11 Correct 374 ms 2812 KB Output is correct
12 Correct 604 ms 2808 KB Output is correct
13 Correct 367 ms 2808 KB Output is correct
14 Correct 349 ms 1852 KB Output is correct
15 Correct 531 ms 2064 KB Output is correct
16 Correct 1010 ms 3068 KB Output is correct
17 Correct 1046 ms 3804 KB Output is correct
18 Correct 1123 ms 3756 KB Output is correct
19 Correct 636 ms 3728 KB Output is correct
20 Correct 1042 ms 3896 KB Output is correct
21 Correct 991 ms 3704 KB Output is correct
22 Correct 610 ms 3704 KB Output is correct
23 Correct 2910 ms 7496 KB Output is correct
24 Correct 3050 ms 12592 KB Output is correct
25 Correct 2206 ms 12408 KB Output is correct
26 Correct 2585 ms 12536 KB Output is correct
27 Correct 2626 ms 12364 KB Output is correct
28 Correct 1582 ms 5240 KB Output is correct
29 Correct 1495 ms 5260 KB Output is correct
30 Correct 1589 ms 5260 KB Output is correct
31 Correct 1497 ms 5260 KB Output is correct
32 Correct 2494 ms 12024 KB Output is correct
33 Correct 2310 ms 11264 KB Output is correct
34 Correct 2228 ms 12152 KB Output is correct
35 Correct 2118 ms 12480 KB Output is correct
36 Correct 2063 ms 12024 KB Output is correct
37 Correct 2707 ms 12408 KB Output is correct
38 Correct 2383 ms 11140 KB Output is correct
39 Correct 2271 ms 12188 KB Output is correct
40 Correct 2302 ms 11244 KB Output is correct
41 Correct 3503 ms 11932 KB Output is correct
42 Correct 3525 ms 12160 KB Output is correct