結果
問題 |
No.945 YKC饅頭
|
ユーザー |
![]() |
提出日時 | 2020-04-14 23:21:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,524 bytes |
コンパイル時間 | 2,277 ms |
コンパイル使用メモリ | 195,192 KB |
最終ジャッジ日時 | 2025-01-09 19:11:38 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=int; using ld=long double; lint left[200'001],right[200'001],p[200'001],a[200'001]; lint find(lint i){lint&j=p[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[find(i)];} bool unite(lint i,lint j){ i=find(i),j=find(j); if(i==j)return false; if(-p[i]<-p[j])std::swap(i,j); p[i]=p[j]; p[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; std::iota(std::begin(left),std::begin(left)+n+1,0); std::iota(std::begin(right),std::begin(right)+n+1,1); std::fill(std::begin(p),std::begin(p)+n,-1); std::string s(n+1,'$'); while(m--){ lint l,r;char c;std::cin>>l>>r>>c;l--; lint sz=0; l=left[find(l)]; for(lint i=l;i<r;){ if(s[i]=='$'){ s[i]=c; a[sz++]=i; i++; }else{ a[sz++]=i; i=right[find(i)]; } } l=left[find(l)]; r=right[find(r-1)]; std::for_each(std::begin(a),std::begin(a)+sz,[l](lint i){unite(l,i);}); lint x=find(l); left[x]=l; right[x]=r; } lint y=0,k=0,c=0; for(char x:s){ if(x=='Y')y++; if(x=='K')k++; if(x=='C')c++; } std::cout<<y<<' '<<k<<' '<<c<<'\n'; }