QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226143#5425. Proposition CompositionIshyWA 0ms3856kbC++142.7kb2023-10-25 16:45:242023-10-25 16:45:25

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 16:45:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2023-10-25 16:45:24]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define MT make_tuple
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		k >>= 1, Sqr(x);
	}
	return res;
}
void read(int &x)
{
	x = 0;
	int f = 1;
	char ch = getchar();
	while(!isdigit(ch))
	{
		if(ch == '-')
			f = -1;
		ch = getchar();
	}
	while(isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	x = x * f;
}
const int N = 2.5e5 + 5;
int T, n, m, ecnt;
namespace Brute3
{
	const int base = 1145141;
	int hsh[2005], cnt[2005];
	map<int, int> mp;
	void clear()
	{
		mp.clear();
		memset(hsh, 0, sizeof(hsh));
		memset(cnt, 0, sizeof(cnt));
	}
	void update(int l, int r)
	{
		for(int i = l; i <= r; ++i)
		{
			++cnt[i];
			hsh[i] = inc(mul(hsh[i], base), ecnt);
		}
	}
	int calc()
	{
		int res = 0;
		int zcnt = 0, ocnt = 0;
		mp.clear();
		for(int i = 1; i < n; ++i)
		{
			zcnt += (cnt[i] == 0);
			ocnt += (cnt[i] == 1);
			if(cnt[i] > 0) mp[hsh[i]]++;
		}
		res += zcnt * (ecnt - 1) - zcnt * (zcnt - 1) / 2;
		res += ocnt;
		for(auto now : mp)
		{
			int c = now.se;
			res += c * (c - 1) / 2;
		}
		return res;
	}
	void work()
	{
		for(int cas = 1; cas <= m; ++cas)
		{
			++ecnt;
			int l, r;
			read(l), read(r);
			if(l > r) swap(l, r);
			if(l < r) update(l, r - 1);
			printf("%d\n", calc());
		}
	}
};
void work()
{
	read(n), read(m);
	ecnt = n - 1;
	if(n <= 2000 && m <= 2000) 
		Brute3::work();
	else assert(0);
}
int main()
{
	scanf("%d", &T);
	while(T--)
		work();
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3856kb

input:

3
4 3
2 4
4 2
3 3
7 3
3 4
1 2
1 7
6 4
1 3
4 6
2 5
3 4

output:

6
5
6
18
19
6
3
1
0
0

result:

wrong answer 4th numbers differ - expected: '21', found: '18'