結果
問題 |
No.945 YKC饅頭
|
ユーザー |
![]() |
提出日時 | 2020-04-14 23:31:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 1,557 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 194,920 KB |
最終ジャッジ日時 | 2025-01-09 19:11:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | lint n,m;std::scanf("%d %d\n",&n,&m); | ~~~~~~~~~~^~~~~~~~~~~~~~~~~ main.cpp:27:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | std::scanf("%d %d %c\n",&l,&r,&c);l--; | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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::scanf("%d %d\n",&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::scanf("%d %d %c\n",&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::printf("%d %d %d",y,k,c); }