• bzoj 2751


    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2751

    稍微推一下就知道是每一位置可取的值的和乘起来

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    typedef long long qword;
    const qword maxn = 100010;
    const qword mod = 1000000007;
    const qword Mx = 500000004;
    qword M, m, n;
    
    struct node {
        qword pos, v;
    }e[maxn];
    
    bool cmp(node a, node b) {
        if(a.pos == b.pos) return a.v < b.v;
        else return a.pos < b.pos;
    }
    
    void read() {
        scanf("%lld%lld%lld", &M,  &m, &n);
        for(qword i = 1; i <= n; ++ i) scanf("%lld%lld", &e[i].pos, &e[i].v);
    }
    
    qword Pow(qword a, qword b) {
        qword ret = 1; qword now = a % mod;
        while(b) {
            if(b & 1) ret = ret * now % mod;
            b >>= 1, now = now * now % mod;
        }
        return ret;
    }
    
    qword ans = 1;
    
    void sov() {
        sort(e + 1, e + 1 + n, cmp);
        qword pre = 0;
        qword S = M * (M + 1) % mod * Mx % mod;
        for(qword i = 1; i <= n; ++ i) {
            qword ls, rs; ls = i, rs = i;
            while(e[rs + 1].pos == e[ls].pos) rs ++;
            ans = ans * Pow(S, e[ls].pos - pre - 1) % mod; pre = e[ls].pos; 
            qword Tmp = S;
            for(qword j = ls; j <= rs; ++ j) {
                if(e[j].pos == e[j - 1].pos && e[j].v == e[j - 1].v) continue;
                Tmp = (Tmp - e[j].v) % mod;
            }
            Tmp = (Tmp % mod + mod) % mod;
            ans = ans * Tmp % mod;
            i = rs;
        }
        if(pre != m) ans = ans * Pow(S, m - pre) % mod;
        printf("%lld
    ", ans);
    }
    
    int main() {
        //freopen("test.in", "r", stdin);
        read(), sov();
        return 0;
    }
  • 相关阅读:
    CSP2018-09
    CSP2018-03
    CSP2017-12
    CSP2017-09
    CSP2017-03
    CSP2016-12
    [算法设计与分析] 奶酪 (并查集)
    5555
    阿超
    结对作业
  • 原文地址:https://www.cnblogs.com/ianaesthetic/p/4139200.html
Copyright © 2020-2023  润新知