QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740813#4385. RandomStarrykillerAC ✓14ms3640kbC++236.1kb2024-11-13 11:39:192024-11-13 11:39:19

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 11:39:19]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:3640kb
  • [2024-11-13 11:39:19]
  • 提交

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever!

#include <bits/stdc++.h>


namespace sk {
    // modint: https://www.cnblogs.com/hzy1/p/16344746.html
    // Edited by Starrykiller.
    using i64=int64_t;
    using i128=__int128;
    using u128=unsigned __int128;
    using u64=uint64_t;
    using i32=int32_t;
    using u32=uint32_t;
    struct barrett { // From Atcoder Library.
        u32 _m;
        u64 im;
        explicit barrett(u32 m) : _m(m), im((u64)(-1)/m+1) {}
        u32 umod() const { return _m; }
        u32 mul(u32 a, u32 b) const {
            u64 z=a; z*=b;
            u64 x=(u64)((u128(z)*im) >> 64);
            u64 y = x * _m;
            return (u32)(z-y+(z<y?_m:0));
        }
    };
    constexpr i32 inverse(i32 a, i32 m) { i32 r=1;
        while (a>1) { i32 t=m/a; r=i64(r)*(m-t)%m; a=m-t*a; }
        return r;
    }
    template<i32 p>
    struct static_modint { 
        using mi=static_modint;
        public:
        constexpr static_modint(i64 x) : x(normal(x%p)) {}
        constexpr static_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr static_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static i32 mod() { return p; }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,p),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(p-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=i64(x)*rhs.x%p; return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x;
    };
    template<i32 id>
    struct dynamic_modint { 
        using mi=dynamic_modint;
        public:
        constexpr dynamic_modint(i64 x) : x(normal(x%mod())) {}
        constexpr dynamic_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr dynamic_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            auto p=mod();
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static void set_mod(i32 m) { assert(m>=1); bt=barrett((u32)m); }
        constexpr static i32 mod() { return bt.umod(); }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,mod()),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(mod()-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=bt.mul(val(),rhs.val()); return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x; 
        static barrett bt;
    };
    template<i32 id> barrett dynamic_modint<id>::bt(998244353);
    using modint998244353=static_modint<998244353>;
    using modint1000000007=static_modint<1000000007>;
    using mint=dynamic_modint<-1>; 
};

using namespace std;

using ll=sk::modint1000000007;
// #define int long long 

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin>>T;
    while (T--) {
        int n, m; cin>>n>>m;
        cout<<(n-m)*ll(2).inv()<<'\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 3640kb

input:

100000
42 30
6335 1161
19170 15725
11479 6401
26963 24465
5706 5322
23282 16828
9962 492
2996 2955
4828 609
32392 14605
3903 154
293 77
17422 1295
19719 177
5448 5383
14772 11539
1870 1213
25668 632
17036 9895
28704 23812
31323 30334
17674 4665
15142 7712
28254 6869
25548 2097
32663 95
20038 12860
8...

output:

6
2587
500001726
2539
1249
192
3227
4735
500000024
500002113
500008897
500001878
108
500008067
9771
500000036
500001620
500000332
12518
500003574
2446
500000498
500006508
3715
500010696
500011729
16284
3589
3853
500013379
500004644
10174
119
49
500007944
500001824
500004584
4510
500006963
500010426
...

result:

ok 100000 lines