結果
問題 |
No.945 YKC饅頭
|
ユーザー |
![]() |
提出日時 | 2020-04-14 22:58:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 1,647 bytes |
コンパイル時間 | 3,137 ms |
コンパイル使用メモリ | 203,644 KB |
最終ジャッジ日時 | 2025-01-09 19:08:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; // Union-Find Tree {{{ struct union_find { std::vector<lint>p; union_find()=default; union_find(lint n):p(n,-1){} lint find(lint i){lint&j=p.at(i);return j<0?i:j=find(j);} bool same(lint i,lint j){return find(i)==find(j);} lint sz(lint i){return -p.at(find(i));} bool unite(lint i,lint j){ i=find(i),j=find(j); if(i==j)return false; if(-p.at(i)<-p.at(j))std::swap(i,j); p.at(i)+=p.at(j); p.at(j)=i; return true; } };/*}}}*/ int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n,m;std::cin>>n>>m; union_find uf(n+1); std::vector<lint>left(n+1),right(n+1); std::iota(ALL(left),0ll); std::iota(ALL(right),1ll); std::string s(n+1,'$'); while(m--){ lint l,r;char c;std::cin>>l>>r>>c;l--; std::vector<lint>a; l=left.at(uf.find(l)); for(lint i=l;i<r;){ if(s.at(i)=='$'){ s.at(i)=c; a.push_back(i); i++; }else{ a.push_back(i); i=right.at(uf.find(i)); } } lint L=left.at(uf.find(l)); lint R=right.at(uf.find(r-1)); for(lint i:a)uf.unite(l,i); lint x=uf.find(l); left.at(x)=L; right.at(x)=R; } std::cout <<std::count(ALL(s),'Y') <<' '<<std::count(ALL(s),'K') <<' '<<std::count(ALL(s),'C') <<'\n'; }