From fea6373239572bdd469c493eadc688064baee55d Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 25 Aug 2025 23:52:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250825]=20BOJ=20/=20P4=20/=20=EA=B0=80?= =?UTF-8?q?=ED=9D=AC=EC=9D=98=20=EC=88=98=EC=97=B4=EB=86=80=EC=9D=B4=20(La?= =?UTF-8?q?rge)=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...27\264\353\206\200\354\235\264 (Large).md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" diff --git "a/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" "b/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" new file mode 100644 index 00000000..e0b08010 --- /dev/null +++ "b/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" @@ -0,0 +1,47 @@ +```cpp +#include +using namespace std; + +int Q, MOD; +vector pos[1000001]{}; +stack st; +set s; + +int main(){ + cin.tie(0)->sync_with_stdio(0); + + cin>>Q>>MOD; + if(MOD > Q) { + for(int o,a;Q--;) { + cin>>o; + if(o == 1) cin>>a; + if(o == 3) cout<<"-1\n"; + } + return 0; + } + + for(int i=0,o,a;i>o; + if(o == 1) { + cin>>a; + a %= MOD; + if(!pos[a].empty()) s.erase(pos[a].back()); + s.insert(st.size()); + pos[a].push_back(st.size()); + st.push(a); + } + else if(o == 2) { + if(st.empty()) continue; + a = st.top(); st.pop(); + s.erase(pos[a].back()); + pos[a].pop_back(); + if(!pos[a].empty()) s.insert(pos[a].back()); + } + else { + if(s.size() != MOD) cout<<"-1\n"; + else cout<