Submission #769341

#TimeUsernameProblemLanguageResultExecution timeMemory
769341singlabharatStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
276 ms27868 KiB
// OM SHRI GANESHAY NAMAH // HARE KRISHNA #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define int long long using vi = vector<int>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; using si = set<int>; using mii = map<int, int>; template<typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(x) (int)size(x) #define pb emplace_back #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define fr first #define sc second #define fo(i, end) for (int i = 0; i < end; i++) #define foo(i, start, end) for (int i = start; i < end; i++) template<typename T> inline void domin(T &x, T y) {if (y < x) x = y;} template<typename T> inline void domax(T &x, T y) {if (y > x) x = y;} template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &a) { os << '{'; string sep; for (const T &x : a) os << sep << x, sep = ", "; return os << '}';} void debug() {cerr << endl;} template <typename Head, typename... Tail> void debug(Head h, Tail... t) {cerr << h << ' '; debug(t...);} #ifdef singlabharat #define debug(...) cerr << "(" << #__VA_ARGS__ << ") : ", debug(__VA_ARGS__) #else #define debug(...) #endif #define endl '\n' const int MX = 2e5 + 2, MOD = 1e9 + 7, INF = 1e6; void solve() { int n; cin >> n; vi cur_idcs; map<int, vi> col_idcs; vi col(n); fo(i, n) { int c; cin >> c; col[i] = c; if (!empty(col_idcs[c])) { int j = col_idcs[c].back(); while (cur_idcs.back() != j) { col_idcs[col[cur_idcs.back()]].pop_back(); cur_idcs.pop_back(); } } cur_idcs.pb(i); col_idcs[c].pb(i); } int ptr = 0; int c = -1; fo(i, n) { if (i == cur_idcs[ptr]) c = col[cur_idcs[ptr++]]; cout << c << endl; } } int32_t main() { #ifdef singlabharat freopen("error.txt", "w", stderr); #endif cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; for (int tc = 1; tc <= t; tc++) { // cout << "Case #" << tc << ": "; solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...