結果

問題 No.318 学学学学学
ユーザー nksk38nksk38
提出日時 2017-10-06 21:21:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 95,632 KB
実行使用メモリ 17,052 KB
最終ジャッジ日時 2023-09-04 20:51:42
合計ジャッジ時間 5,453 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,688 KB
testcase_01 AC 38 ms
7,812 KB
testcase_02 AC 44 ms
8,192 KB
testcase_03 AC 29 ms
7,204 KB
testcase_04 AC 39 ms
7,828 KB
testcase_05 AC 259 ms
16,972 KB
testcase_06 AC 203 ms
12,304 KB
testcase_07 AC 170 ms
10,684 KB
testcase_08 AC 142 ms
9,608 KB
testcase_09 AC 122 ms
8,520 KB
testcase_10 AC 99 ms
7,656 KB
testcase_11 AC 258 ms
17,052 KB
testcase_12 AC 173 ms
12,256 KB
testcase_13 AC 147 ms
10,804 KB
testcase_14 AC 126 ms
9,636 KB
testcase_15 AC 108 ms
8,508 KB
testcase_16 AC 88 ms
7,656 KB
testcase_17 AC 142 ms
12,260 KB
testcase_18 AC 118 ms
12,492 KB
testcase_19 AC 141 ms
12,256 KB
testcase_20 AC 71 ms
7,740 KB
testcase_21 AC 2 ms
5,612 KB
testcase_22 AC 2 ms
5,536 KB
testcase_23 AC 2 ms
5,592 KB
testcase_24 AC 2 ms
5,612 KB
testcase_25 AC 2 ms
5,588 KB
testcase_26 AC 2 ms
5,592 KB
testcase_27 AC 2 ms
5,536 KB
testcase_28 AC 2 ms
5,536 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;

const int MAX_N = 1 << 18;
int n,sz;
ll node[MAX_N], lazy[MAX_N];

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