結果
| 問題 | 
                            No.945 YKC饅頭
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-12-06 02:15:39 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,303 ms / 2,000 ms | 
| コード長 | 2,529 bytes | 
| コンパイル時間 | 3,073 ms | 
| コンパイル使用メモリ | 82,704 KB | 
| 実行使用メモリ | 64,848 KB | 
| 最終ジャッジ日時 | 2024-12-23 04:47:56 | 
| 合計ジャッジ時間 | 50,324 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 74 | 
ソースコード
import java.io.*;
import java.util.*;
class Main {
	public static void main(String[] args) {
		new Main().run();
	}
    
    class DJSet{
        int n;
        int[] upper;
        int[] ma;
        int[] mi;
        int[] cols;
        
        public DJSet(int n){
            this.n=n;
            upper=new int[n];
            ma=new int[n];
            mi=new int[n];
            cols=new int[n];
            Arrays.fill(upper,-1);
            Arrays.fill(cols,-1);
            for(int i=0;i<n;++i){
                ma[i]=i;
                mi[i]=i;
            }
        }
        
        //[l,r)
        void paint(int l, int r, int col){
            if(l>=r)return;
            if(cols[l]!=-1){
                paint(ma[root(l)]+1,r,col);
            }else{
                cols[l]=col;
                paint(l+1,r,col);
            }
            setUnion(l,r-1);
        }
        
        boolean equiv(int a, int b){
            return root(a)==root(b);
        }
        
        int root(int x){
            return upper[x]<0?x:(upper[x]=root(upper[x]));
        }
        
        void setUnion(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y)return;
            if(upper[x]<upper[y]){
                x^=y;y^=x;x^=y;
            }
            upper[y]+=upper[x];
            upper[x]=y;
            ma[y]=Math.max(ma[y],ma[x]);
            mi[y]=Math.min(mi[y],mi[x]);
        }
    }
    
    void run() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        if(!(1<=N&&N<=2e5))throw new AssertionError();
        if(!(1<=M&&M<=2e5))throw new AssertionError();
        DJSet ds=new DJSet(N);
        for(int i=0;i<M;++i){
            int L=sc.nextInt();
            int R=sc.nextInt();
            if(!(1<=L&&L<=R&&R<=N))throw new AssertionError();
            --L;--R;
            String T=sc.next();
            int col=-1;
            if(T.equals("Y")){
                col=0;
            }else if(T.equals("K")){
                col=1;
            }else if(T.equals("C")){
                col=2;
            }else{
                throw new AssertionError();
            }
            ds.paint(L,R+1,col);
        }
        int[] cnt=new int[3];
        for(int i=0;i<N;++i){
            if(ds.cols[i]!=-1)
                cnt[ds.cols[i]]++;
        }
        System.out.println(cnt[0]+" "+cnt[1]+" "+cnt[2]);
    }
    
    void tr(Object...objects){
        System.out.println(Arrays.deepToString(objects));
    }
}