結果

問題 No.1549 [Cherry 2nd Tune] BANning Tuple
ユーザー chocoruskchocorusk
提出日時 2021-06-11 22:51:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 4,000 ms
コード長 3,132 bytes
コンパイル時間 3,580 ms
コンパイル使用メモリ 197,708 KB
実行使用メモリ 4,576 KB
最終ジャッジ日時 2023-08-21 13:39:24
合計ジャッジ時間 4,583 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 7 ms
4,484 KB
testcase_08 AC 6 ms
4,576 KB
testcase_09 AC 6 ms
4,444 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 7 ms
4,496 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 6 ms
4,436 KB
testcase_15 AC 6 ms
4,456 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 7 ms
4,496 KB
testcase_18 AC 6 ms
4,428 KB
testcase_19 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    ll n; int Q; cin>>n>>Q;
    using mint=modint998244353;
    const int mx=3002;
    vector<mint> v(mx+1);
    v[0]=1;
    for(int i=1; i<=mx; i++) v[i]=v[i-1]*mint(n-1+i)/mint(i);
    int i0=0;
    map<ll, vector<int>> mp;
    for(int i=0; i<Q; i++){
        ll k;
        int a, b, s, t;
        cin>>k>>a>>b>>s>>t;
        b++;
        if(mp.find(k)!=mp.end()){
            auto ws=mp[k];
            vector<int> w;
            int q=0;
            for(int j=0; j<=mx; j++){
                if(!q && ws[j]){
                    w.push_back(j);
                    q=1;
                }else if(q && ws[j]==0){
                    w.push_back(j);
                    q=0;
                }
            }
            if(w[0]==0){
                i0-=w[1];
                for(int j=0; j<=mx; j++){
                    for(int m=2; m<w.size(); m++){
                        if(!(m&1) && j>=w[m]-w[1]) v[j]+=v[j-w[m]+w[1]];
                        else if((m&1) && j>=w[m]-w[1]) v[j]-=v[j-w[m]+w[1]];
                    }
                }
            }else{
                for(int j=0; j<=mx; j++){
                    for(int m=0; m<w.size(); m++){
                        if(!(m&1) && j>=w[m]) v[j]+=v[j-w[m]];
                        else if((m&1) && j>=w[m]) v[j]-=v[j-w[m]];
                    }
                }
            }
        }else{
            mp[k].resize(3001);
        }
        for(int j=a; j<b; j++) mp[k][j]++;
        auto ws=mp[k];
        vector<int> w;
        int q=0;
        for(int j=0; j<=mx; j++){
                if(!q && ws[j]){
                    w.push_back(j);
                    q=1;
                }else if(q && ws[j]==0){
                    w.push_back(j);
                    q=0;
                }
        }
        if(w[0]==0){
                i0+=w[1];
                for(int j=mx; j>=0; j--){
                    for(int m=2; m<w.size(); m++){
                        if(!(m&1) && j+w[m]-w[1]<=mx) v[j+w[m]-w[1]]-=v[j];
                        else if((m&1) && j+w[m]-w[1]<=mx) v[j+w[m]-w[1]]+=v[j];
                    }
                }
        }else{
                for(int j=mx; j>=0; j--){
                    for(int m=0; m<w.size(); m++){
                        if(!(m&1) && j+w[m]<=mx) v[j+w[m]]-=v[j];
                        else if((m&1) && j+w[m]<=mx) v[j+w[m]]+=v[j];
                    }
                }
        }
        mint ans=0;
        for(int j=max(0, s-i0); j<=t-i0; j++) ans+=v[j];
        cout<<ans.val()<<endl;
    }
    return 0;
}
0