#include<bits/stdc++.h>
using namespace std;
int c, t, n, m, ans;
int hs[5000005];
unordered_map<int, int> mp;
void read(int &x) {
x = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
x = x * 10 + (ch - '0');
ch = getchar();
}
}
void write(int x) {
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
signed main() {
freopen("set.in", "r", stdin);
freopen("set.out", "w", stdout);
srand(time(0));
read(c), read(t);
while (t--) {
ans = 0;
read(n), read(m);
memset(hs, 0, sizeof hs);
mp.clear();
while (m--) {
int base = rand();
int k;
read(k);
while (k--) {
int l, r;
read(l), read(r);
hs[l] ^= base;
hs[r + 1] ^= base;
}
}
for (int i = 1; i <= n; i++) hs[i] ^= hs[i - 1];
for (int i = 1; i <= n; i++) mp[hs[i]]++;
for (int i = 1; i <= n; i++) ans += mp[hs[i]] == 1;
write(ans), putchar('\n');
}
return 0;
}
不需要题面,就帮忙卡一下就行了。