OIFC未来共同体20241102noip模拟五

T1

观察大样例,发现只有两个点被同样的集合包含这两个点一定不能成为单独的集合。

直接哈希,差分即可。

#include<iostream>
#include<random>
#include<map>
#include<algorithm>

using namespace std;

inline int read(){register int x = 0, f = 1;register char c = getchar();while (c < '0' || c > '9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return x * f;}

const int N = 5e6 + 10;
int c, T, n, m, ans;
long long w[N], cf[N], f[N];
mt19937 rd(40491522);
void solve(){
    n = read(), m = read(), ans = 0;
    for (int i = 1; i <= m + 1; i++) w[i] = rd();
    for (int i = 1; i <= m; i++){
        int k = read();
        for (int j = 1; j <= k; j++){
            int l = read(), r = read();
            cf[l] += w[i], cf[r + 1] -= w[i];
        }
    }
    cf[1] += w[m + 1], cf[n + 1] -= w[m + 1];
    long long sum = 0;
    for (int i = 1; i <= n; i++) sum += cf[i], f[i] = sum;
    sort(f + 1, f + n + 1);
    for (int i = 1; i <= n; i++){
        int res = 0;
        while (f[i] == f[i + 1]) res++, i++;
        if (res >= 1) ans += res + 1;
    }
    cout << n - ans << '\n';
    for (int i = 1; i <= n + 1; i++) cf[i] = 0;
}

signed main(){
    freopen("set.in", "r", stdin);
    freopen("set.out", "w", stdout);
    c = read(), T = read();
    while (T--) solve();
    return 0;
}

T2

不会。

T3

不会。

T4

不会。

posted @ 2024-11-04 19:45  bryce_yyds  阅读(8)  评论(0编辑  收藏  举报