답안 #356062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
356062 2021-01-23T06:49:38 Z tengiz05 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
4756 ms 12204 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=1.5e5, B=900, mxBC=(mxN-1)/B+1;
int n, l, *x, uc, bc, r[mxBC];
map<int, int> mp;
vector<int> v[mxBC];
vector<array<int, 2>> w[mxBC];
void init(int N, int L, int X[]) {
	n=N, l=L, x=X;
	for(int i=0; i<n; ++i)
		++mp[x[i]];
}
void bb(int i) {
	w[i]=vector<array<int, 2>>(v[i].size());
	for(int j1=(int)v[i].size()-1, j2=v[i].size(); ~j1; --j1) {
		while(v[i][j2-1]>v[i][j1]+l)
			--j2;
		w[i][j1]=j2<v[i].size()?array<int, 2>{w[i][j2][0]+1, w[i][j2][1]}:array<int, 2>{1, v[i][j1]+l};
	}
}
void bld() {
	bc=0;
	for(pair<int, int> p : mp) {
		if(!bc||v[bc-1].size()>=B)
			v[bc++].clear();
		v[bc-1].push_back(p.first);
	}
	for(int i=0; i<bc; ++i) {
		r[i]=i+1<bc?v[i+1][0]-1:1e9;
		bb(i);
	}
}
 
void upd(int x, bool a) {
	int c=-1;
	while(x>r[++c]);
	int p=lower_bound(v[c].begin(), v[c].end(), x)-v[c].begin();
	if(a)
		v[c].insert(v[c].begin()+p, x);
	else
		v[c].erase(v[c].begin()+p);
	bb(c);
}
 
int update(int i, int y) {
	if(uc++%B==0)
		bld();
	--mp[x[i]];
	if(!mp[x[i]]) {
		upd(x[i], 0);
		mp.erase(x[i]);
	}
	if(!mp[y])
		upd(y, 1);
	++mp[y];
	x[i]=y;
	int a=0;
	for(int i=0, c=-1; i<bc; ++i) {
		int p=upper_bound(v[i].begin(), v[i].end(), c)-v[i].begin();
		if(p<v[i].size()) {
			a+=w[i][p][0];
			c=w[i][p][1];
		}
	}
	return a;
}

Compilation message

elephants.cpp: In function 'void bb(int)':
elephants.cpp:19:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   w[i][j1]=j2<v[i].size()?array<int, 2>{w[i][j2][0]+1, w[i][j2][1]}:array<int, 2>{1, v[i][j1]+l};
      |            ~~^~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:61:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   if(p<v[i].size()) {
      |      ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 455 ms 2072 KB Output is correct
8 Correct 447 ms 2284 KB Output is correct
9 Correct 521 ms 4564 KB Output is correct
10 Correct 461 ms 4460 KB Output is correct
11 Correct 471 ms 4388 KB Output is correct
12 Correct 959 ms 4436 KB Output is correct
13 Correct 499 ms 4460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 455 ms 2072 KB Output is correct
8 Correct 447 ms 2284 KB Output is correct
9 Correct 521 ms 4564 KB Output is correct
10 Correct 461 ms 4460 KB Output is correct
11 Correct 471 ms 4388 KB Output is correct
12 Correct 959 ms 4436 KB Output is correct
13 Correct 499 ms 4460 KB Output is correct
14 Correct 342 ms 3564 KB Output is correct
15 Correct 676 ms 2852 KB Output is correct
16 Correct 1495 ms 4640 KB Output is correct
17 Correct 1583 ms 6224 KB Output is correct
18 Correct 1719 ms 6008 KB Output is correct
19 Correct 774 ms 6024 KB Output is correct
20 Correct 1611 ms 6052 KB Output is correct
21 Correct 1557 ms 6016 KB Output is correct
22 Correct 726 ms 6016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 455 ms 2072 KB Output is correct
8 Correct 447 ms 2284 KB Output is correct
9 Correct 521 ms 4564 KB Output is correct
10 Correct 461 ms 4460 KB Output is correct
11 Correct 471 ms 4388 KB Output is correct
12 Correct 959 ms 4436 KB Output is correct
13 Correct 499 ms 4460 KB Output is correct
14 Correct 342 ms 3564 KB Output is correct
15 Correct 676 ms 2852 KB Output is correct
16 Correct 1495 ms 4640 KB Output is correct
17 Correct 1583 ms 6224 KB Output is correct
18 Correct 1719 ms 6008 KB Output is correct
19 Correct 774 ms 6024 KB Output is correct
20 Correct 1611 ms 6052 KB Output is correct
21 Correct 1557 ms 6016 KB Output is correct
22 Correct 726 ms 6016 KB Output is correct
23 Correct 3130 ms 11896 KB Output is correct
24 Correct 3218 ms 11972 KB Output is correct
25 Correct 2259 ms 11756 KB Output is correct
26 Correct 2511 ms 12028 KB Output is correct
27 Correct 2830 ms 11920 KB Output is correct
28 Correct 2154 ms 2940 KB Output is correct
29 Correct 1970 ms 3052 KB Output is correct
30 Correct 2107 ms 3060 KB Output is correct
31 Correct 2011 ms 3000 KB Output is correct
32 Correct 2694 ms 11904 KB Output is correct
33 Correct 1128 ms 11884 KB Output is correct
34 Correct 2438 ms 11896 KB Output is correct
35 Correct 1217 ms 11824 KB Output is correct
36 Correct 75 ms 2796 KB Output is correct
37 Correct 1542 ms 12140 KB Output is correct
38 Correct 2366 ms 11896 KB Output is correct
39 Correct 2509 ms 12016 KB Output is correct
40 Correct 2440 ms 11904 KB Output is correct
41 Correct 4535 ms 12204 KB Output is correct
42 Correct 4756 ms 12108 KB Output is correct