제출 #936697

#제출 시각아이디문제언어결과실행 시간메모리
936697kitlixStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
158 ms22772 KiB
#include <bits/stdc++.h> #define int long long using namespace std; struct SegTree { int h = 0; vector<int> flag; vector<int> resarr; SegTree(int n) { while ((1 << h) < n) h += 1; flag.resize((1 << (h + 1)), -1); resarr.resize(n); } void upd(int v, int vl, int vr, int l, int r, int val) { if (vl >= r || vr <= l) return; if (l <= vl && vr <= r) { flag[v] = val; return; } int vm = (vl + vr) / 2; upd(2 * v, vl, vm, l, r, val); upd(2 * v + 1, vm, vr, l, r, val); } void upd(int l, int r, int val) { upd(1, 0, (1 << h), l, r, val); } void calc(int v, int vl, int vr, int upval = -1) { if (flag[v] != -1 && upval == -1) upval = flag[v]; if (vl + 1 == vr) { if (upval != -1) resarr[v - (1 << h)] = upval; return; } int vm = (vl + vr) / 2; calc(2 * v, vl, vm, upval); calc(2 * v + 1, vm, vr, upval); } void calc() { calc(1, 0, (1 << h)); } }; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector<int> a(n); vector<int> curst; multiset<int> has; SegTree st(n); for (int i = 0; i < n; ++i) { int ai; cin >> ai; a[i] = ai; if (!has.count(ai)) { has.insert(ai); curst.push_back(i); st.upd(i, i + 1, ai); continue; } while (a[curst.back()] != ai) { has.extract(a[curst.back()]); curst.pop_back(); } st.upd(curst.back(), i + 1, ai); } st.calc(); for (auto el : st.resarr) cout << el << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...