結果
問題 |
No.3167 [Cherry 7th Tune C] Cut in Queue
|
ユーザー |
![]() |
提出日時 | 2025-06-16 19:42:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 386 ms / 2,500 ms |
コード長 | 2,074 bytes |
コンパイル時間 | 2,822 ms |
コンパイル使用メモリ | 208,544 KB |
実行使用メモリ | 24,028 KB |
最終ジャッジ日時 | 2025-06-16 19:43:13 |
合計ジャッジ時間 | 15,821 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define Loop(x,l,r) for (ll x = ll(l); x < ll(r); ++x) #define LoopR(x,l,r) for (ll x = ll(r)-1; x >= ll(l); --x) #define Looc(x,l,r) for (ll x = ll(l); x <= ll(r); ++x) #define LoocR(x,l,r) for (ll x = ll(r); x >= ll(l); --x) #define int ll typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #ifndef DB #define DB 0 #define endl '\n' #endif #define debugl(l) if constexpr ((l) < DB) #define debug debugl(0) const int N = 300'010*2; const int S = 512; mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count()); vector<vector<int>> blocks(1); int rt[N]; void insert_into(int i, int pos, int x) { auto &b = blocks[i]; b.insert(b.begin() + pos, x); rt[x] = i + 1 == blocks.size()? -1: b.back(); if (rd() % S == 0) { vector<int> vec(b.begin(), b.begin() + pos + 1); b.erase(b.begin(), b.begin() + pos + 1); blocks.insert(blocks.begin() + i, vec); for (int y : vec) rt[y] = vec.back(); } } int by_index(int pos) { int i = 0; while (pos >= blocks[i].size()) { pos -= blocks[i].size(); i++; } return blocks[i][pos]; } void insert(int p, int x) { if (p == -1) return insert_into(blocks.size() - 1, blocks.back().size(), x); int i = 0; while (i + 1 < blocks.size() && blocks[i].back() != rt[p]) i++; int j = 0; while (blocks[i][j] != p) j++; insert_into(i, j, x); } void solve() { int n; cin >> n; vector<int> a(n); for (auto &x : a) { cin >> x; x--; } int q; cin >> q; vector<pii> qu(q); for (auto &[x, y] : qu) { cin >> x; if (x != 2) { cin >> y; y--; } } for (int x : a) insert(-1, x); int base = 0; int cnt = n; for (auto [t, x] : qu) { if (t == 1) insert(x, cnt++); if (t == 2) base++; if (t == 3) cout << by_index(base + x) + 1 << '\n'; debug { for (auto &b : blocks) { cerr << "[ "; for (auto x : b) cerr << x << ' '; cerr << "]\n"; } cout << '\n'; } } } signed main() { cin.tie(0) -> sync_with_stdio(false); int t = 1; //cin >> t; while (t--) solve(); }