답안 #572389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572389 2022-06-04T10:28:54 Z MODDI Pilot (NOI19_pilot) C++14
40 / 100
218 ms 37452 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
const int maxn = 1e6 + 5;
int n, q;
vl arr;
int parent[maxn];
int sz[maxn];
bool on[maxn];
int find(int v){
	if(v == parent[v])
		return v;
	return parent[v] = find(parent[v]);
}
ll rez = 0;
void mrg(int a, int b){
	a = find(a);
	b = find(b);
	if(a != b){
		rez -= sz[a] * (sz[a] + 1) / 2;
		rez -= sz[b] * (sz[b] + 1) / 2;
		sz[a] += sz[b];
		rez += sz[a] * (sz[a] + 1) / 2;
		parent[b] = a;
	}
}
vi G[maxn];
ll ans[maxn];
int main(){
	cin>>n>>q;
	arr.resize(n);
	for(int i = 0; i < n; i++){
		parent[i] = i;
		sz[i] = 1;
	}
	for(int i = 0; i < n; i++){
		cin>>arr[i];
		G[arr[i]].pb(i);
	}
	for(int i = 1; i <= 1000000; i++){
		for(int x : G[i]){
			++rez;
			on[x] = 1;
			if(x && on[x-1]) mrg(x, x-1);
			if(x != n-1 && on[x+1]) mrg(x, x + 1);
		}
		ans[i] = rez;
	}
	for(int i = 0; i < q; i++){
		ll a;
		cin>>a;
		cout<<ans[a]<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 20 ms 31604 KB Output is correct
13 Correct 19 ms 31540 KB Output is correct
14 Correct 22 ms 31576 KB Output is correct
15 Correct 19 ms 31516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 20 ms 31604 KB Output is correct
13 Correct 19 ms 31540 KB Output is correct
14 Correct 22 ms 31576 KB Output is correct
15 Correct 19 ms 31516 KB Output is correct
16 Correct 17 ms 31572 KB Output is correct
17 Correct 18 ms 31572 KB Output is correct
18 Correct 22 ms 31640 KB Output is correct
19 Correct 18 ms 31700 KB Output is correct
20 Correct 19 ms 31632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 20 ms 31604 KB Output is correct
13 Correct 19 ms 31540 KB Output is correct
14 Correct 22 ms 31576 KB Output is correct
15 Correct 19 ms 31516 KB Output is correct
16 Correct 17 ms 31572 KB Output is correct
17 Correct 18 ms 31572 KB Output is correct
18 Correct 22 ms 31640 KB Output is correct
19 Correct 18 ms 31700 KB Output is correct
20 Correct 19 ms 31632 KB Output is correct
21 Correct 20 ms 31680 KB Output is correct
22 Correct 20 ms 31612 KB Output is correct
23 Correct 26 ms 31672 KB Output is correct
24 Correct 25 ms 31632 KB Output is correct
25 Correct 19 ms 31556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 35296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 201 ms 37188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 218 ms 37452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Incorrect 62 ms 35296 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 20 ms 31604 KB Output is correct
13 Correct 19 ms 31540 KB Output is correct
14 Correct 22 ms 31576 KB Output is correct
15 Correct 19 ms 31516 KB Output is correct
16 Correct 17 ms 31572 KB Output is correct
17 Correct 18 ms 31572 KB Output is correct
18 Correct 22 ms 31640 KB Output is correct
19 Correct 18 ms 31700 KB Output is correct
20 Correct 19 ms 31632 KB Output is correct
21 Correct 20 ms 31680 KB Output is correct
22 Correct 20 ms 31612 KB Output is correct
23 Correct 26 ms 31672 KB Output is correct
24 Correct 25 ms 31632 KB Output is correct
25 Correct 19 ms 31556 KB Output is correct
26 Incorrect 62 ms 35296 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31604 KB Output is correct
2 Correct 18 ms 31572 KB Output is correct
3 Correct 17 ms 31572 KB Output is correct
4 Correct 21 ms 31568 KB Output is correct
5 Correct 17 ms 31540 KB Output is correct
6 Correct 21 ms 31608 KB Output is correct
7 Correct 18 ms 31572 KB Output is correct
8 Correct 19 ms 31604 KB Output is correct
9 Correct 17 ms 31572 KB Output is correct
10 Correct 19 ms 31516 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 20 ms 31604 KB Output is correct
13 Correct 19 ms 31540 KB Output is correct
14 Correct 22 ms 31576 KB Output is correct
15 Correct 19 ms 31516 KB Output is correct
16 Correct 17 ms 31572 KB Output is correct
17 Correct 18 ms 31572 KB Output is correct
18 Correct 22 ms 31640 KB Output is correct
19 Correct 18 ms 31700 KB Output is correct
20 Correct 19 ms 31632 KB Output is correct
21 Correct 20 ms 31680 KB Output is correct
22 Correct 20 ms 31612 KB Output is correct
23 Correct 26 ms 31672 KB Output is correct
24 Correct 25 ms 31632 KB Output is correct
25 Correct 19 ms 31556 KB Output is correct
26 Incorrect 62 ms 35296 KB Output isn't correct
27 Halted 0 ms 0 KB -