Submission #965496

# Submission time Handle Problem Language Result Execution time Memory
965496 2024-04-18T18:24:57 Z red24 Pilot (NOI19_pilot) C++14
100 / 100
645 ms 104532 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define all(x) x.begin()+1, x.end()
const int INF = (int)1e17;

vi parent, siz;
int res = 0;

void make(int x)
{
	parent[x] = x;
	siz[x] = 1;
}

int f(int x)
{
	return ((x)*(x+1))/2ll;
}

int find(int x)
{
	if (parent[x] == x) return x;
	return parent[x] = find(parent[x]);
}

void unite(int x, int y)
{
	x = find(x); y = find(y);
	if (x == y) return;
	if (siz[x] < siz[y]) swap(x, y);

	res -= f(siz[x]);
	res -= f(siz[y]);

	siz[x] += siz[y];
	parent[y] = x;
	res += f(siz[x]);
}

void solve()
{
	int n, q; cin >> n >> q;
	vi a(n+1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	siz = vi(n+1);
	parent = vi(n+1);

	const int mx = (int)1e6 + 4529;
	vvi idx(mx+100);
	for (int i = 1; i <= n; i++) idx[a[i]].pb(i);

	for (int i = 1; i <= n; i++) make(i);
	vi ans(mx);
	vi vis(n+1);

	for (int el = 1; el <= mx-100; el++)
	{
		for (int i : idx[el])
		{
			res++;
			vis[i] = 1;

			if (i < n && vis[i+1]) unite(i, i+1);
			if (i > 1 && vis[i-1]) unite(i, i-1);
		}
		ans[el] = res;
	}
	while (q--)
	{
		int x; cin >> x;
		cout << ans[x] << '\n';
	}
}
 
int32_t main()
{
	auto begin = std::chrono::high_resolution_clock::now();
	// FASTIO
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
 
 
 
	int T = 1;
	//cin >> T;
	for (int i = 1; i <= T; i++)
	{
		//cout << "Case #" << i << ": ";
		solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 9 ms 31832 KB Output is correct
12 Correct 10 ms 31836 KB Output is correct
13 Correct 11 ms 31764 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 9 ms 31832 KB Output is correct
12 Correct 10 ms 31836 KB Output is correct
13 Correct 11 ms 31764 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31880 KB Output is correct
16 Correct 10 ms 31836 KB Output is correct
17 Correct 10 ms 31732 KB Output is correct
18 Correct 10 ms 31836 KB Output is correct
19 Correct 11 ms 31836 KB Output is correct
20 Correct 11 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 9 ms 31832 KB Output is correct
12 Correct 10 ms 31836 KB Output is correct
13 Correct 11 ms 31764 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31880 KB Output is correct
16 Correct 10 ms 31836 KB Output is correct
17 Correct 10 ms 31732 KB Output is correct
18 Correct 10 ms 31836 KB Output is correct
19 Correct 11 ms 31836 KB Output is correct
20 Correct 11 ms 31832 KB Output is correct
21 Correct 11 ms 31984 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 11 ms 31836 KB Output is correct
24 Correct 10 ms 31856 KB Output is correct
25 Correct 11 ms 31960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 37724 KB Output is correct
2 Correct 41 ms 38464 KB Output is correct
3 Correct 30 ms 37228 KB Output is correct
4 Correct 36 ms 37844 KB Output is correct
5 Correct 30 ms 37224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39832 KB Output is correct
2 Correct 39 ms 39672 KB Output is correct
3 Correct 42 ms 39660 KB Output is correct
4 Correct 38 ms 39976 KB Output is correct
5 Correct 41 ms 39572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 40016 KB Output is correct
2 Correct 44 ms 39760 KB Output is correct
3 Correct 42 ms 39588 KB Output is correct
4 Correct 42 ms 40272 KB Output is correct
5 Correct 44 ms 40084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 29 ms 37724 KB Output is correct
12 Correct 41 ms 38464 KB Output is correct
13 Correct 30 ms 37228 KB Output is correct
14 Correct 36 ms 37844 KB Output is correct
15 Correct 30 ms 37224 KB Output is correct
16 Correct 27 ms 37212 KB Output is correct
17 Correct 41 ms 38492 KB Output is correct
18 Correct 41 ms 38484 KB Output is correct
19 Correct 28 ms 37200 KB Output is correct
20 Correct 38 ms 38236 KB Output is correct
21 Correct 31 ms 37468 KB Output is correct
22 Correct 37 ms 37988 KB Output is correct
23 Correct 30 ms 37456 KB Output is correct
24 Correct 37 ms 37980 KB Output is correct
25 Correct 28 ms 37468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 9 ms 31832 KB Output is correct
12 Correct 10 ms 31836 KB Output is correct
13 Correct 11 ms 31764 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31880 KB Output is correct
16 Correct 10 ms 31836 KB Output is correct
17 Correct 10 ms 31732 KB Output is correct
18 Correct 10 ms 31836 KB Output is correct
19 Correct 11 ms 31836 KB Output is correct
20 Correct 11 ms 31832 KB Output is correct
21 Correct 11 ms 31984 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 11 ms 31836 KB Output is correct
24 Correct 10 ms 31856 KB Output is correct
25 Correct 11 ms 31960 KB Output is correct
26 Correct 29 ms 37724 KB Output is correct
27 Correct 41 ms 38464 KB Output is correct
28 Correct 30 ms 37228 KB Output is correct
29 Correct 36 ms 37844 KB Output is correct
30 Correct 30 ms 37224 KB Output is correct
31 Correct 37 ms 39832 KB Output is correct
32 Correct 39 ms 39672 KB Output is correct
33 Correct 42 ms 39660 KB Output is correct
34 Correct 38 ms 39976 KB Output is correct
35 Correct 41 ms 39572 KB Output is correct
36 Correct 41 ms 40016 KB Output is correct
37 Correct 44 ms 39760 KB Output is correct
38 Correct 42 ms 39588 KB Output is correct
39 Correct 42 ms 40272 KB Output is correct
40 Correct 44 ms 40084 KB Output is correct
41 Correct 27 ms 37212 KB Output is correct
42 Correct 41 ms 38492 KB Output is correct
43 Correct 41 ms 38484 KB Output is correct
44 Correct 28 ms 37200 KB Output is correct
45 Correct 38 ms 38236 KB Output is correct
46 Correct 31 ms 37468 KB Output is correct
47 Correct 37 ms 37988 KB Output is correct
48 Correct 30 ms 37456 KB Output is correct
49 Correct 37 ms 37980 KB Output is correct
50 Correct 28 ms 37468 KB Output is correct
51 Correct 45 ms 38740 KB Output is correct
52 Correct 65 ms 39364 KB Output is correct
53 Correct 46 ms 38992 KB Output is correct
54 Correct 58 ms 39424 KB Output is correct
55 Correct 46 ms 39000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31836 KB Output is correct
2 Correct 10 ms 31836 KB Output is correct
3 Correct 11 ms 31728 KB Output is correct
4 Correct 10 ms 31836 KB Output is correct
5 Correct 10 ms 31836 KB Output is correct
6 Correct 10 ms 31924 KB Output is correct
7 Correct 10 ms 31836 KB Output is correct
8 Correct 10 ms 31836 KB Output is correct
9 Correct 10 ms 31924 KB Output is correct
10 Correct 10 ms 31832 KB Output is correct
11 Correct 9 ms 31832 KB Output is correct
12 Correct 10 ms 31836 KB Output is correct
13 Correct 11 ms 31764 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31880 KB Output is correct
16 Correct 10 ms 31836 KB Output is correct
17 Correct 10 ms 31732 KB Output is correct
18 Correct 10 ms 31836 KB Output is correct
19 Correct 11 ms 31836 KB Output is correct
20 Correct 11 ms 31832 KB Output is correct
21 Correct 11 ms 31984 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 11 ms 31836 KB Output is correct
24 Correct 10 ms 31856 KB Output is correct
25 Correct 11 ms 31960 KB Output is correct
26 Correct 29 ms 37724 KB Output is correct
27 Correct 41 ms 38464 KB Output is correct
28 Correct 30 ms 37228 KB Output is correct
29 Correct 36 ms 37844 KB Output is correct
30 Correct 30 ms 37224 KB Output is correct
31 Correct 37 ms 39832 KB Output is correct
32 Correct 39 ms 39672 KB Output is correct
33 Correct 42 ms 39660 KB Output is correct
34 Correct 38 ms 39976 KB Output is correct
35 Correct 41 ms 39572 KB Output is correct
36 Correct 41 ms 40016 KB Output is correct
37 Correct 44 ms 39760 KB Output is correct
38 Correct 42 ms 39588 KB Output is correct
39 Correct 42 ms 40272 KB Output is correct
40 Correct 44 ms 40084 KB Output is correct
41 Correct 27 ms 37212 KB Output is correct
42 Correct 41 ms 38492 KB Output is correct
43 Correct 41 ms 38484 KB Output is correct
44 Correct 28 ms 37200 KB Output is correct
45 Correct 38 ms 38236 KB Output is correct
46 Correct 31 ms 37468 KB Output is correct
47 Correct 37 ms 37988 KB Output is correct
48 Correct 30 ms 37456 KB Output is correct
49 Correct 37 ms 37980 KB Output is correct
50 Correct 28 ms 37468 KB Output is correct
51 Correct 45 ms 38740 KB Output is correct
52 Correct 65 ms 39364 KB Output is correct
53 Correct 46 ms 38992 KB Output is correct
54 Correct 58 ms 39424 KB Output is correct
55 Correct 46 ms 39000 KB Output is correct
56 Correct 577 ms 101144 KB Output is correct
57 Correct 547 ms 103384 KB Output is correct
58 Correct 513 ms 98348 KB Output is correct
59 Correct 531 ms 100784 KB Output is correct
60 Correct 645 ms 104532 KB Output is correct