Submission #1011124

# Submission time Handle Problem Language Result Execution time Memory
1011124 2024-06-29T20:54:03 Z xnqs Pilot (NOI19_pilot) C++17
100 / 100
339 ms 52748 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

struct Query {
	int cap, idx;
	Query():
		cap(0), idx(0) {}
	Query(int cap, int idx):
		cap(cap), idx(idx) {}
};

struct DSUBootleg {
	int64_t ans = 0;
	int left[1000005];
	int right[1000005];
	
	void Activate(int pos) {
		left[pos] = right[pos] = pos;

		if (left[pos-1]) {
			left[pos] = left[pos-1];
			int l = left[pos-1];
			int r = pos-1;
			ans -= 1LL*(r-l+1)*(r-l+2)/2;
		}
		if (right[pos+1]) {
			right[pos] = right[pos+1];
			int l = pos+1;
			int r = right[pos+1];
			ans -= 1LL*(r-l+1)*(r-l+2)/2;
		}

		left[right[pos]] = left[pos];
		right[left[pos]] = right[pos];
		ans += 1LL*(right[pos]-left[pos]+1)*(right[pos]-left[pos]+2)/2;
	}

	int64_t GetAns() {
		return ans;
	}
};

int x, q;
int arr[1000005];
int64_t ret[1000005];
DSUBootleg dsu;
std::vector<int> sorted_pos;
std::vector<Query> queries;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	std::cin >> x >> q;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
		sorted_pos.emplace_back(i);
	}

	std::sort(sorted_pos.begin(),sorted_pos.end(),[&](int a, int b) {
		return arr[a] < arr[b];
	});

	for (int i = 0, tmp; i < q; i++) {
		std::cin >> tmp;
		queries.emplace_back(tmp,i);
	}

	std::sort(queries.begin(),queries.end(),[](const Query& a, const Query& b) {
		return a.cap < b.cap;
	});

	int scanline = 0;
	for (const auto& [cap, idx] : queries) {
		while (scanline<x&&arr[sorted_pos[scanline]]<=cap) {
			dsu.Activate(sorted_pos[scanline]);
			++scanline;
		}

		/*for (int i = 1; i <= x; i++) {
			std::cout << dsu.left[i] << " " << dsu.right[i] << "\n";
		}
		std::cout << "\n";*/

		ret[idx] = dsu.GetAns();
	}

	for (int i = 0; i < q; i++) {
		std::cout << ret[i] << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6660 KB Output is correct
23 Correct 2 ms 6612 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 11788 KB Output is correct
2 Correct 16 ms 11984 KB Output is correct
3 Correct 14 ms 11740 KB Output is correct
4 Correct 14 ms 9700 KB Output is correct
5 Correct 14 ms 9692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 14068 KB Output is correct
2 Correct 25 ms 14164 KB Output is correct
3 Correct 25 ms 14212 KB Output is correct
4 Correct 25 ms 14172 KB Output is correct
5 Correct 25 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 14260 KB Output is correct
2 Correct 28 ms 14168 KB Output is correct
3 Correct 32 ms 14160 KB Output is correct
4 Correct 25 ms 14160 KB Output is correct
5 Correct 26 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 15 ms 11788 KB Output is correct
12 Correct 16 ms 11984 KB Output is correct
13 Correct 14 ms 11740 KB Output is correct
14 Correct 14 ms 9700 KB Output is correct
15 Correct 14 ms 9692 KB Output is correct
16 Correct 16 ms 9688 KB Output is correct
17 Correct 14 ms 11996 KB Output is correct
18 Correct 14 ms 11996 KB Output is correct
19 Correct 15 ms 9696 KB Output is correct
20 Correct 14 ms 11992 KB Output is correct
21 Correct 13 ms 9692 KB Output is correct
22 Correct 14 ms 9788 KB Output is correct
23 Correct 14 ms 11996 KB Output is correct
24 Correct 13 ms 9892 KB Output is correct
25 Correct 14 ms 11740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6660 KB Output is correct
23 Correct 2 ms 6612 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 15 ms 11788 KB Output is correct
27 Correct 16 ms 11984 KB Output is correct
28 Correct 14 ms 11740 KB Output is correct
29 Correct 14 ms 9700 KB Output is correct
30 Correct 14 ms 9692 KB Output is correct
31 Correct 24 ms 14068 KB Output is correct
32 Correct 25 ms 14164 KB Output is correct
33 Correct 25 ms 14212 KB Output is correct
34 Correct 25 ms 14172 KB Output is correct
35 Correct 25 ms 14164 KB Output is correct
36 Correct 26 ms 14260 KB Output is correct
37 Correct 28 ms 14168 KB Output is correct
38 Correct 32 ms 14160 KB Output is correct
39 Correct 25 ms 14160 KB Output is correct
40 Correct 26 ms 14412 KB Output is correct
41 Correct 16 ms 9688 KB Output is correct
42 Correct 14 ms 11996 KB Output is correct
43 Correct 14 ms 11996 KB Output is correct
44 Correct 15 ms 9696 KB Output is correct
45 Correct 14 ms 11992 KB Output is correct
46 Correct 13 ms 9692 KB Output is correct
47 Correct 14 ms 9788 KB Output is correct
48 Correct 14 ms 11996 KB Output is correct
49 Correct 13 ms 9892 KB Output is correct
50 Correct 14 ms 11740 KB Output is correct
51 Correct 40 ms 15948 KB Output is correct
52 Correct 39 ms 16012 KB Output is correct
53 Correct 36 ms 15964 KB Output is correct
54 Correct 32 ms 15996 KB Output is correct
55 Correct 32 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6660 KB Output is correct
23 Correct 2 ms 6612 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 15 ms 11788 KB Output is correct
27 Correct 16 ms 11984 KB Output is correct
28 Correct 14 ms 11740 KB Output is correct
29 Correct 14 ms 9700 KB Output is correct
30 Correct 14 ms 9692 KB Output is correct
31 Correct 24 ms 14068 KB Output is correct
32 Correct 25 ms 14164 KB Output is correct
33 Correct 25 ms 14212 KB Output is correct
34 Correct 25 ms 14172 KB Output is correct
35 Correct 25 ms 14164 KB Output is correct
36 Correct 26 ms 14260 KB Output is correct
37 Correct 28 ms 14168 KB Output is correct
38 Correct 32 ms 14160 KB Output is correct
39 Correct 25 ms 14160 KB Output is correct
40 Correct 26 ms 14412 KB Output is correct
41 Correct 16 ms 9688 KB Output is correct
42 Correct 14 ms 11996 KB Output is correct
43 Correct 14 ms 11996 KB Output is correct
44 Correct 15 ms 9696 KB Output is correct
45 Correct 14 ms 11992 KB Output is correct
46 Correct 13 ms 9692 KB Output is correct
47 Correct 14 ms 9788 KB Output is correct
48 Correct 14 ms 11996 KB Output is correct
49 Correct 13 ms 9892 KB Output is correct
50 Correct 14 ms 11740 KB Output is correct
51 Correct 40 ms 15948 KB Output is correct
52 Correct 39 ms 16012 KB Output is correct
53 Correct 36 ms 15964 KB Output is correct
54 Correct 32 ms 15996 KB Output is correct
55 Correct 32 ms 15964 KB Output is correct
56 Correct 325 ms 52120 KB Output is correct
57 Correct 326 ms 51252 KB Output is correct
58 Correct 334 ms 51116 KB Output is correct
59 Correct 309 ms 50724 KB Output is correct
60 Correct 339 ms 52748 KB Output is correct