QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226148#5425. Proposition CompositionIshyRE 348ms3944kbC++142.7kb2023-10-25 16:52:242023-10-25 16:52:24

Judging History

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

  • [2023-10-25 16:52:24]
  • 评测
  • 测评结果:RE
  • 用时:348ms
  • 内存:3944kb
  • [2023-10-25 16:52: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()
	{
		clear();
		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;
}

/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

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
21
24
10
15
12
3
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 36ms
memory: 3856kb

input:

45540
10 9
10 1
1 10
10 1
1 10
1 10
10 1
1 10
3 3
10 1
10 4
1 2
1 10
3 4
1 10
7 6
7 1
5 6
1 7
6 6
7 1
6 7
9 7
3 3
7 7
5 4
1 1
9 1
9 1
6 5
8 7
1 8
4 4
5 6
1 1
1 8
6 6
4 5
3 3
3 2
3 1
3 3
3 9
3 1
3 3
2 2
3 3
3 1
2 2
1 1
2 3
3 1
10 1
2 1
7 1
1 7
3 8
1 3
1 3
3 3
1 3
2 2
1 3
1 3
3 3
3 6
3 1
1 3
1 3
1 3
1...

output:

45
36
36
36
36
36
36
36
36
45
36
28
21
21
15
10
10
10
6
36
44
50
57
28
21
15
28
28
21
21
15
15
10
3
1
1
3
3
3
3
1
1
1
0
0
45
21
3
1
1
1
1
1
1
1
3
1
1
1
1
1
45
36
36
36
36
36
36
36
3
3
1
0
0
0
0
0
0
3
1
0
0
15
10
10
0
0
0
0
0
0
0
0
28
34
21
6
6
6
6
1
0
0
21
15
15
0
0
0
0
0
0
0
45
53
0
0
0
0
0
0
0
0
1...

result:

ok 249586 numbers

Test #3:

score: 0
Accepted
time: 348ms
memory: 3944kb

input:

2507
86 4
41 41
36 36
31 30
86 1
110 22
1 110
110 1
11 11
110 1
110 1
110 1
1 110
107 106
72 72
106 106
74 74
1 110
110 1
58 58
110 1
110 1
1 110
101 100
110 1
100 100
110 1
8 7
114 180
114 1
114 1
114 1
1 114
1 114
114 1
37 38
49 48
105 106
1 114
90 90
1 114
9 9
114 1
67 68
20 20
114 1
1 114
54 55
...

output:

3655
3740
3823
3570
5995
5886
5886
5886
5886
5886
5886
5778
5778
5778
5778
5778
5778
5778
5778
5778
5778
5671
5671
5671
5671
5565
6441
6328
6328
6328
6328
6328
6216
6105
5995
5995
5995
5995
5995
5995
5886
5886
5886
5886
5778
5671
5671
5565
5565
5460
5460
5460
5460
5460
5356
5253
5253
5253
5151
5151
...

result:

ok 249877 numbers

Test #4:

score: -100
Runtime Error

input:

3
82425 27858
30801 30802
1 82425
73850 73850
1 82425
65949 65949
82425 1
76026 76025
61936 61936
82425 1
82425 1
82425 1
6504 6504
82425 1
25155 25156
79743 79743
1 82425
69406 69406
29247 29247
18351 18351
23171 23170
29704 29703
82425 1
1 82425
82425 1
74918 74917
22395 22394
893 894
82425 1
391 ...

output:


result: