結果

問題 No.318 学学学学学
ユーザー femtofemto
提出日時 2017-02-20 17:38:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 89,052 KB
実行使用メモリ 18,724 KB
最終ジャッジ日時 2023-09-04 20:39:03
合計ジャッジ時間 5,102 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
8,356 KB
testcase_01 AC 24 ms
9,632 KB
testcase_02 AC 28 ms
9,792 KB
testcase_03 AC 19 ms
9,044 KB
testcase_04 AC 25 ms
9,448 KB
testcase_05 AC 174 ms
18,420 KB
testcase_06 AC 145 ms
13,212 KB
testcase_07 AC 117 ms
11,244 KB
testcase_08 AC 104 ms
10,380 KB
testcase_09 AC 84 ms
9,448 KB
testcase_10 AC 63 ms
8,152 KB
testcase_11 AC 175 ms
18,724 KB
testcase_12 AC 118 ms
12,916 KB
testcase_13 AC 99 ms
11,128 KB
testcase_14 AC 85 ms
10,004 KB
testcase_15 AC 72 ms
9,024 KB
testcase_16 AC 58 ms
8,108 KB
testcase_17 AC 96 ms
12,924 KB
testcase_18 AC 88 ms
12,928 KB
testcase_19 AC 94 ms
13,056 KB
testcase_20 AC 56 ms
8,228 KB
testcase_21 AC 3 ms
7,496 KB
testcase_22 AC 3 ms
7,452 KB
testcase_23 AC 4 ms
7,436 KB
testcase_24 AC 4 ms
7,732 KB
testcase_25 AC 4 ms
7,428 KB
testcase_26 AC 4 ms
7,660 KB
testcase_27 AC 4 ms
7,452 KB
testcase_28 AC 4 ms
7,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 1 << 17;
const int def = 0;
const int INF = 1 << 25;

struct SumSegTree3 {
	int n;
	struct S {
		bool flag;
		ll dat;
		S() : dat(0), flag(false) {}
	};

	S node[2 * MAX_N - 1];
	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
	}

	void propagate(int k) {
		if(!node[k].flag) return;
		node[k].flag = false;
		if(2 * k + 1 < 2 * n - 1) {
			S& t = node[k];
			S& l = node[2 * k + 1];
			S& r = node[2 * k + 2];
			l.flag = r.flag = true;
			l.dat = r.dat = t.dat / 2;
		}
	}

	void update(int a, int b, ll x) { update(a, b, x, 0, 0, n); }

	void update(int a, int b, ll x, int k, int l, int r) {
		propagate(k);
		if(r <= a || b <= l) return;
		if(a <= l && r <= b) {
			node[k].dat = (r - l) * x;
			node[k].flag = true;
			propagate(k);
			return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		// merge
		node[k].dat = node[2 * k + 1].dat + node[2 * k + 2].dat;
	}

	ll query(int a, int b) { return query(a, b, 0, 0, n); }

	ll query(int a, int b, int k, int l, int r) {
		propagate(k);
		if(r <= a || b <= l) return 0;
		if(a <= l && r <= b) return node[k].dat;
		ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return vl + vr;
	}
};

SumSegTree3 st;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	st.init(N);

	map<int, vector<int>> m;
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		st.update(i, i + 1, a);
		m[a].push_back(i);
	}

	for(auto& v : m) {
		vector<int>& a = v.second;
		sort(a.begin(), a.end());
		int l = a.front(), r = a.back();
		st.update(l, r + 1, v.first);
	}

	for(int i = 0; i < N; i++) {
		cout << st.query(i, i + 1) << " ";
	}
	cout << endl;
}
0