제출 #922993

#제출 시각아이디문제언어결과실행 시간메모리
922993Gromp15Stone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
213 ms31200 KiB
#include <bits/stdc++.h> #define ll long long #define ar array #define db double #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rint(l, r) uniform_int_distribution<int>(l, r)(rng) template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } struct segtree { int N; vector<int> tree, time; segtree(int n) : N(1<<(__lg(n)+1)), tree(2*N, -1), time(2*N, -1) {} void update(int node, int nl, int nr, int ql, int qr, int v, int cur_time) { if (ql > nr || qr < nl) return; if (ql <= nl && nr <= qr) { tree[node] = v; time[node] = cur_time; return; } int mid = (nl+nr)/2; update(node*2, nl, mid, ql, qr, v, cur_time); update(node*2+1, mid+1, nr, ql, qr, v, cur_time); } int query(int pos) { int mx_time = -1, col = -1; for (int i = pos+N; i; i >>= 1) { if (ckmax(mx_time, time[i])) { col = tree[i]; } } return col; } }; void test_case() { int n; cin >> n; vector<int> a(n); for (int &x : a) cin >> x; map<int, vector<int>> cols; segtree st(n); for (int i = 0; i < n; i++) { while (cols[a[i]].size()) { int c = cols[a[i]].back(); int ret = st.query(c); if (~ret && ret != a[i]) cols[a[i]].pop_back(); else break; } if (cols[a[i]].size()) { int c = cols[a[i]].back(); st.update(1, 0, st.N-1, c, i, a[i], i); } cols[a[i]].push_back(i); } for (int i = 0; i < n; i++) cout << (~st.query(i) ? st.query(i) : a[i]) << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while (t--) test_case(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...