Submission #319741

# Submission time Handle Problem Language Result Execution time Memory
319741 2020-11-06T10:37:37 Z soroush Pilot (NOI19_pilot) C++14
100 / 100
936 ms 87516 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e6+100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , t;
int a[maxn];
vector < int > pos[maxn];
ll ans[maxn];
ll sum;
ll sz[maxn];
int par[maxn];

ll C(ll x){
	return(x * (x - 1) / 2);
}

int getpar(int v){
	return((v == par[v])?v : par[v] = getpar(par[v]));
}

void merge(int u , int v){
	u = getpar(u) , v = getpar(v);
	if(u == v)return;
	if(sz[u] > sz[v])
		swap(u , v);
	sum -= C(sz[u] + 1);
	sum -= C(sz[v] + 1);
	sz[v] += sz[u];
	par[u] = v;
	sum +=C(sz[v] + 1);
}

void add(int x){
	for(auto i : pos[x]	)
		par[i] = i , sz[i] = 1 , sum += C(sz[i] + 1);
	for(auto i : pos[x]){
		if(i > 1 and a[i - 1] <= x){
			merge(i , i - 1);
		}
		if(i < n and a[i + 1] <= x){
			merge(i , i + 1);
		}
	}
}

int32_t main(){
    migmig;
    cin >> n >> t;
	for(int i = 1 ; i <= n ; i ++)
		cin >> a[i] , pos[a[i]].pb(i);
	for(int i = 0 ; i < maxn ; i ++)
		add(i), ans[i] = sum;
	while(t -- ){
		int x;
		cin >> x;
		cout << ans[x] << endl;
	}
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 23 ms 31724 KB Output is correct
12 Correct 23 ms 31724 KB Output is correct
13 Correct 23 ms 31852 KB Output is correct
14 Correct 23 ms 31724 KB Output is correct
15 Correct 23 ms 31852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 23 ms 31724 KB Output is correct
12 Correct 23 ms 31724 KB Output is correct
13 Correct 23 ms 31852 KB Output is correct
14 Correct 23 ms 31724 KB Output is correct
15 Correct 23 ms 31852 KB Output is correct
16 Correct 23 ms 31724 KB Output is correct
17 Correct 23 ms 31724 KB Output is correct
18 Correct 23 ms 31732 KB Output is correct
19 Correct 24 ms 31872 KB Output is correct
20 Correct 23 ms 31852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 23 ms 31724 KB Output is correct
12 Correct 23 ms 31724 KB Output is correct
13 Correct 23 ms 31852 KB Output is correct
14 Correct 23 ms 31724 KB Output is correct
15 Correct 23 ms 31852 KB Output is correct
16 Correct 23 ms 31724 KB Output is correct
17 Correct 23 ms 31724 KB Output is correct
18 Correct 23 ms 31732 KB Output is correct
19 Correct 24 ms 31872 KB Output is correct
20 Correct 23 ms 31852 KB Output is correct
21 Correct 24 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 24 ms 31720 KB Output is correct
24 Correct 25 ms 31724 KB Output is correct
25 Correct 24 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 35684 KB Output is correct
2 Correct 74 ms 36836 KB Output is correct
3 Correct 53 ms 35556 KB Output is correct
4 Correct 74 ms 36452 KB Output is correct
5 Correct 52 ms 35556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 38244 KB Output is correct
2 Correct 69 ms 38248 KB Output is correct
3 Correct 71 ms 38244 KB Output is correct
4 Correct 68 ms 38444 KB Output is correct
5 Correct 68 ms 38116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 38652 KB Output is correct
2 Correct 78 ms 38244 KB Output is correct
3 Correct 74 ms 38244 KB Output is correct
4 Correct 74 ms 38628 KB Output is correct
5 Correct 78 ms 38372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 55 ms 35684 KB Output is correct
12 Correct 74 ms 36836 KB Output is correct
13 Correct 53 ms 35556 KB Output is correct
14 Correct 74 ms 36452 KB Output is correct
15 Correct 52 ms 35556 KB Output is correct
16 Correct 55 ms 35564 KB Output is correct
17 Correct 77 ms 36964 KB Output is correct
18 Correct 76 ms 36836 KB Output is correct
19 Correct 53 ms 35428 KB Output is correct
20 Correct 74 ms 36708 KB Output is correct
21 Correct 54 ms 35432 KB Output is correct
22 Correct 71 ms 36584 KB Output is correct
23 Correct 54 ms 35960 KB Output is correct
24 Correct 74 ms 36464 KB Output is correct
25 Correct 54 ms 35672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 23 ms 31724 KB Output is correct
12 Correct 23 ms 31724 KB Output is correct
13 Correct 23 ms 31852 KB Output is correct
14 Correct 23 ms 31724 KB Output is correct
15 Correct 23 ms 31852 KB Output is correct
16 Correct 23 ms 31724 KB Output is correct
17 Correct 23 ms 31724 KB Output is correct
18 Correct 23 ms 31732 KB Output is correct
19 Correct 24 ms 31872 KB Output is correct
20 Correct 23 ms 31852 KB Output is correct
21 Correct 24 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 24 ms 31720 KB Output is correct
24 Correct 25 ms 31724 KB Output is correct
25 Correct 24 ms 31724 KB Output is correct
26 Correct 55 ms 35684 KB Output is correct
27 Correct 74 ms 36836 KB Output is correct
28 Correct 53 ms 35556 KB Output is correct
29 Correct 74 ms 36452 KB Output is correct
30 Correct 52 ms 35556 KB Output is correct
31 Correct 67 ms 38244 KB Output is correct
32 Correct 69 ms 38248 KB Output is correct
33 Correct 71 ms 38244 KB Output is correct
34 Correct 68 ms 38444 KB Output is correct
35 Correct 68 ms 38116 KB Output is correct
36 Correct 74 ms 38652 KB Output is correct
37 Correct 78 ms 38244 KB Output is correct
38 Correct 74 ms 38244 KB Output is correct
39 Correct 74 ms 38628 KB Output is correct
40 Correct 78 ms 38372 KB Output is correct
41 Correct 55 ms 35564 KB Output is correct
42 Correct 77 ms 36964 KB Output is correct
43 Correct 76 ms 36836 KB Output is correct
44 Correct 53 ms 35428 KB Output is correct
45 Correct 74 ms 36708 KB Output is correct
46 Correct 54 ms 35432 KB Output is correct
47 Correct 71 ms 36584 KB Output is correct
48 Correct 54 ms 35960 KB Output is correct
49 Correct 74 ms 36464 KB Output is correct
50 Correct 54 ms 35672 KB Output is correct
51 Correct 85 ms 37092 KB Output is correct
52 Correct 101 ms 37860 KB Output is correct
53 Correct 86 ms 37092 KB Output is correct
54 Correct 99 ms 37856 KB Output is correct
55 Correct 87 ms 37092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31852 KB Output is correct
2 Correct 25 ms 31724 KB Output is correct
3 Correct 23 ms 31724 KB Output is correct
4 Correct 23 ms 31724 KB Output is correct
5 Correct 23 ms 31724 KB Output is correct
6 Correct 24 ms 31724 KB Output is correct
7 Correct 23 ms 31740 KB Output is correct
8 Correct 24 ms 31724 KB Output is correct
9 Correct 24 ms 31724 KB Output is correct
10 Correct 26 ms 31724 KB Output is correct
11 Correct 23 ms 31724 KB Output is correct
12 Correct 23 ms 31724 KB Output is correct
13 Correct 23 ms 31852 KB Output is correct
14 Correct 23 ms 31724 KB Output is correct
15 Correct 23 ms 31852 KB Output is correct
16 Correct 23 ms 31724 KB Output is correct
17 Correct 23 ms 31724 KB Output is correct
18 Correct 23 ms 31732 KB Output is correct
19 Correct 24 ms 31872 KB Output is correct
20 Correct 23 ms 31852 KB Output is correct
21 Correct 24 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 24 ms 31720 KB Output is correct
24 Correct 25 ms 31724 KB Output is correct
25 Correct 24 ms 31724 KB Output is correct
26 Correct 55 ms 35684 KB Output is correct
27 Correct 74 ms 36836 KB Output is correct
28 Correct 53 ms 35556 KB Output is correct
29 Correct 74 ms 36452 KB Output is correct
30 Correct 52 ms 35556 KB Output is correct
31 Correct 67 ms 38244 KB Output is correct
32 Correct 69 ms 38248 KB Output is correct
33 Correct 71 ms 38244 KB Output is correct
34 Correct 68 ms 38444 KB Output is correct
35 Correct 68 ms 38116 KB Output is correct
36 Correct 74 ms 38652 KB Output is correct
37 Correct 78 ms 38244 KB Output is correct
38 Correct 74 ms 38244 KB Output is correct
39 Correct 74 ms 38628 KB Output is correct
40 Correct 78 ms 38372 KB Output is correct
41 Correct 55 ms 35564 KB Output is correct
42 Correct 77 ms 36964 KB Output is correct
43 Correct 76 ms 36836 KB Output is correct
44 Correct 53 ms 35428 KB Output is correct
45 Correct 74 ms 36708 KB Output is correct
46 Correct 54 ms 35432 KB Output is correct
47 Correct 71 ms 36584 KB Output is correct
48 Correct 54 ms 35960 KB Output is correct
49 Correct 74 ms 36464 KB Output is correct
50 Correct 54 ms 35672 KB Output is correct
51 Correct 85 ms 37092 KB Output is correct
52 Correct 101 ms 37860 KB Output is correct
53 Correct 86 ms 37092 KB Output is correct
54 Correct 99 ms 37856 KB Output is correct
55 Correct 87 ms 37092 KB Output is correct
56 Correct 864 ms 85604 KB Output is correct
57 Correct 884 ms 86756 KB Output is correct
58 Correct 835 ms 83040 KB Output is correct
59 Correct 860 ms 84836 KB Output is correct
60 Correct 936 ms 87516 KB Output is correct