結果

問題 No.318 学学学学学
ユーザー nksk38nksk38
提出日時 2017-10-06 21:19:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,128 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 92,268 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-04-28 10:23:51
合計ジャッジ時間 6,880 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,248 KB
testcase_01 AC 32 ms
6,144 KB
testcase_02 AC 39 ms
6,656 KB
testcase_03 AC 24 ms
5,504 KB
testcase_04 AC 34 ms
6,400 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int n,sz;
ll node[100010*2], lazy[100010*2];
bool lazyFlag[100010*2];

struct LazySegmentTree {
	LazySegmentTree(int n) {
		sz = 1;
		while (n > sz )sz *= 2;
		for (int i = 0; i < 2 * sz - 1; i++)lazy[i] = -1;
	}
	void lazy_evaluate_node(int k, int l, int r) {
		if (lazy[k] != -1) { 
			node[k] = lazy[k] * (r - l); 
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k]; 
				lazy[k * 2 + 2] = lazy[k]; 
			}
			lazy[k] = -1;
		}
	}
	
	void update(int a, int b, ll v, int k = 0, int l = 0, int r = sz) {
		lazy_evaluate_node(k, l, r); 
		if (r <= a || b <= l)return; 
		if (a <= l && r <= b) {
			lazy[k] = v;
			lazy_evaluate_node(k, l, r);
		}
		else {
			update(a, b, v, k * 2 + 1, l, (l + r) / 2);
			update(a, b, v, k * 2 + 2, (l + r) / 2, r);
			node[k] = node[k * 2 + 1] + node[k * 2 + 2];
		}
	}
	ll get(int a, int b, int k = 0, int l = 0, int r = sz) {
		lazy_evaluate_node(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return node[k];
		ll x = get(a, b, k * 2 + 1, l, (l + r) / 2); 
		ll y = get(a, b, k * 2 + 2, (l + r) / 2, r);
		return x + y;
	}
};

int main()
{
	cin >> n;

	vector<int> a(n);
	rep(i, n)cin >> a[i];

	map<int, int>left, right;
	rep(i, n) {
		if (left.count(a[i]) == 0)
			left[a[i]] = i;
	}

	for (int i = n - 1; i >= 0; i--) {
		if (right.count(a[i]) == 0) {
			right[a[i]] = i;
		}
	}

	LazySegmentTree seg(n);
	rep(i, n)seg.update(i,i+1,a[i]);

	for (auto v : left) {
		if (right.count(v.first)) {
			seg.update(v.second, right[v.first] + 1, v.first);
		}
	}

	rep(i, n)printf("%d ",(int)seg.get(i,i+1));
	printf("\n");
	return 0;
}
0