답안 #62184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62184 2018-07-27T18:34:39 Z reality 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
컴파일 오류
0 ms 0 KB
#include "elephants.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

int n,l;
vi s;

int K;

const int oo = 2e9 + 5;

int Step = 0;

multiset < int > ss;

vi v[K * K];

vi dp[K * K];


int SZ;

void build_block(int w) {
	int sz = v[w].size();
	int index = sz;
	dp[w].resize(sz);
	for (auto & it : dp[w])
		it = 0;
	for (int j = sz - 1;j >= 0;--j) {
		while (v[w][j] + l < v[w][index - 1])
			--index;
		dp[w][j] = 1;
		if (index < sz)
			dp[w][j] += dp[w][index];
	}
}

void del(int val) {
	
	for (int i = 0;i < SZ;++i) 
		if (!v[i].empty() && v[i][0] <= val && val <= v[i].back()) {
			vi nw;
			for (auto it : v[i])
				if (it != val)
					nw.pb(it);
				else
					val = oo;
			v[i] = nw;
			build_block(i);
			break;
		}
}

void add(int val) {
	int pr = SZ - 1;
	for (int i = 0;i < SZ;++i) 
		if (!v[i].empty() && val <= v[i].back()) {
			pr = i;
			break;
		}
	vi nw;
	for (auto it : v[pr]) {
		if (it > val)
			nw.pb(val),val = oo;
		nw.pb(it);
	}
	if (val != oo)
		nw.pb(val);
	v[pr] = nw;
	build_block(pr);
}

void build(void) {
	int index = -1;
	SZ = (ss.size() + K - 1) / K;
	for (int i = 0;i < SZ;++i)
		v[i].clear(),dp[i].clear();
	for (auto it : ss) {
		++index;
		v[index / K].pb(it);
		smax(SZ,index / K + 1);
	}
	for (int i = 0;i < SZ;++i) {
		build_block(i);
	}
}

void init(int N, int L, int X[])
{
	n = N;
	K = sqrt(n);
	l = L;
	for (int i = 0;i < n;++i)
		s.pb(X[i]),ss.insert(X[i]);
}

int update(int i, int y)
{
	if (!(Step % K)) {
		build();
	}
	++Step;
	ss.erase(ss.find(s[i]));
	del(s[i]);
	ss.insert(y);
	add(s[i] = y);
	int prev = -oo;
	int ans = 0;
	for (int i = 0;i < SZ;++i) {
		if (v[i].empty())
			continue;
		int low = lower_bound(all(v[i]),prev) - v[i].begin();
		if (low != v[i].size()) {
			ans += dp[i][low];
			prev = v[i][low] + l + 1;
		}
	}
	return ans;
}

Compilation message

elephants.cpp:29:11: error: array bound is not an integer constant before ']' token
 vi v[K * K];
           ^
elephants.cpp:31:12: error: array bound is not an integer constant before ']' token
 vi dp[K * K];
            ^
elephants.cpp: In function 'void build_block(int)':
elephants.cpp:37:11: error: 'v' was not declared in this scope
  int sz = v[w].size();
           ^
elephants.cpp:39:2: error: 'dp' was not declared in this scope
  dp[w].resize(sz);
  ^~
elephants.cpp:39:2: note: suggested alternative: 'db'
  dp[w].resize(sz);
  ^~
  db
elephants.cpp: In function 'void del(int)':
elephants.cpp:54:8: error: 'v' was not declared in this scope
   if (!v[i].empty() && v[i][0] <= val && val <= v[i].back()) {
        ^
elephants.cpp: In function 'void add(int)':
elephants.cpp:70:8: error: 'v' was not declared in this scope
   if (!v[i].empty() && val <= v[i].back()) {
        ^
elephants.cpp:75:17: error: 'v' was not declared in this scope
  for (auto it : v[pr]) {
                 ^
elephants.cpp:82:2: error: 'v' was not declared in this scope
  v[pr] = nw;
  ^
elephants.cpp: In function 'void build()':
elephants.cpp:90:3: error: 'v' was not declared in this scope
   v[i].clear(),dp[i].clear();
   ^
elephants.cpp:90:16: error: 'dp' was not declared in this scope
   v[i].clear(),dp[i].clear();
                ^~
elephants.cpp:90:16: note: suggested alternative: 'db'
   v[i].clear(),dp[i].clear();
                ^~
                db
elephants.cpp:93:3: error: 'v' was not declared in this scope
   v[index / K].pb(it);
   ^
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:123:7: error: 'v' was not declared in this scope
   if (v[i].empty())
       ^
elephants.cpp:125:29: error: 'v' was not declared in this scope
   int low = lower_bound(all(v[i]),prev) - v[i].begin();
                             ^
elephants.cpp:14:16: note: in definition of macro 'all'
 #define all(s) s.begin(),s.end()
                ^
elephants.cpp:127:11: error: 'dp' was not declared in this scope
    ans += dp[i][low];
           ^~
elephants.cpp:127:11: note: suggested alternative: 'db'
    ans += dp[i][low];
           ^~
           db