Submission #1138460

#TimeUsernameProblemLanguageResultExecution timeMemory
1138460BolatuluStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
302 ms28972 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3,unroll-loops") #pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt") #define ios ios_base::sync_with_stdio(0); cin.tie(0); #define all(x) (x).begin(), (x).end() #define len(x) (ll) x.size() #define pb push_back #define eb emplace_back #define F first #define S second #define ins insert #define md (tl + tr) / 2 #define TL v + v, tl, md #define TR v + v + 1, md + 1, tr #define Tl L[v], tl, md #define Tr R[v], md + 1, tr #define int long long using namespace std; typedef long long ll; typedef double db; typedef long double ld; const int N = 5e5 + 7; const int M = 998244353; const ll INF = 1e18 + 7; int dx[8] = {0, 1, 0, -1, -1, 1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int mod(int a, int b = M) { if (a < 0) a = b + a % b; return a % b; } int binpow(int a, int n) { if (n == 0) return 1; if (n & 1) return a * binpow(a, n - 1) % M; int x = binpow(a, n / 2); return x * x % M; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int random(int l,int r) { return uniform_int_distribution<int>(l, r)(rng); } int n, a[N]; map <int, vector <int>> last; void solution(){ cin >> n; vector <pair <int, int>> v; for (int i = 1;i <= n;i++) { cin >> a[i]; int c = 1; if (!last[a[i]].empty()) { while (v.back().F != a[i]) { c += v.back().S; last[v.back().F].pop_back(); v.pop_back(); } c += v.back().S; last[v.back().F].pop_back(); v.pop_back(); } last[a[i]].pb(i); v.eb(a[i], c); } for (auto now : v) { for (int i = 1;i <= now.S;i++) cout << now.F << '\n'; } } signed main(){ ios int cs = 1; // cin >> cs; while(cs--) { solution(); cout << '\n'; } } //op/adj
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...