TLE 60pts 求卡常

#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;
}

不需要题面,就帮忙卡一下就行了。

memset换成for(大概会浪费几毫秒左右的时间)

1 个赞

用老师给的那个随机值

1 个赞

srand换一个常数值

1 个赞

问:用mt19937会更快吗?

老师让用的

1 个赞

@stringdp100005 现在卡过了吗?

没有,WA 了()

@stringdp100005 。6哪道题?

image
第 16 个封禁用户粉丝祭 /kx(

。。。
下面那个是啥???

@stringdp100005 。有我的多吗?

image
/cf

建议把犇犇里的这种人批量清理一下,这种人真的看不过去

@stringdp100005 一群人集体没了,但是 QYC____ 怎么还没有禁言?

正常对线应该是不会禁言的,除非骂的很重,攻击性极强的那种

@stringdp100005 那他说 @0Io_oI0 早密码比 这样为什么不尽言?

等会它们不封禁是不是可以用复活币(?
所以就是等 14 天的事(?

这样不会禁言的,除非是对管理