Submission #676484

# Submission time Handle Problem Language Result Execution time Memory
676484 2022-12-31T03:36:47 Z penguin133 Pilot (NOI19_pilot) C++17
100 / 100
933 ms 59720 KB
#include <bits/stdc++.h>
using namespace std;
int parent[1000005];
long long root[1000005];
pair<int, int> arr[1000005];
pair<int, long long> s[1000005];
int exis[1000005];
int getr(int p){
	if(parent[p] == p)return p;
	else return parent[p] = getr(parent[p]);
}
void merge(int a,int b){
	a = getr(a);b=getr(b);
	if(a != b){
		root[a]  += root[b];
		parent[b] = parent[a];
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,q;
	cin >> n >> q;
	for(int i=1;i<=n;i++){
		parent[i]= i;
		root[i] = 1;
	}
	for(int i=1;i<=n;i++){
		cin >> arr[i].first;
		arr[i].second = i;
		s[i].first = arr[i].first;
	}
	sort(arr+1, arr + n+1);
	sort(s+1, s + n+1);
	long long ans = 0;
	for(int i=1;i<=n;i++){
		int cur = arr[i].second;
		exis[cur] = true;
		
		if(exis[cur-1] == true && exis[cur+1] == true){
			ans -= (root[getr(cur-1)] * (root[getr(cur-1)]+1))/2;
			ans -= (root[getr(cur+1)] * (root[getr(cur+1)] + 1))/2;
			merge(cur-1, cur);
			merge(cur, cur+1);
			ans += root[getr(cur-1)] * (root[getr(cur-1)] +1 )/2;
		}
		else{
			if(exis[cur-1] == true){
				ans -= root[getr(cur-1)] * (root[getr(cur-1)] + 1)/2;
				merge(cur-1, cur);
				ans += root[getr(cur-1)] * (root[getr(cur-1)]+1)/2;
			}
			else if(exis[cur+1] == true){
				ans -= root[getr(cur+1)] * (root[getr(cur+1)] + 1)/2;
				merge(cur, cur+1);
				ans += root[getr(cur)]*(root[getr(cur)] + 1)/2;
			}
			else{
				ans++;
			}
		}
		
		if(i == n || arr[i].first != arr[i+1].first){
			s[i].second = ans;
		}
	}
	for(int i=0;i<q;i++){
		int a;
		cin >> a;
		int start = 1, end = n;
		int index = -1;
		while(start <= end){
			int m = (start+end)/2;
			if(s[m].first <= a){
				index = max(index, m);
				start = m + 1;
			}
			else{
				end = m -1;
			}
		}
		cout << s[index].second << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4556 KB Output is correct
2 Correct 27 ms 4840 KB Output is correct
3 Correct 28 ms 4428 KB Output is correct
4 Correct 24 ms 4372 KB Output is correct
5 Correct 28 ms 4400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6080 KB Output is correct
2 Correct 36 ms 6092 KB Output is correct
3 Correct 36 ms 5964 KB Output is correct
4 Correct 36 ms 6164 KB Output is correct
5 Correct 35 ms 5964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 6152 KB Output is correct
2 Correct 44 ms 6136 KB Output is correct
3 Correct 40 ms 6072 KB Output is correct
4 Correct 39 ms 6424 KB Output is correct
5 Correct 41 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 33 ms 4556 KB Output is correct
12 Correct 27 ms 4840 KB Output is correct
13 Correct 28 ms 4428 KB Output is correct
14 Correct 24 ms 4372 KB Output is correct
15 Correct 28 ms 4400 KB Output is correct
16 Correct 27 ms 4388 KB Output is correct
17 Correct 30 ms 4776 KB Output is correct
18 Correct 29 ms 4888 KB Output is correct
19 Correct 25 ms 4436 KB Output is correct
20 Correct 27 ms 4684 KB Output is correct
21 Correct 27 ms 4436 KB Output is correct
22 Correct 25 ms 4592 KB Output is correct
23 Correct 27 ms 4684 KB Output is correct
24 Correct 25 ms 4436 KB Output is correct
25 Correct 33 ms 4552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 33 ms 4556 KB Output is correct
27 Correct 27 ms 4840 KB Output is correct
28 Correct 28 ms 4428 KB Output is correct
29 Correct 24 ms 4372 KB Output is correct
30 Correct 28 ms 4400 KB Output is correct
31 Correct 35 ms 6080 KB Output is correct
32 Correct 36 ms 6092 KB Output is correct
33 Correct 36 ms 5964 KB Output is correct
34 Correct 36 ms 6164 KB Output is correct
35 Correct 35 ms 5964 KB Output is correct
36 Correct 49 ms 6152 KB Output is correct
37 Correct 44 ms 6136 KB Output is correct
38 Correct 40 ms 6072 KB Output is correct
39 Correct 39 ms 6424 KB Output is correct
40 Correct 41 ms 6272 KB Output is correct
41 Correct 27 ms 4388 KB Output is correct
42 Correct 30 ms 4776 KB Output is correct
43 Correct 29 ms 4888 KB Output is correct
44 Correct 25 ms 4436 KB Output is correct
45 Correct 27 ms 4684 KB Output is correct
46 Correct 27 ms 4436 KB Output is correct
47 Correct 25 ms 4592 KB Output is correct
48 Correct 27 ms 4684 KB Output is correct
49 Correct 25 ms 4436 KB Output is correct
50 Correct 33 ms 4552 KB Output is correct
51 Correct 55 ms 6048 KB Output is correct
52 Correct 61 ms 5864 KB Output is correct
53 Correct 55 ms 6104 KB Output is correct
54 Correct 53 ms 5896 KB Output is correct
55 Correct 50 ms 6104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 33 ms 4556 KB Output is correct
27 Correct 27 ms 4840 KB Output is correct
28 Correct 28 ms 4428 KB Output is correct
29 Correct 24 ms 4372 KB Output is correct
30 Correct 28 ms 4400 KB Output is correct
31 Correct 35 ms 6080 KB Output is correct
32 Correct 36 ms 6092 KB Output is correct
33 Correct 36 ms 5964 KB Output is correct
34 Correct 36 ms 6164 KB Output is correct
35 Correct 35 ms 5964 KB Output is correct
36 Correct 49 ms 6152 KB Output is correct
37 Correct 44 ms 6136 KB Output is correct
38 Correct 40 ms 6072 KB Output is correct
39 Correct 39 ms 6424 KB Output is correct
40 Correct 41 ms 6272 KB Output is correct
41 Correct 27 ms 4388 KB Output is correct
42 Correct 30 ms 4776 KB Output is correct
43 Correct 29 ms 4888 KB Output is correct
44 Correct 25 ms 4436 KB Output is correct
45 Correct 27 ms 4684 KB Output is correct
46 Correct 27 ms 4436 KB Output is correct
47 Correct 25 ms 4592 KB Output is correct
48 Correct 27 ms 4684 KB Output is correct
49 Correct 25 ms 4436 KB Output is correct
50 Correct 33 ms 4552 KB Output is correct
51 Correct 55 ms 6048 KB Output is correct
52 Correct 61 ms 5864 KB Output is correct
53 Correct 55 ms 6104 KB Output is correct
54 Correct 53 ms 5896 KB Output is correct
55 Correct 50 ms 6104 KB Output is correct
56 Correct 891 ms 57524 KB Output is correct
57 Correct 899 ms 58832 KB Output is correct
58 Correct 915 ms 54884 KB Output is correct
59 Correct 877 ms 56204 KB Output is correct
60 Correct 933 ms 59720 KB Output is correct