답안 #965481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965481 2024-04-18T17:56:18 Z red24 Pilot (NOI19_pilot) C++14
23 / 100
45 ms 40188 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;
 
void make(int x)
{
	parent[x] = x;
	siz[x] = 1;
}
 
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);
 
	parent[y] = x;
	siz[x] += siz[y];
}
 
int f(int x)
{
	return ((x)*(x+1))/2ll;
}
 
void solve()
{
	int n, q; cin >> n >> q;
	vi a(n+2);
	for (int i = 1; i <= n; i++) cin >> a[i];
 
	const int mx = (int)1e6 + 69420;
	parent = vi(n+10);
	siz = vi(n+10);
 
	vi ans(mx+1);
	vvi idx(mx+1);
 
	for (int i = 1; i <= n; i++)
	{
		idx[a[i]].pb(i);
	}		
	int res = 0;
 
	for (int i = 1; i <= n+9; i++) make(i);
	a[0] = INF;
	a[n+1] = INF;
 
	for (int el = 1; el <= mx-100; el++)
	{
		for (auto i : idx[el])
		{
			if (siz[find(i)] == 1) res++;
			if (a[i+1] <= el)
			{
				if (find(i+1) == find(i)) continue;
				res -= f(siz[find(i+1)]);
				res -= f(siz[find(i)]);
				unite(i, i+1);
				res += f(siz[find(i)]);
			}
			if (a[i-1] <= el)
			{
				if (find(i-1) == find(i)) continue;
				res -= f(siz[find(i-1)]);
				res -= f(siz[find(i)]);
				unite(i, i-1);
				res += f(siz[find(i)]);
			}
		}
		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"; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 38236 KB Output is correct
2 Correct 40 ms 39164 KB Output is correct
3 Incorrect 29 ms 37980 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 40016 KB Output is correct
2 Correct 40 ms 40020 KB Output is correct
3 Correct 40 ms 39768 KB Output is correct
4 Correct 41 ms 40152 KB Output is correct
5 Correct 39 ms 39772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 40092 KB Output is correct
2 Correct 43 ms 39856 KB Output is correct
3 Correct 44 ms 39768 KB Output is correct
4 Correct 43 ms 40188 KB Output is correct
5 Correct 45 ms 39972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 33880 KB Output is correct
2 Correct 12 ms 33884 KB Output is correct
3 Correct 10 ms 33884 KB Output is correct
4 Correct 12 ms 33884 KB Output is correct
5 Correct 11 ms 33796 KB Output is correct
6 Incorrect 11 ms 33884 KB Output isn't correct
7 Halted 0 ms 0 KB -