QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712894#9584. 顾影自怜fsy_juruoWA 100ms31128kbC++171.4kb2024-11-05 17:24:542024-11-05 17:24:55

Judging History

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

  • [2024-11-05 17:24:55]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:31128kb
  • [2024-11-05 17:24:54]
  • 提交

answer

#include <bits/stdc++.h>
using LL = long long;

const int maxN = 1e6 + 10;
int T, n, k;
int a[maxN], max[maxN][21];

std::vector<int> e[maxN];

std::set<int> allowed, banned, neg;

int main() {
	std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
	std::cin >> T;
	while(T--) {
		std::cin >> n >> k;

		if(k == 1) {
			LL ans = 1ll * n * (n + 1) / 2;
			std::cout << ans << "\n";
			continue;
		}

		for(int i = 1; i <= n; i++) {
			std::cin >> a[i];
			e[a[i]].emplace_back(i);
			banned.insert(i);
			neg.insert(-i);
		}

		LL ans = 0;
		banned.insert(n + 1);
		neg.insert(0);

		for(int i = 1; i <= n; i++) {
			for(auto u : e[i]) {
				banned.erase(u);
				allowed.insert(u);
				neg.erase(-u);
			}
			if(e[i].size() < k) continue;

			for(int j = 0; j <= e[i].size() - k; j++) {
				int require = e[i][j + k - 1];
				int pos = *banned.lower_bound(e[i][j]);

				if(require <= pos - 1) {
					int lpos = -(*neg.lower_bound(-e[i][j]));
					lpos = std::max(lpos, (j == 0 ? 0 : e[i][j - 1]));

					ans += 1ll * (e[i][j] - lpos) * (pos - require);
				//	std::cout << pos << " " << lpos << " " << i << " " << e[i][j] << " " << require << "\n";
				}
			}
		}

		std::cout << ans << "\n";

		for(int i = 1; i <= n; i++) {
			e[a[i]].clear();
		}

		allowed.clear();
		banned.clear();
		neg.clear();
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

7
0

result:

ok 2 lines

Test #2:

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

input:

1
1000000 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 ...

output:

500000500000

result:

ok single line: '500000500000'

Test #3:

score: -100
Wrong Answer
time: 100ms
memory: 30876kb

input:

158921
1 1
1
2 1
1 1
2 2
1 1
2 1
1 2
2 2
1 2
2 1
2 1
2 2
2 1
2 1
2 2
2 2
2 2
3 1
1 1 1
3 2
1 1 1
3 3
1 1 1
3 1
1 1 2
3 2
1 1 2
3 3
1 1 2
3 1
1 1 3
3 2
1 1 3
3 3
1 1 3
3 1
1 2 1
3 2
1 2 1
3 3
1 2 1
3 1
1 2 2
3 2
1 2 2
3 3
1 2 2
3 1
1 2 3
3 2
1 2 3
3 3
1 2 3
3 1
1 3 1
3 2
1 3 1
3 3
1 3 1
3 1
1 3 2
3 2...

output:

1
0
1
1
3
0
3
0
0
3
3
1
0
1
0
1
0
1
0
1
0
0
6
0
1
0
3
0
6
0
1
3
0
0
6
0
2
0
6
0
0
0
6
0
0
0
6
0
0
0
6
0
2
0
6
3
0
3
0
3
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
2
0
0
0
0
1
1
0
6
6
0
0
0
0
0
0
0
0
2
0
0
2
0
2
3
2
0
0
0
0
0
0
0
1
0
1
1
6
3
1
10
1
0
3
1
0
1
0
1
0
1
0
0
6
1
0
0
1
1
0
0
0
0
0
1...

result:

wrong answer 2nd lines differ - expected: '3', found: '0'