結果
問題 | No.3103 Butterfly Effect |
ユーザー |
|
提出日時 | 2025-04-11 23:16:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 685 ms / 5,000 ms |
コード長 | 1,305 bytes |
コンパイル時間 | 2,397 ms |
コンパイル使用メモリ | 211,056 KB |
実行使用メモリ | 68,424 KB |
最終ジャッジ日時 | 2025-04-11 23:17:20 |
合計ジャッジ時間 | 24,496 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; vector<map<int,int,greater<>>> Hold(N); int answer = 1; vector<int> T(N,Q+1); T.at(0) = 0; for(int t=0; t<Q; t++){ int p,x,y; cin >> p >> x >> y; p--; x--; y--; int xt = T.at(x),yt = T.at(y); if(xt < p && yt < p){} else if(xt > p && yt > p) Hold.at(x)[p] = y,Hold.at(y)[p] = x; else{ if(xt > p) swap(x,y),swap(xt,yt); if(T.at(y) == Q+1) answer++; T.at(y) = p; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> PQ; PQ.push({p,y}); while(PQ.size()){ auto [ti,pos] = PQ.top(); PQ.pop(); if(T.at(pos) != ti) continue; vector<int> era; for(auto [k,to] : Hold.at(pos)){ if(k < ti) break; if(T.at(to) > k){ if(T.at(to) == Q+1) answer++; T.at(to) = k; PQ.push({k,to}); } era.push_back(k); } for(auto e : era) Hold.at(pos).erase(e); } } cout << answer << "\n"; } }