Submission #689892

# Submission time Handle Problem Language Result Execution time Memory
689892 2023-01-29T17:03:14 Z sudheerays123 Pilot (NOI19_pilot) C++17
100 / 100
578 ms 67704 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 1e6+5 , INF = 1e18 , MOD = 1e9+7;

vector<ll> par(N) , ssize(N);

void make_set(ll n){
	for(ll i = 1; i <= n; i++){
		par[i] = i;
		ssize[i] = 1;
	}
}

ll find(ll x){
	if(x == par[x]) return x;
	return par[x] = find(par[x]);
}

ll cnt = 0;

ll cost(ll z){
	return ((z*(z+1))/2);
}

void add_edge(ll a, ll b){

	a = find(a);
	b = find(b);

	if(a == b) return;

	cnt -= cost(ssize[a]);
	cnt -= cost(ssize[b]);
	cnt += cost(ssize[a]+ssize[b]);

	par[a] = b;
	ssize[b] += ssize[a];
}

void solve(){

	ll n,q;
	cin >> n >> q;

	vector<ll> a(n+5);
	vector<pair<ll,ll>> v;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		v.push_back(make_pair(a[i],i));
	}

	a[0] = INF;
	a[n+1] = INF;

	sort(v.begin(),v.end());
	make_set(n);

	vector<ll> ans(N);

	for(auto u : v){	
		cnt++;
		if(a[u.second-1] <= u.first) add_edge(u.second-1,u.second);
		if(a[u.second+1] <= u.first) add_edge(u.second,u.second+1);

		ans[u.first] = cnt;
	}

	for(ll i = 1; i <= N; i++) if(!ans[i]) ans[i] = ans[i-1];

	while(q--){
		ll x;
		cin >> x;

		cout << ans[x] << "\n";
	}
}

