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<