結果

問題 No.2206 Popcount Sum 2
ユーザー FplusFplusF
提出日時 2025-01-13 17:25:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,831 ms / 4,000 ms
コード長 2,574 bytes
コンパイル時間 5,190 ms
コンパイル使用メモリ 288,592 KB
実行使用メモリ 8,040 KB
最終ジャッジ日時 2025-01-13 17:26:33
合計ジャッジ時間 45,156 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
constexpr ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((ll)v.size())
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
struct Mo{
    int n;
    vector<pair<int,int>> ab;
    Mo(int n_):n(n_){}
    void add(int l,int r){
        ab.emplace_back(l,r);
    }
    int a=0,b=0;
    template<class LL,class LR,class RL,class RR,class O> void solve(LL &al,LR &ar,RL &bl,RR &br,O &output){
        int q=ab.size();
        if(q==0) return;
        int block_size=max(1,n/(int)sqrt(q));
        vector<int> ord(q);
        for(int i=0;i<q;i++) ord[i]=i;
        sort(ord.begin(),ord.end(),
        [&](int i,int j){
            int block_i=ab[i].first/block_size,block_j=ab[j].first/block_size;
            if(block_i!=block_j) return ab[i].first<ab[j].first;
            if(block_i&1) return ab[i].second>ab[j].second;
            else return ab[i].second<ab[j].second;
        }
        );
        for(auto &idx:ord){
            while(ab[idx].first<a) al(),a--;
            while(a<ab[idx].first) ar(),a++;
            while(ab[idx].second<b) bl(),b--;
            while(b<ab[idx].second) br(),b++;
            output(idx);
        }
    }
};
#include <atcoder/modint>
using mint=atcoder::modint998244353;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    constexpr ll sz=200001;
    Mo mo(sz);
    rep(_,t){
        ll n,m;
        cin >> n >> m;
        n--;
        m--;
        mo.add(n,m);
    }
    vector<mint> p(sz,1),q(sz,1);
    for(ll i=2;i<=sz;i++) p[i]=p[i-1]*i;
    for(ll i=2;i<=sz;i++) q[i]=1/p[i];
    auto nCr=[&](ll a,ll b){
        if(a<0||b<0||a<b) return (mint)0;
        return p[a]*q[b]*q[a-b];
    };
    mint now=1;
    auto nl=[&]{
        now=(now+nCr(mo.a-1,mo.b))/2;
    };
    auto nr=[&]{
        now=2*now-nCr(mo.a,mo.b);
    };
    auto ml=[&]{
        now=now-nCr(mo.a,mo.b);
    };
    auto mr=[&]{
        now=now+nCr(mo.a,mo.b+1);
    };
    vector<mint> ans(t);
    auto out=[&](int idx){
        ans[idx]=(mint(2).pow(mo.a+1)-1)*now;
    };
    mo.solve(nl,nr,ml,mr,out);
    rep(i,t) cout << ans[i].val() << '\n';
}
0