結果
| 問題 | No.318 学学学学学 |
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2016-09-24 17:40:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 3,175 bytes |
| 記録 | |
| コンパイル時間 | 2,095 ms |
| コンパイル使用メモリ | 180,148 KB |
| 実行使用メモリ | 12,724 KB |
| 最終ジャッジ日時 | 2024-06-22 18:02:38 |
| 合計ジャッジ時間 | 5,505 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename V> struct SegTreeLazy {
static const V zero = 0;
static const V def = 0;
struct Node {
V dat;
V lazy;
bool flag;
Node() : dat(def), lazy(zero), flag(false) {}
};
static V merge(const V &l, const V &r) {
return l + r;
}
static V mul(const V &v, const int a) {
return v * a;
}
const int N;
vector<Node> seg;
SegTreeLazy(int size) : N(p2(size)), seg(N * 2) {};
void update(int a, int b, V v) {
update(a, b, v, 0, 0, N);
}
void push(int k, int l, int r) {
if (seg[k].flag) {
seg[k].dat = seg[k].lazy;
if (r - l > 1) {
seg[k * 2 + 1].lazy = seg[k].lazy;
seg[k * 2 + 2].lazy = seg[k].lazy;
seg[k * 2 + 1].flag = true;
seg[k * 2 + 2].flag = true;
}
seg[k].lazy = zero;
seg[k].flag = false;
}
}
V query(int a, int b) {
return query(a, b, 0, 0, N);
}
private:
void update(int a, int b, V v, int k, int l, int r) {
push(k, l, r);
if (r <= a || b <= l) return;
if (a <= l && r <= b) {
seg[k].lazy = v;
seg[k].flag = true;
push(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);
seg[k].dat = merge(seg[k * 2 + 1].dat, seg[k * 2 + 2].dat);
}
}
V query(int a, int b, int k, int l, int r) {
push(k, l, r);
if (r <= a || b <= l) return 0;
if (a <= l && r <= b) return seg[k].dat;
V x = query(a, b, k * 2 + 1, l, (l + r) / 2);
V y = query(a, b, k * 2 + 2, (l + r) / 2, r);
return merge(x, y);
}
static int p2(int n, int m=1) { return m >= n ? m : p2(n, m * 2); }
};
void Main() {
int N;
scanf("%d", &N);
map<int, pii> pos;
rep(i, N) {
int a;
scanf("%d", &a);
if (pos.count(a)==0) pos[a].fst = pos[a].snd = i;
else pos[a].snd = i;
}
SegTreeLazy<int> seg(N);
forr(nfl, pos) {
int f, l;
tie(f, l) = nfl.snd;
seg.update(f, l+1, nfl.fst);
//cout << "seg.seg:"; rep(ii,SZ(seg.seg)) cout << ' ' << seg.seg[ii].lazy; cout << endl;
}
rep(i, N) {
_p("%d ", seg.query(i, i+1));
}
_p("\n");
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
しらっ亭