답안 #529385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529385 2022-02-22T23:15:52 Z flappybird 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
컴파일 오류
0 ms 0 KB
#include "elephants.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define MAX 150010
#define INF 1000000010
#define B 300

int N;
int L;
int arr[MAX];
int cnt;
map<int, int> ncnt;
int gcnt;
set<int> allv;
vector<pair<int, pi>> bukkit[MAX];

inline bool cmpp(const pair<int, pi>& p1, pair<int, pi>& p2) {
	return p1.first < p2.first;
}

//refresh bukkit
void refb(int b) {
	if (bukkit[b].empty()) return;
	sort(bukkit[b].begin(), bukkit[b].end());
	while (bukkit[b].size() && bukkit[b].back().first == INF) bukkit[b].pop_back();
	int i;
	for (i = bukkit[b].size() - 1; i >= 0; i--) {
		int x = bukkit[b][i].first;
		int e = x + L;
		int ub = lower_bound(bukkit[b].begin(), bukkit[b].end(), make_pair(e + 1, pi(0, 0)), cmpp) - bukkit[b].begin();
		if (ub == bukkit[b].size()) bukkit[b][i].second = pi(1, e);
		else bukkit[b][i].second = pi(bukkit[b][ub].second.first + 1, bukkit[b][ub].second.second);
	}
}

void ref() {
	for (int i = 0; i < gcnt; i++) bukkit[i].clear();
	gcnt = 0;
	for (auto v : allv) {
		if (bukkit[gcnt].size() == B) gcnt++;
		bukkit[gcnt].push_back(make_pair(v, pi(0, 0)));
	}
	gcnt++;
	for (int i = 0; i < gcnt; i++) refb(i);
}

int calc() {
	int en = -2, i;
	int cnt = 0;
	for (i = 0; i < gcnt; i++) {
		if (bukkit[i].empty()) continue;
		auto ub = lower_bound(bukkit[i].begin(), bukkit[i].end(), make_pair(en + 1, pi(0, 0)), cmpp) - bukkit[i].begin();
		if (ub == bukkit[i].size()) continue;
		cnt += bukkit[i][ub].second.first;
		en = bukkit[i][ub].second.second;
	}
	return cnt;
}

void init(int N, int L, int X[]) {
	::N = N;
	::L = L;
	int i;
	for (i = 0; i < N; i++) arr[i] = X[i], allv.insert(arr[i]), ncnt[arr[i]]++;
	ref();
}

int update(int i, int y) {
	cnt++;
	if (cnt == B) ref(), cnt = 0;
	int x = arr[i];
	arr[i] = y;
	ncnt[x]--;
	if (ncnt[x] == 0) {
		int i, ind = 0;
		for (i = 0; i < gcnt; i++) if (bukkit[i].size() && bukkit[i].begin()->first <= x) ind = i;
		int it = lower_bound(bukkit[ind].begin(), bukkit[ind].end(), make_pair(x, pi(0, 0)), cmpp) - bukkit[ind].begin();
		bukkit[ind][it].first = INF;
		allv.erase(x);
		refb(ind);
	}
	if (ncnt[y] == 0) {
		allv.insert(y);
		int i, ind = 0;
		for (i = 0; i < gcnt; i++) if (bukkit[i].size() && bukkit[i].begin()->first <= y) ind = i;
		bukkit[ind].push_back(make_pair(y, pi(0, 0)));
		allv.insert(y);
		refb(ind);
	}
	ncnt[y]++;
	return calc();
}

Compilation message

elephants.cpp: In function 'void refb(int)':
elephants.cpp:38:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   if (ub == bukkit[b].size()) bukkit[b][i].second = pi(1, e);
      |       ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'int calc()':
elephants.cpp:60:10: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   if (ub == bukkit[i].size()) continue;
      |       ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from elephants.cpp:2:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, std::pair<int, int> >*, std::vector<std::pair<int, std::pair<int, int> > > >; _Value = const std::pair<int, std::pair<int, int> >; _Compare = bool (*)(const std::pair<int, std::pair<int, int> >&, std::pair<int, std::pair<int, int> >&)]':
/usr/include/c++/10/bits/stl_algobase.h:1324:14:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::pair<int, std::pair<int, int> >*, std::vector<std::pair<int, std::pair<int, int> > > >; _Tp = std::pair<int, std::pair<int, int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(const std::pair<int, std::pair<int, int> >&, std::pair<int, std::pair<int, int> >&)>]'
/usr/include/c++/10/bits/stl_algo.h:2041:32:   required from '_FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare) [with _FIter = __gnu_cxx::__normal_iterator<std::pair<int, std::pair<int, int> >*, std::vector<std::pair<int, std::pair<int, int> > > >; _Tp = std::pair<int, std::pair<int, int> >; _Compare = bool (*)(const std::pair<int, std::pair<int, int> >&, std::pair<int, std::pair<int, int> >&)]'
elephants.cpp:37:92:   required from here
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: binding reference of type 'std::pair<int, std::pair<int, int> >&' to 'const std::pair<int, std::pair<int, int> >' discards qualifiers
  194 |  { return bool(_M_comp(*__it, __val)); }
      |                ~~~~~~~^~~~~~~~~~~~~~