結果

問題 No.945 YKC饅頭
ユーザー RubikunRubikun
提出日時 2019-12-08 00:07:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 3,156 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 173,840 KB
実行使用メモリ 7,468 KB
最終ジャッジ日時 2023-08-27 06:58:40
合計ジャッジ時間 12,621 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 23 ms
4,380 KB
testcase_32 AC 34 ms
5,044 KB
testcase_33 AC 114 ms
7,128 KB
testcase_34 AC 220 ms
5,128 KB
testcase_35 AC 385 ms
7,416 KB
testcase_36 AC 216 ms
4,380 KB
testcase_37 AC 209 ms
4,376 KB
testcase_38 AC 206 ms
4,380 KB
testcase_39 AC 66 ms
5,272 KB
testcase_40 AC 75 ms
7,468 KB
testcase_41 AC 37 ms
5,196 KB
testcase_42 AC 316 ms
5,012 KB
testcase_43 AC 174 ms
4,376 KB
testcase_44 AC 294 ms
7,220 KB
testcase_45 AC 335 ms
5,136 KB
testcase_46 AC 21 ms
5,192 KB
testcase_47 AC 219 ms
5,044 KB
testcase_48 AC 40 ms
4,380 KB
testcase_49 AC 102 ms
5,020 KB
testcase_50 AC 367 ms
5,108 KB
testcase_51 AC 474 ms
7,156 KB
testcase_52 AC 473 ms
7,236 KB
testcase_53 AC 475 ms
7,216 KB
testcase_54 AC 469 ms
7,232 KB
testcase_55 AC 476 ms
7,156 KB
testcase_56 AC 53 ms
7,264 KB
testcase_57 AC 51 ms
7,220 KB
testcase_58 AC 161 ms
7,464 KB
testcase_59 AC 183 ms
7,280 KB
testcase_60 AC 96 ms
7,152 KB
testcase_61 AC 162 ms
7,312 KB
testcase_62 AC 159 ms
7,224 KB
testcase_63 AC 52 ms
7,152 KB
testcase_64 AC 100 ms
7,128 KB
testcase_65 AC 89 ms
7,156 KB
testcase_66 AC 88 ms
7,252 KB
testcase_67 AC 127 ms
7,256 KB
testcase_68 AC 95 ms
7,244 KB
testcase_69 AC 65 ms
7,224 KB
testcase_70 AC 70 ms
7,152 KB
testcase_71 AC 70 ms
7,220 KB
testcase_72 AC 113 ms
7,232 KB
testcase_73 AC 173 ms
7,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=200005;
const ll INF=1LL<<60;

template<typename T,typename E>
struct LazySegmentTree{
    using F=function<T(T,T)>;
    using G=function<T(T,E)>;
    using H=function<E(E,E)>;
    
    int n;
    vector<T> dat;
    vector<E> lazy;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    
    LazySegmentTree(int n_,F f,G g,H h,T ti,E ei) :f(f),g(g),h(h),ti(ti),ei(ei){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        lazy.assign(2*n-1,ei);
    }
    
    LazySegmentTree(int n_,vector<T> &v,F f,G g,H h,T ti,E ei) :f(f),g(g),h(h),ti(ti),ei(ei){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        
        for(int i=n-1;i-(n-1)<v.size();i++) dat[i]=v[i-(n-1)];
        
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
        
        lazy.assign(2*n-1,ei);
    }
    
    inline void eval(int k,int l,int r){
        
        if(lazy[k]==ei) return;
        
        dat[k]=g(dat[k],lazy[k]);
        
        if(r-l>1){
            lazy[k*2+1]=h(lazy[k*2+1],lazy[k]);
            lazy[k*2+2]=h(lazy[k*2+2],lazy[k]);
        }
        
        lazy[k]=ei;
    }
    
    void update_(int a,int b,E x,int k,int l,int r){
        
        eval(k,l,r);
        
        if(r<=a||b<=l) return;
        
        if(a<=l&&r<=b){
            lazy[k]=h(lazy[k],x);
            eval(k,l,r);
        }
        
        else{
            update_(a,b,x,2*k+1,l,(l+r)/2);
            update_(a,b,x,2*k+2,(l+r)/2,r);
            dat[k]=f(dat[2*k+1],dat[2*k+2]);
        }
        
    }
    
    void update(int a,int b,E x){
        return update_(a,b,x,0,0,n);
    }
    
    T query_(int a,int b,int k,int l,int r){
        
        eval(k,l,r);
        
        if(r<=a||b<=l) return ti;
        if(a<=l&&r<=b) return dat[k];
        
        T vl=query_(a,b,2*k+1,l,(l+r)/2);
        T vr=query_(a,b,2*k+2,(l+r)/2,r);
        return f(vl,vr);
    }
    
    T query(int a,int b){
        return query_(a,b,0,0,n);
    }
    
};

//区間和はTをpair<ll,int>にするa

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    
    auto f=[&](int a,int b){return max(a,b);};
    auto g=[&](int a,int b){
        if(a==0) return b;
        else return a;
    };
    auto h=[&](int a,int b){
        if(a==0) return b;
        else return a;
    };
    
    LazySegmentTree<int,int> seg(N,
                                 f,
                                 g,
                                 h,
                                 0,
                                 0);
    
    for(int i=0;i<M;i++){
        int a,b;char c;cin>>a>>b>>c;
        if(c=='Y') seg.update(a-1,b,1);
        if(c=='K') seg.update(a-1,b,2);
        if(c=='C') seg.update(a-1,b,3);
    }
    
    vector<int> ans(4);
    
    for(int i=0;i<N;i++){
        ans[seg.query(i,i+1)]++;
    }
    
    for(int i=1;i<=3;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    
    
}

0