QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#50182#4808. Great Partybvd#WA 13ms30888kbC++2.8kb2022-09-25 05:25:242022-09-25 05:25:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-25 05:25:24]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:30888kb
  • [2022-09-25 05:25:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int maxn = 100000;
const int blk = 350;
const int base = maxn+13;
const int oo1 = 1e9+7;
const int oo2 = 1e9+9;
const int maxx = 1e6;
int n, q;
int a[maxn+1];
int multiplier[maxx+1];
pii value_a[maxn+1];
vector<pii> Q;

pii hash_list[maxn+1];
pii powB[maxx+1];

vector<pii> hash_values;

int cnt[maxn+1];

#define K(x) pii(x.first/blk, x.second ^ -(x.first/blk & 1))

pii ad(pii x, pii y) { return {(x.first + y.first)%oo1, (x.second + y.second)%oo2}; }
pii mult(pii x, int y) { return {x.first*y%oo1, x.second*y%oo2}; }
pii mult(pii x, pii y) { return {x.first*y.first%oo1, x.second*y.second%oo2}; }
pii sub(pii x,pii y) { return {(x.first - y.first + oo1*oo1)%oo1, (x.second - y.second + oo2*oo2)%oo2}; }

int get_index(pii x) {
	return distance(begin(hash_values), lower_bound(all(hash_values), x));
}
main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	rep(i,0,maxx+1) multiplier[i] = 1;
	rep(i,1,n+1) {
		cin >> a[i];
		if (multiplier[a[i]] == 1) value_a[i] = {1,1};
		else value_a[i] = {oo1 - 1, oo2 - 1};
		multiplier[a[i]] = -multiplier[a[i]];
	}
	
	powB[0] = {1,1};
	rep(i,1,maxx+1) powB[i] = mult(powB[i-1], base);

	rep(i,0,q) {
		int l, r; cin >> l >> r;
		Q.push_back({l-1,r});
	}
	
	hash_list[0] = {0,0};
	rep(i,1,n+1) {
		hash_list[i] = ad(hash_list[i-1], mult(value_a[i], powB[a[i]]));
		//cout << value_a[i].first << ' ' << value_a[i].second << '\n';
		//cout << powB[a[i]].first << ' ' << powB[a[i]].second << '\n';
		//cout << hash_list[i].first << ' ' << hash_list[i].second << '\n';
	}
	
	rep(i,0,n+1) hash_values.push_back(hash_list[i]);
	sort(all(hash_values));
	hash_values.erase(unique(all(hash_values)), end(hash_values));
	
	vi s(sz(Q)), res = s;
	iota(all(s), 0);
	sort(all(s), [&](int s,int t) { return K(Q[s]) < K(Q[t]); });
	
	int L = 0, R = 0;
	cnt[get_index({0,0})]++;
	int total_res = 0;
	for (int qi : s) {
		pii q = Q[qi];
		while (L > q.first) {
			L--;
			int vt = get_index(hash_list[L]);
			total_res += cnt[vt];
			cnt[vt]++;
		}
		while (R < q.second) {
			R++;
			int vt = get_index(hash_list[R]);
			total_res += cnt[vt];
			cnt[vt]++;
		}
		while (L < q.first) {
			int vt = get_index(hash_list[L]);
			cnt[vt]--;
			total_res -= cnt[vt];
			L++;
		}
		while (R > q.second) {
			int vt = get_index(hash_list[R]);
			cnt[vt]--;
			total_res -= cnt[vt];
			R--;
		}
		int length = q.second - q.first;
		res[qi] = length * (length + 1) / 2 - total_res;
	}
	
	
	rep(i,0,q) cout << res[i] << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 29416kb

input:

4 5
1 2 2 4
1 2
2 3
3 4
1 3
2 4

output:

3
2
3
5
5

result:

ok 5 number(s): "3 2 3 5 5"

Test #2:

score: 0
Accepted
time: 3ms
memory: 30052kb

input:

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

output:

3
3
3
6
6

result:

ok 5 number(s): "3 3 3 6 6"

Test #3:

score: 0
Accepted
time: 8ms
memory: 30888kb

input:

10 10
3 7 3 1 6 6 10 3 3 3
9 10
5 10
3 7
5 6
5 6
9 10
3 10
1 4
6 6
1 4

output:

2
18
14
2
2
2
33
10
1
10

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 8ms
memory: 29408kb

input:

10 8
91 63 1 34 50 11 10 73 96 67
5 9
2 7
2 5
4 7
1 10
3 3
1 4
5 10

output:

15
21
10
10
55
1
10
21

result:

ok 8 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 29444kb

input:

10 6
9 539 285 408 615 861 951 413 319 368
4 4
8 10
1 7
3 9
2 3
2 10

output:

1
6
28
28
3
45

result:

ok 6 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 30112kb

input:

10 6
1348 7002 4687 6325 8253 5750 2464 5509 6543 8704
3 9
4 8
8 8
8 9
2 9
9 10

output:

28
15
1
3
36
3

result:

ok 6 numbers

Test #7:

score: 0
Accepted
time: 13ms
memory: 28748kb

input:

10 8
59041 28802 92255 14246 65768 79252 70656 81265 98363 85237
1 6
9 10
4 7
6 8
9 10
1 2
1 3
4 5

output:

21
3
10
6
3
3
6
3

result:

ok 8 numbers

Test #8:

score: 0
Accepted
time: 10ms
memory: 29416kb

input:

10 7
28607 249948 373828 584253 989446 308313 199311 253174 283937 133758
2 4
1 2
4 9
7 8
7 8
2 6
1 1

output:

6
3
21
3
3
15
1

result:

ok 7 numbers

Test #9:

score: -100
Wrong Answer
time: 11ms
memory: 30788kb

input:

100 98
6 9 6 10 8 10 3 4 7 5 4 10 2 10 4 5 2 1 7 1 3 1 4 1 1 2 6 9 3 10 2 5 3 2 6 2 1 7 7 6 5 4 2 5 3 2 7 2 6 2 9 7 10 7 4 2 9 3 3 7 9 1 4 9 6 1 5 5 8 3 7 5 8 3 9 5 8 7 8 6 6 3 2 3 8 1 8 1 5 9 1 8 6 3 3 7 10 6 5 5
48 72
14 46
23 28
37 84
1 65
45 72
9 19
9 81
37 53
47 50
25 26
26 88
51 54
53 69
22 94...

output:

323
559
20
1172
2136
404
65
2691
152
10
3
2011
10
151
2695
35
169
6
28
323
625
3070
376
4740
2919
135
1270
54
168
3074
135
3150
817
1535
91
2007
229
65
78
433
348
662
273
1124
941
987
2769
2273
463
151
229
5
3904
1370
104
1270
592
2268
298
699
375
986
1
229
152
738
119
104
3475
943
135
1
90
1172
208...

result:

wrong answer 1st numbers differ - expected: '316', found: '323'