結果
| 問題 |
No.945 YKC饅頭
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-14 22:48:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,462 bytes |
| コンパイル時間 | 2,408 ms |
| コンパイル使用メモリ | 200,308 KB |
| 最終ジャッジ日時 | 2025-01-09 19:05:05 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 32 TLE * 12 |
ソースコード
#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);}
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,'$');
while(m--){
lint l,r;char c;std::cin>>l>>r>>c;l--;
std::vector<lint>a;
for(lint i=l;i<r;){
if(s.at(i)=='$'){
s.at(i)=c;
a.push_back(i);
i++;
}else{
i=right.at(i);
}
}
for(lint i:a)uf.unite(l,i);
lint x=uf.find(l);
left.at(x)=left.at(l);
right.at(x)=right.at(r);
}
std::cout
<<std::count(ALL(s),'Y')
<<' '<<std::count(ALL(s),'K')
<<' '<<std::count(ALL(s),'C')
<<'\n';
}
ngtkana