結果
| 問題 |
No.3167 [Cherry 7th Tune C] Cut in Queue
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-30 22:44:44 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,159 ms / 2,500 ms |
| コード長 | 2,958 bytes |
| コンパイル時間 | 6,030 ms |
| コンパイル使用メモリ | 363,236 KB |
| 実行使用メモリ | 467,356 KB |
| 最終ジャッジ日時 | 2025-05-30 22:45:24 |
| 合計ジャッジ時間 | 37,492 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans *= a;
b >>= 1;
a *= a;
}
return ans;
}
ll pow(ll a, ll b, ll c) {
ll ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % c;
b >>= 1;
a = (a * a) % c;
}
return ans;
}
void check(bool b) {
if (b)
cout << "Yes\n";
else
cout << "No\n";
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pSet tree<pair<ll,ll>, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n;cin>>n;
vector<ll>a(n);
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
ll q;cin>>q;
pSet s;
vector<deque<ll>>v(n+q+1);
vector<vector<ll>>queries;
ll back=n+1;
vector<ll>p(n+q+1, -1);ll pos=0;
while (q--){
ll t;cin>>t;
if (t==1){
ll x;cin>>x;
queries.push_back({1, back});
v[x].push_back(back++);
} else if (t==2){
queries.push_back({2});
} else {
ll x;cin>>x;--x;
queries.push_back({3, x});
}
}
for (int i = 1; i < n+1; ++i) {
ll x=a[i-1];
vector<ll>v1;
while (x!=-1){
if (!v[x].empty()){
v1.push_back(x);
auto it = v[x].front();
v[x].pop_front();
x = it;
} else {
p[x]=pos++;
if (v1.empty()) {
x = -1;
} else {
x = v1.back();
v1.pop_back();
}
}
}
s.insert({p[a[i-1]], a[i-1]});
}
{
ll x=0;
vector<ll>v1;
while (x!=-1){
if (!v[x].empty()){
v1.push_back(x);
auto it = v[x].front();
v[x].pop_front();
x = it;
} else {
p[x]=pos++;
if (v1.empty()) {
x = -1;
} else {
x = v1.back();
v1.pop_back();
}
}
}
}
for(auto &i:queries){
if (i[0]==1){
s.insert({p[i[1]], i[1]});
} else if (i[0]==2){
s.erase(s.begin());
} else {
auto it = s.find_by_order(i[1]);
cout<<it->second<<'\n';
}
}
return 0;
}