int main(){

	fast;

	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23800 KB Output is correct
12 Correct 12 ms 23724 KB Output is correct
13 Correct 12 ms 23816 KB Output is correct
14 Correct 12 ms 23816 KB Output is correct
15 Correct 12 ms 23804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23800 KB Output is correct
12 Correct 12 ms 23724 KB Output is correct
13 Correct 12 ms 23816 KB Output is correct
14 Correct 12 ms 23816 KB Output is correct
15 Correct 12 ms 23804 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 13 ms 23824 KB Output is correct
20 Correct 16 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23800 KB Output is correct
12 Correct 12 ms 23724 KB Output is correct
13 Correct 12 ms 23816 KB Output is correct
14 Correct 12 ms 23816 KB Output is correct
15 Correct 12 ms 23804 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 13 ms 23824 KB Output is correct
20 Correct 16 ms 23796 KB Output is correct
21 Correct 13 ms 23876 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 13 ms 23756 KB Output is correct
25 Correct 12 ms 23872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 26768 KB Output is correct
2 Correct 32 ms 26800 KB Output is correct
3 Correct 32 ms 26688 KB Output is correct
4 Correct 31 ms 26664 KB Output is correct
5 Correct 36 ms 26532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 28228 KB Output is correct
2 Correct 57 ms 28192 KB Output is correct
3 Correct 40 ms 28100 KB Output is correct
4 Correct 49 ms 28272 KB Output is correct
5 Correct 41 ms 28108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 28356 KB Output is correct
2 Correct 44 ms 28236 KB Output is correct
3 Correct 43 ms 28228 KB Output is correct
4 Correct 40 ms 28504 KB Output is correct
5 Correct 42 ms 28396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 32 ms 26768 KB Output is correct
12 Correct 32 ms 26800 KB Output is correct
13 Correct 32 ms 26688 KB Output is correct
14 Correct 31 ms 26664 KB Output is correct
15 Correct 36 ms 26532 KB Output is correct
16 Correct 33 ms 26560 KB Output is correct
17 Correct 39 ms 26796 KB Output is correct
18 Correct 34 ms 26880 KB Output is correct
19 Correct 32 ms 26572 KB Output is correct
20 Correct 32 ms 26820 KB Output is correct
21 Correct 35 ms 26540 KB Output is correct
22 Correct 30 ms 26752 KB Output is correct
23 Correct 33 ms 26836 KB Output is correct
24 Correct 31 ms 26668 KB Output is correct
25 Correct 35 ms 26800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23800 KB Output is correct
12 Correct 12 ms 23724 KB Output is correct
13 Correct 12 ms 23816 KB Output is correct
14 Correct 12 ms 23816 KB Output is correct
15 Correct 12 ms 23804 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 13 ms 23824 KB Output is correct
20 Correct 16 ms 23796 KB Output is correct
21 Correct 13 ms 23876 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 13 ms 23756 KB Output is correct
25 Correct 12 ms 23872 KB Output is correct
26 Correct 32 ms 26768 KB Output is correct
27 Correct 32 ms 26800 KB Output is correct
28 Correct 32 ms 26688 KB Output is correct
29 Correct 31 ms 26664 KB Output is correct
30 Correct 36 ms 26532 KB Output is correct
31 Correct 54 ms 28228 KB Output is correct
32 Correct 57 ms 28192 KB Output is correct
33 Correct 40 ms 28100 KB Output is correct
34 Correct 49 ms 28272 KB Output is correct
35 Correct 41 ms 28108 KB Output is correct
36 Correct 46 ms 28356 KB Output is correct
37 Correct 44 ms 28236 KB Output is correct
38 Correct 43 ms 28228 KB Output is correct
39 Correct 40 ms 28504 KB Output is correct
40 Correct 42 ms 28396 KB Output is correct
41 Correct 33 ms 26560 KB Output is correct
42 Correct 39 ms 26796 KB Output is correct
43 Correct 34 ms 26880 KB Output is correct
44 Correct 32 ms 26572 KB Output is correct
45 Correct 32 ms 26820 KB Output is correct
46 Correct 35 ms 26540 KB Output is correct
47 Correct 30 ms 26752 KB Output is correct
48 Correct 33 ms 26836 KB Output is correct
49 Correct 31 ms 26668 KB Output is correct
50 Correct 35 ms 26800 KB Output is correct
51 Correct 53 ms 28124 KB Output is correct
52 Correct 50 ms 28004 KB Output is correct
53 Correct 50 ms 28100 KB Output is correct
54 Correct 55 ms 28040 KB Output is correct
55 Correct 49 ms 28156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23820 KB Output is correct
2 Correct 13 ms 23804 KB Output is correct
3 Correct 13 ms 23824 KB Output is correct
4 Correct 13 ms 23812 KB Output is correct
5 Correct 13 ms 23908 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23800 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23796 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23800 KB Output is correct
12 Correct 12 ms 23724 KB Output is correct
13 Correct 12 ms 23816 KB Output is correct
14 Correct 12 ms 23816 KB Output is correct
15 Correct 12 ms 23804 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 13 ms 23824 KB Output is correct
20 Correct 16 ms 23796 KB Output is correct
21 Correct 13 ms 23876 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 13 ms 23756 KB Output is correct
25 Correct 12 ms 23872 KB Output is correct
26 Correct 32 ms 26768 KB Output is correct
27 Correct 32 ms 26800 KB Output is correct
28 Correct 32 ms 26688 KB Output is correct
29 Correct 31 ms 26664 KB Output is correct
30 Correct 36 ms 26532 KB Output is correct
31 Correct 54 ms 28228 KB Output is correct
32 Correct 57 ms 28192 KB Output is correct
33 Correct 40 ms 28100 KB Output is correct
34 Correct 49 ms 28272 KB Output is correct
35 Correct 41 ms 28108 KB Output is correct
36 Correct 46 ms 28356 KB Output is correct
37 Correct 44 ms 28236 KB Output is correct
38 Correct 43 ms 28228 KB Output is correct
39 Correct 40 ms 28504 KB Output is correct
40 Correct 42 ms 28396 KB Output is correct
41 Correct 33 ms 26560 KB Output is correct
42 Correct 39 ms 26796 KB Output is correct
43 Correct 34 ms 26880 KB Output is correct
44 Correct 32 ms 26572 KB Output is correct
45 Correct 32 ms 26820 KB Output is correct
46 Correct 35 ms 26540 KB Output is correct
47 Correct 30 ms 26752 KB Output is correct
48 Correct 33 ms 26836 KB Output is correct
49 Correct 31 ms 26668 KB Output is correct
50 Correct 35 ms 26800 KB Output is correct
51 Correct 53 ms 28124 KB Output is correct
52 Correct 50 ms 28004 KB Output is correct
53 Correct 50 ms 28100 KB Output is correct
54 Correct 55 ms 28040 KB Output is correct
55 Correct 49 ms 28156 KB Output is correct
56 Correct 578 ms 66336 KB Output is correct
57 Correct 498 ms 66844 KB Output is correct
58 Correct 477 ms 64188 KB Output is correct
59 Correct 513 ms 65104 KB Output is correct
60 Correct 498 ms 67704 KB Output is correct