QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735695#9482. Count Pseudo-PalindromeszqsWA 1456ms76056kbC++14995b2024-11-11 21:20:002024-11-11 21:20:01

Judging History

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

  • [2024-11-11 21:20:01]
  • 评测
  • 测评结果:WA
  • 用时:1456ms
  • 内存:76056kb
  • [2024-11-11 21:20:00]
  • 提交

answer

#include <cstdio>
#include <random>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cstring>

typedef unsigned long long ull;
std::mt19937_64 rnd(19410622);
std::unordered_multiset<int> tab;
std::set<int> s;
int a[1000005], b[1000005], ans1[1000005], ans2[1000005], lst[500005], n;
ull hsh[1000005];
void solve(int *ans) {
	s.clear(), tab.clear(), tab.insert(0), memset(lst, 0, sizeof lst);
	for (int i = 1; i <= n + n; ++ i) {//r=i;
		hsh[i] = hsh[i - 1] ^ b[a[i]];
		if (lst[a[i]]) s.erase(lst[a[i]]);
		else s.insert(i), lst[a[i]] = i;
		if (s.size()) {
			int x = *-- s.end();
			ans[x] += tab.count(hsh[i] ^ b[a[x]]);
		}
		tab.insert(hsh[i]);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) b[i] = rnd();
	for (int i = 1; i <= n + n; ++ i) scanf("%d", a + i);
	solve(ans1), std::reverse(a + 1, a + n + 1), solve(ans2);
	for (int i = 1; i <= n + n; ++ i) printf("%d ", ans1[i] + ans2[n + n + 1 - i]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 14052kb

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 2ms
memory: 14068kb

input:

3
2 1 2 3 1 3

output:

1 2 2 2 2 1 

result:

ok 6 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 14052kb

input:

4
1 2 4 3 4 1 3 2

output:

1 2 1 2 1 3 1 1 

result:

ok 8 tokens

Test #4:

score: 0
Accepted
time: 1ms
memory: 14348kb

input:

1
1 1

output:

1 1 

result:

ok 2 tokens

Test #5:

score: -100
Wrong Answer
time: 1456ms
memory: 76056kb

input:

500000
233733 151347 468353 495903 234861 297169 312993 2734 287872 359375 79017 285205 219439 37290 409190 194953 306816 472906 123794 121028 66509 62235 385879 300188 485875 72413 167304 333428 33910 220100 151575 22575 206653 82054 111518 34032 48702 198940 6262 222529 170641 1735 38943 235003 11...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

wrong answer 222nd words differ - expected: '1', found: '2'