結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 02:30:10 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,091 bytes |
| 記録 | |
| コンパイル時間 | 4,628 ms |
| コンパイル使用メモリ | 381,484 KB |
| 実行使用メモリ | 18,688 KB |
| 最終ジャッジ日時 | 2026-04-18 02:30:29 |
| 合計ジャッジ時間 | 14,326 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 WA * 2 RE * 23 |
ソースコード
// Compile: g++ -std=c++20 -O2 -Wall -I$HOME/ctf/tools/ac-library -DLOCAL -o sol sol.cpp
// Or: make sol (uses Makefile in this dir)
// Run: ./sol < in.txt
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define rep2(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((ll)(x).size())
template<class T> bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
#ifdef LOCAL
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#else
#define dbg(x)
#endif
using mint = modint998244353;
// using mint = modint1000000007;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
deque<pair<char, int>> deq;
stack<vector<int>> st;
for (int i = 0; i < q; i++) {
int query;
cin >> query;
if(query == 1){
char c;
cin >> c;
if (sz(deq) >= 2) {
if(deq[sz(deq)-2].first=='(' && deq[sz(deq)-1].first=='|' && c==')'){
vector<int> pop_index = {deq[sz(deq)-2].second, deq[sz(deq)-1].second, i};
st.push(pop_index);
deq.pop_back();
deq.pop_back();
} else {
deq.push_back(make_pair(c, i));
}
} else {
deq.push_back(make_pair(c, i));
}
} else if (query == 2) {
int deq_last;
if(sz(deq)>0) deq_last = deq[sz(deq) - 1].second;
else
deq_last = -1;
int st_top = st.top()[2];
if (deq_last > st_top){
deq.pop_back();
} else {
if(deq_last > st.top()[1]) {
deq.push_front(make_pair('|', st.top()[1]));
deq.push_front(make_pair('(', st.top()[0]));
} else {
deq.push_back(make_pair('|', st.top()[1]));
if(deq_last > st.top()[0]) {
deq.push_front(make_pair('(', st.top()[0]));
} else {
deq.push_back(make_pair('(', st.top()[0]));
}
}
st.pop();
}
}
// cout << "deq: ";
// rep(j, sz(deq)) cout << deq[j].first << "," << deq[j].second << " ";
// cout << endl;
// cout << "st: ";
// if (sz(st) > 0) cout << "sz(st)" << sz(st) << ", top" << st.top()[0] << "," << st.top()[1] << "," << st.top()[2];
// cout << endl;
if (deq.empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}