結果

問題 No.3094 Stapler
ユーザー makichan
提出日時 2025-04-06 16:19:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 6,434 ms
コンパイル使用メモリ 333,828 KB
実行使用メモリ 31,432 KB
最終ジャッジ日時 2025-06-20 02:30:49
合計ジャッジ時間 13,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = atcoder::static_modint<998244353>;
// using mint = atcoder::static_modint<1000000007>;
using ld = long double;
using ll = long long;
#define mp(a,b) make_pair(a,b)
#define rep(i,s,n) for(int i=s; i<(int)n; i++)
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
const vector<int> dx{1,0,-1,0},dy{0,1,0,-1};

struct v{
    int val,cnt;
};
v op(v L, v R){
    if(L.val<R.val)return L;
    else if(L.val>R.val)return R;
    else{
        L.cnt+=R.cnt;
        return L;
    }
}
const int inf=1e9;
v e(){return {inf,0};}

v mapping(int F,v x){
    x.val+=F;
    return x;
}
int comp(int F,int G){return F+G;}
int id(){return 0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,Q;cin >> n >> Q;
    lazy_segtree<v,op,e,int,mapping,comp,id> seg(n-1);
    rep(i,0,n-1)seg.set(i,{0,1});
    vector<pair<int,int>> memo(Q);
    rep(q,0,Q){
        int t;cin >> t;
        if(t==1){
            int L,R;cin >> L >> R;
            L--;
            R--;
            memo[q]={L,R};
            seg.apply(L,R,1);
        }
        else if(t==2){
            int q;cin >> q;
            q--;
            auto [L,R]=memo[q];
            seg.apply(L,R,-1);
        }
        else{
            auto p=seg.all_prod();
            int ans=1;
            if(p.val==0)ans+=p.cnt;
            cout << ans << "\n";
        }
        // rep(i,0,n-1){
        //     cout << seg.get(i).val << " ";
        // }
        // cout << "\n";
    }
}
0