結果
| 問題 |
No.945 YKC饅頭
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-14 23:11:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 1,611 bytes |
| コンパイル時間 | 2,480 ms |
| コンパイル使用メモリ | 203,440 KB |
| 最終ジャッジ日時 | 2025-01-09 19:10:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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[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.at(i)+=p.at(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;
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[uf.find(l)];
for(lint i=l;i<r;){
if(s[i]=='$'){
s[i]=c;
a.push_back(i);
i++;
}else{
a.push_back(i);
i=right[uf.find(i)];
}
}
lint L=left[uf.find(l)];
lint R=right[uf.find(r-1)];
for(lint i:a)uf.unite(l,i);
lint x=uf.find(l);
left[x]=L;
right[x]=R;
}
std::cout
<<std::count(ALL(s),'Y')
<<' '<<std::count(ALL(s),'K')
<<' '<<std::count(ALL(s),'C')
<<'\n';
}
ngtkana