結果

問題 No.318 学学学学学
ユーザー climpetclimpet
提出日時 2015-12-11 00:32:23
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,676 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 78,356 KB
実行使用メモリ 814,484 KB
最終ジャッジ日時 2023-10-13 10:43:42
合計ジャッジ時間 4,450 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;

typedef pair<int,int> pii;

struct intset{
	typedef unsigned long long ULL;
	vector<vector<ULL> > val;
	int n;
	intset() : n() {}
	explicit intset(int m){
		init(m);
	}
	void init(int m){
		n = m;
		val.clear();
		do{
			int t = (n + 63) >> 6;
			val.emplace_back(t);
			m = t;
		} while(m > 1);
	}
	bool contains(int x) const{
		if(x < 0 || x >= n){ return false; }
		return val[0][x >> 6] >> (x & 63) & 1;
	}
	bool insert(int x){
		if(x < 0 || x >= n){ return false; }
		if(contains(x)){ return false; }
		int h = val.size();
		bool cont = true;
		for(int i = 0; cont && i < h; ++i){
			ULL &v = val[i][x >> 6];
			cont = !v;
			v |= 1ull << (x & 63);
			x >>= 6;
		}
		return true;
	}
	bool erase(int x){
		if(x < 0 || x >= n){ return false; }
		if(!contains(x)){ return false; }
		int h = val.size();
		bool cont = true;
		for(int i = 0; cont && i < h; ++i){
			ULL &v = val[i][x >> 6];
			v &= ~(1ull << (x & 63));
			cont = !v;
			x >>= 6;
		}
		return true;
	}
	int successor(int x) const{
		if(x >= n){ return INT_MAX; }
		if(x < 0){
			if(contains(0)){ return 0; }
			x = 0;
		}
		int h = val.size();
		int i;
		for(i = 0; i < h; ++i){
			int t = x >> 6;
			ULL v = val[i][t];
			v &= ~((2ull << (x & 63)) - 1);
			if(v){
				x = (t << 6) + __builtin_ctzll(v);
				break;
			}
			x = t;
		}
		if(i == h){ return INT_MAX; }
		while(i > 0){
			--i;
			x = (x << 6) + __builtin_ctzll(val[i][x]);
		}
		return x;
	}
	int predecessor(int x) const{
		if(x <= 0){ return INT_MIN; }
		if(x >= n){
			if(contains(n - 1)){ return n - 1; }
			x = n - 1;
		}
		int h = val.size();
		int i;
		for(i = 0; i < h; ++i){
			int t = x >> 6;
			ULL v = val[i][t];
			v &= (1ull << (x & 63)) - 1;
			if(v){
				x = (t << 6) + 63 - __builtin_clzll(v);
				break;
			}
		}
		if(i == h){ return INT_MIN; }
		while(i > 0){
			--i;
			x = (x << 6) + 63 - __builtin_clzll(val[i][x]);
		}
		return x;
	}
};

int main(){
	const int INF = 1010101010;

	int n;
	scanf("%d", &n);
	vector<pii> v(n + 1);
	for(int i = 0; i < n; ++i){
		int x;
		scanf("%d", &x);
		v[i] = pii(-x, i);
	}
	v[n] = pii(INF, INF);
	sort(v.begin(), v.end());

	intset is(n);
	for(int i = 0; i < n; ++i){
		is.insert(i);
	}
	vector<int> b(n);

	for(int i = 0; i < n; ){
		int j;
		int val = -v[i].first;
		for(j = i + 1; v[j].first == -val; ++j);
		int l = v[i].second, r = v[j - 1].second;
		int x;
		while((x = is.successor(l - 1)) <= r){
			b[x] = val;
			is.erase(x);
		}
		i = j;
	}

	for(int i = 0; i < n; ++i){
		printf("%d%c", b[i], i + 1 == n ? '\n' : ' ');
	}
}
0