Submission #1007268

#TimeUsernameProblemLanguageResultExecution timeMemory
1007268THXuanStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
189 ms21188 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 using namespace std; typedef long long ll; const ll maxn = 2e5 + 1; ll lazy[4 * maxn], v[200005]; void pushdown(int v) { if (lazy[v]) { lazy[2 * v] = lazy[v]; lazy[2 * v + 1] = lazy[v]; lazy[v] = 0; } } void update(int v, int l, int r, int tl, int tr, ll val) { if (l > r)return; if (l == tl && r == tr) { lazy[v] = val; return; } pushdown(v); int tm = (tl + tr) / 2; if (r <= tm) update(2 * v, l, r, tl, tm, val); else if (l >= tm + 1) update(2 * v + 1, l, r, tm + 1, tr, val); else { update(2 * v, l, tm, tl, tm, val); update(2 * v + 1, tm + 1, r, tm + 1, tr, val); } } ll query(int v, int l, int r, int pos) { if (l == r)return lazy[v]; int tm = (l + r) / 2; pushdown(v); if (pos <= tm)return query(2 * v, l, tm, pos); else return query(2 * v + 1, tm + 1, r, pos); } void solve() { int n; cin >> n; map<ll, int>cnt; for (int i = 1; i <= n; i++) { cin >> v[i]; cnt[v[i]] = max(cnt[v[i]], i); } int i = 1; while (i <= n) { update(1, i, cnt[v[i]], 1, n, v[i]); i = cnt[v[i]] + 1; }// for (int i = 1; i <= n; i++) cout << query(1, 1, n, i) << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin>>t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...