Submission #1063011

# Submission time Handle Problem Language Result Execution time Memory
1063011 2024-08-17T13:19:08 Z _rain_ Pilot (NOI19_pilot) C++14
100 / 100
352 ms 53072 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define debug false

const int maxn = 1e6;
struct QUERY
{
	int q;
	int id;
	bool operator < (const QUERY& other) const{
		return q < other.q;
	}
};
QUERY p[maxn+2],a[maxn+2];
i64 answer = 0 , ans[maxn+2] = {};
int par[maxn+2] , sz[maxn+2];
int n , q;
bool used[maxn+2];

i64 get(int sz){
	return (i64)sz*(sz+1)/2;
}
int find(int u){
	return u == par[u] ? par[u] : par[u] = find(par[u]);
}
void unite(int u , int v){
	u = find(u) , v = find(v);
	if (u==v) return;
	if (sz[u] < sz[v]) swap(u,v);
	answer -= get(sz[v]); answer -= get(sz[u]);
	par[v] = u;
	sz[u] += sz[v];
	answer += get(sz[u]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) sz[i] = 1 , par[i] = i;
	for (int i = 1; i <= n; ++i){
		cin >> a[i].q;
		a[i].id = i;
	}
	for (int i = 1; i <= q; ++i){
		cin >> p[i].q;
		p[i].id = i;
	}
	sort(a+1,a+n+1);
	sort(p+1,p+q+1);
	int idx = 1;
	for (int i = 1; i <= q; ++i){
		while (idx <= n && a[idx].q <= p[i].q){
			int id = a[idx].id;
			answer += get(sz[id]);
			if (used[id - 1]) unite(id - 1 , id);
			if (used[id + 1]) unite(id , id + 1);
			used[id] = true;
			++idx;
		}
		ans[p[i].id] = answer;
	}
	for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 460 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 460 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2652 KB Output is correct
2 Correct 15 ms 2596 KB Output is correct
3 Correct 16 ms 2392 KB Output is correct
4 Correct 15 ms 2588 KB Output is correct
5 Correct 13 ms 2376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5568 KB Output is correct
2 Correct 27 ms 5460 KB Output is correct
3 Correct 24 ms 5464 KB Output is correct
4 Correct 25 ms 5720 KB Output is correct
5 Correct 26 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5460 KB Output is correct
2 Correct 31 ms 5720 KB Output is correct
3 Correct 25 ms 5676 KB Output is correct
4 Correct 29 ms 5716 KB Output is correct
5 Correct 27 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 17 ms 2652 KB Output is correct
12 Correct 15 ms 2596 KB Output is correct
13 Correct 16 ms 2392 KB Output is correct
14 Correct 15 ms 2588 KB Output is correct
15 Correct 13 ms 2376 KB Output is correct
16 Correct 13 ms 2396 KB Output is correct
17 Correct 17 ms 2684 KB Output is correct
18 Correct 13 ms 2648 KB Output is correct
19 Correct 11 ms 2392 KB Output is correct
20 Correct 13 ms 2652 KB Output is correct
21 Correct 14 ms 2392 KB Output is correct
22 Correct 13 ms 2652 KB Output is correct
23 Correct 12 ms 2616 KB Output is correct
24 Correct 11 ms 2396 KB Output is correct
25 Correct 12 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 460 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 17 ms 2652 KB Output is correct
27 Correct 15 ms 2596 KB Output is correct
28 Correct 16 ms 2392 KB Output is correct
29 Correct 15 ms 2588 KB Output is correct
30 Correct 13 ms 2376 KB Output is correct
31 Correct 25 ms 5568 KB Output is correct
32 Correct 27 ms 5460 KB Output is correct
33 Correct 24 ms 5464 KB Output is correct
34 Correct 25 ms 5720 KB Output is correct
35 Correct 26 ms 5460 KB Output is correct
36 Correct 28 ms 5460 KB Output is correct
37 Correct 31 ms 5720 KB Output is correct
38 Correct 25 ms 5676 KB Output is correct
39 Correct 29 ms 5716 KB Output is correct
40 Correct 27 ms 5712 KB Output is correct
41 Correct 13 ms 2396 KB Output is correct
42 Correct 17 ms 2684 KB Output is correct
43 Correct 13 ms 2648 KB Output is correct
44 Correct 11 ms 2392 KB Output is correct
45 Correct 13 ms 2652 KB Output is correct
46 Correct 14 ms 2392 KB Output is correct
47 Correct 13 ms 2652 KB Output is correct
48 Correct 12 ms 2616 KB Output is correct
49 Correct 11 ms 2396 KB Output is correct
50 Correct 12 ms 2652 KB Output is correct
51 Correct 32 ms 5464 KB Output is correct
52 Correct 32 ms 5324 KB Output is correct
53 Correct 31 ms 5460 KB Output is correct
54 Correct 31 ms 5208 KB Output is correct
55 Correct 30 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 460 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 17 ms 2652 KB Output is correct
27 Correct 15 ms 2596 KB Output is correct
28 Correct 16 ms 2392 KB Output is correct
29 Correct 15 ms 2588 KB Output is correct
30 Correct 13 ms 2376 KB Output is correct
31 Correct 25 ms 5568 KB Output is correct
32 Correct 27 ms 5460 KB Output is correct
33 Correct 24 ms 5464 KB Output is correct
34 Correct 25 ms 5720 KB Output is correct
35 Correct 26 ms 5460 KB Output is correct
36 Correct 28 ms 5460 KB Output is correct
37 Correct 31 ms 5720 KB Output is correct
38 Correct 25 ms 5676 KB Output is correct
39 Correct 29 ms 5716 KB Output is correct
40 Correct 27 ms 5712 KB Output is correct
41 Correct 13 ms 2396 KB Output is correct
42 Correct 17 ms 2684 KB Output is correct
43 Correct 13 ms 2648 KB Output is correct
44 Correct 11 ms 2392 KB Output is correct
45 Correct 13 ms 2652 KB Output is correct
46 Correct 14 ms 2392 KB Output is correct
47 Correct 13 ms 2652 KB Output is correct
48 Correct 12 ms 2616 KB Output is correct
49 Correct 11 ms 2396 KB Output is correct
50 Correct 12 ms 2652 KB Output is correct
51 Correct 32 ms 5464 KB Output is correct
52 Correct 32 ms 5324 KB Output is correct
53 Correct 31 ms 5460 KB Output is correct
54 Correct 31 ms 5208 KB Output is correct
55 Correct 30 ms 5480 KB Output is correct
56 Correct 346 ms 51968 KB Output is correct
57 Correct 337 ms 51308 KB Output is correct
58 Correct 330 ms 48832 KB Output is correct
59 Correct 352 ms 49940 KB Output is correct
60 Correct 344 ms 53072 KB Output is correct