• ZR#330. 【18 提高 3】矿石(容斥)


    题意

    题目链接

    Sol

    挺显然的,首先对每个矿排序

    那么答案就是$2^x - 2^y$

    $x$表示能覆盖到它的区间,$y$表示的是能覆盖到它且覆盖到上一个的区间

    第一个可以差分维护

    第二个直接vector暴力插入扫就行,

    时间复杂度:$O(nlogn)$

    #include<cstdio>
    #include<algorithm>
    #include<bitset>
    #include<vector>
    #define Pair pair<int, ull>
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    #define ull unsigned long long 
    #define LL long long
    #define int long long  
    using namespace std;
    const int MAXN = 3 * 1e6 + 10, INF = 1e9 + 7, mod = 998244353;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int N, M;
    int l[MAXN], r[MAXN], a[MAXN], date[MAXN], cnt = 0, sum[MAXN], num[MAXN];
    vector<int> v[MAXN];
    int fp(int a, int p) {
        int base = 1;
        while(p) {
            if(p & 1) base = (base * a) % mod;
            a = (a * a) % mod; p >>= 1;
        }
        return base % mod;
    }
    main() {
        N = read(); M = read();
        for(int i = 1; i <= N; i++) l[i] = read(), r[i] = read(), date[++cnt] = l[i], date[++cnt] = r[i];
        for(int i = 1; i <= M; i++) a[i] = read(), date[++cnt] = a[i];
        sort(a + 1, a + M + 1);
        sort(date + 1, date + cnt + 1);
        cnt = unique(date + 1, date + cnt + 1) - date - 1;
        for(int i = 1; i <= N; i++) {
            l[i] = lower_bound(date + 1, date + cnt + 1, l[i]) - date;
            r[i] = lower_bound(date + 1, date + cnt + 1, r[i]) - date;
            sum[l[i]]++; sum[r[i] + 1]--; 
            v[l[i]].push_back(r[i]);
        }
        for(int i = 1; i <= M; i++)  a[i] = lower_bound(date + 1, date + cnt + 1, a[i]) - date;
        for(int i = 1; i <= cnt; i++) 
            sum[i] += sum[i - 1];
        
       // for(int i = 1; i <= cnt; i++)
        //    printf("%d ", num[i]); puts("");
        int ans = 0;
        for(int i = 1; i <= M; i++) {
               int base = 0;
            for(int j = a[i - 1] + 1; j <= a[i]; j++) {
                for(int k = 0; k < v[j].size(); k++) {
                    if(v[j][k] >= a[i]) base++;
                }
            }
            ans = (ans + fp(2, sum[a[i]]) - fp(2, sum[a[i]] - base) + mod) % mod;
        }
        printf("%lld
    ", (ans + mod) % mod);
        return 0;
    }
    /*
    3 2
    7 11
    1 5
    3 8
    4
    7
    */
  • 相关阅读:
    cocos2d-x ios 设置横屏/竖屏(全)
    决策树之ID3算法实现(python)
    基于Spring开发的DUBBO服务接口测试
    Mac电脑下配置maven环境变量
    Mac Eclipse+Maven+TestNg+ReportNg 生成测试报告
    TestNG+Maven+IDEA环境搭建
    115个Java面试题和答案——终极列表(上)
    115个Java面试题和答案——终极列表(下)
    阿里巴巴常考面试题及汇总答案
    阿里面试回来,想和Java程序员谈一谈
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9625941.html
Copyright © 2020-2023  润新知