Submission #383314

# Submission time Handle Problem Language Result Execution time Memory
383314 2021-03-29T14:56:50 Z MODDI Mountains (NOI20_mountains) C++14
100 / 100
848 ms 113500 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;
int n;
vl arr;
vector<ll> tree[12 * 100000];
void build(int node, int l, int r){
	if(l == r)
		tree[node].pb(arr[l]);
	else{
		ll mid = (l + r) / 2;
		build(node * 2, l, mid);
		build(node * 2 + 1, mid + 1, r);
		merge(tree[node * 2].begin(), tree[node * 2].end(), tree[node * 2 + 1].begin(), tree[node * 2 + 1].end(), back_inserter(tree[node]));
	}
}
ll query(int node, int l, int r, int L, int R, ll k){
	if(r < L || l > R)	return 0;
	if(L <= l && r <= R){
		return lower_bound(tree[node].begin(), tree[node].end(), k) -tree[node].begin();
	}
	int mid = (l + r) / 2;
	ll left = query(node  * 2, l, mid, L, R, k), right = query(node * 2 + 1, mid + 1, r, L, R, k);
	return left + right;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i = 0; i < n; i++){
		ll a;
		cin>>a;
		arr.pb(a);
	}
	build(1, 0, n - 1);
	ll rez = 0;
	for(int i =1; i < n - 1; i++){
		ll left = query(1, 0, n - 1, 0, i, arr[i]);
		ll right = query(1, 0, n - 1, i, n - 1, arr[i]);
		if(left > 0 && right > 0)
			rez += (left * right);
	}
	cout<<rez<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28524 KB Output is correct
2 Correct 450 ms 107868 KB Output is correct
3 Correct 446 ms 107740 KB Output is correct
4 Correct 449 ms 107752 KB Output is correct
5 Correct 445 ms 107740 KB Output is correct
6 Correct 447 ms 107868 KB Output is correct
7 Correct 445 ms 107792 KB Output is correct
8 Correct 453 ms 107876 KB Output is correct
9 Correct 454 ms 107868 KB Output is correct
10 Correct 458 ms 107788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 107740 KB Output is correct
2 Correct 451 ms 107868 KB Output is correct
3 Correct 444 ms 107740 KB Output is correct
4 Correct 449 ms 107868 KB Output is correct
5 Correct 447 ms 107828 KB Output is correct
6 Correct 450 ms 107904 KB Output is correct
7 Correct 447 ms 107924 KB Output is correct
8 Correct 428 ms 107868 KB Output is correct
9 Correct 433 ms 107740 KB Output is correct
10 Correct 19 ms 28524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 107740 KB Output is correct
2 Correct 451 ms 107868 KB Output is correct
3 Correct 444 ms 107740 KB Output is correct
4 Correct 449 ms 107868 KB Output is correct
5 Correct 447 ms 107828 KB Output is correct
6 Correct 450 ms 107904 KB Output is correct
7 Correct 447 ms 107924 KB Output is correct
8 Correct 428 ms 107868 KB Output is correct
9 Correct 433 ms 107740 KB Output is correct
10 Correct 19 ms 28524 KB Output is correct
11 Correct 714 ms 107868 KB Output is correct
12 Correct 726 ms 107868 KB Output is correct
13 Correct 713 ms 107868 KB Output is correct
14 Correct 719 ms 107868 KB Output is correct
15 Correct 714 ms 107740 KB Output is correct
16 Correct 712 ms 107996 KB Output is correct
17 Correct 712 ms 107996 KB Output is correct
18 Correct 425 ms 107740 KB Output is correct
19 Correct 418 ms 107740 KB Output is correct
20 Correct 19 ms 28524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28524 KB Output is correct
2 Correct 20 ms 28536 KB Output is correct
3 Correct 20 ms 28652 KB Output is correct
4 Correct 20 ms 28652 KB Output is correct
5 Correct 20 ms 28652 KB Output is correct
6 Correct 19 ms 28652 KB Output is correct
7 Correct 20 ms 28652 KB Output is correct
8 Correct 19 ms 28652 KB Output is correct
9 Correct 20 ms 28524 KB Output is correct
10 Correct 20 ms 28524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28524 KB Output is correct
2 Correct 20 ms 28536 KB Output is correct
3 Correct 20 ms 28652 KB Output is correct
4 Correct 20 ms 28652 KB Output is correct
5 Correct 20 ms 28652 KB Output is correct
6 Correct 19 ms 28652 KB Output is correct
7 Correct 20 ms 28652 KB Output is correct
8 Correct 19 ms 28652 KB Output is correct
9 Correct 20 ms 28524 KB Output is correct
10 Correct 20 ms 28524 KB Output is correct
11 Correct 34 ms 30956 KB Output is correct
12 Correct 35 ms 30956 KB Output is correct
13 Correct 35 ms 30956 KB Output is correct
14 Correct 36 ms 31084 KB Output is correct
15 Correct 35 ms 30956 KB Output is correct
16 Correct 35 ms 30956 KB Output is correct
17 Correct 35 ms 30956 KB Output is correct
18 Correct 35 ms 30956 KB Output is correct
19 Correct 34 ms 30700 KB Output is correct
20 Correct 19 ms 28524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 107740 KB Output is correct
2 Correct 451 ms 107868 KB Output is correct
3 Correct 444 ms 107740 KB Output is correct
4 Correct 449 ms 107868 KB Output is correct
5 Correct 447 ms 107828 KB Output is correct
6 Correct 450 ms 107904 KB Output is correct
7 Correct 447 ms 107924 KB Output is correct
8 Correct 428 ms 107868 KB Output is correct
9 Correct 433 ms 107740 KB Output is correct
10 Correct 19 ms 28524 KB Output is correct
11 Correct 714 ms 107868 KB Output is correct
12 Correct 726 ms 107868 KB Output is correct
13 Correct 713 ms 107868 KB Output is correct
14 Correct 719 ms 107868 KB Output is correct
15 Correct 714 ms 107740 KB Output is correct
16 Correct 712 ms 107996 KB Output is correct
17 Correct 712 ms 107996 KB Output is correct
18 Correct 425 ms 107740 KB Output is correct
19 Correct 418 ms 107740 KB Output is correct
20 Correct 19 ms 28524 KB Output is correct
21 Correct 801 ms 107868 KB Output is correct
22 Correct 806 ms 107740 KB Output is correct
23 Correct 804 ms 107868 KB Output is correct
24 Correct 800 ms 107920 KB Output is correct
25 Correct 800 ms 107868 KB Output is correct
26 Correct 807 ms 107868 KB Output is correct
27 Correct 844 ms 107868 KB Output is correct
28 Correct 427 ms 107868 KB Output is correct
29 Correct 428 ms 107752 KB Output is correct
30 Correct 22 ms 28524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28524 KB Output is correct
2 Correct 450 ms 107868 KB Output is correct
3 Correct 446 ms 107740 KB Output is correct
4 Correct 449 ms 107752 KB Output is correct
5 Correct 445 ms 107740 KB Output is correct
6 Correct 447 ms 107868 KB Output is correct
7 Correct 445 ms 107792 KB Output is correct
8 Correct 453 ms 107876 KB Output is correct
9 Correct 454 ms 107868 KB Output is correct
10 Correct 458 ms 107788 KB Output is correct
11 Correct 441 ms 107740 KB Output is correct
12 Correct 451 ms 107868 KB Output is correct
13 Correct 444 ms 107740 KB Output is correct
14 Correct 449 ms 107868 KB Output is correct
15 Correct 447 ms 107828 KB Output is correct
16 Correct 450 ms 107904 KB Output is correct
17 Correct 447 ms 107924 KB Output is correct
18 Correct 428 ms 107868 KB Output is correct
19 Correct 433 ms 107740 KB Output is correct
20 Correct 19 ms 28524 KB Output is correct
21 Correct 714 ms 107868 KB Output is correct
22 Correct 726 ms 107868 KB Output is correct
23 Correct 713 ms 107868 KB Output is correct
24 Correct 719 ms 107868 KB Output is correct
25 Correct 714 ms 107740 KB Output is correct
26 Correct 712 ms 107996 KB Output is correct
27 Correct 712 ms 107996 KB Output is correct
28 Correct 425 ms 107740 KB Output is correct
29 Correct 418 ms 107740 KB Output is correct
30 Correct 19 ms 28524 KB Output is correct
31 Correct 19 ms 28524 KB Output is correct
32 Correct 20 ms 28536 KB Output is correct
33 Correct 20 ms 28652 KB Output is correct
34 Correct 20 ms 28652 KB Output is correct
35 Correct 20 ms 28652 KB Output is correct
36 Correct 19 ms 28652 KB Output is correct
37 Correct 20 ms 28652 KB Output is correct
38 Correct 19 ms 28652 KB Output is correct
39 Correct 20 ms 28524 KB Output is correct
40 Correct 20 ms 28524 KB Output is correct
41 Correct 34 ms 30956 KB Output is correct
42 Correct 35 ms 30956 KB Output is correct
43 Correct 35 ms 30956 KB Output is correct
44 Correct 36 ms 31084 KB Output is correct
45 Correct 35 ms 30956 KB Output is correct
46 Correct 35 ms 30956 KB Output is correct
47 Correct 35 ms 30956 KB Output is correct
48 Correct 35 ms 30956 KB Output is correct
49 Correct 34 ms 30700 KB Output is correct
50 Correct 19 ms 28524 KB Output is correct
51 Correct 801 ms 107868 KB Output is correct
52 Correct 806 ms 107740 KB Output is correct
53 Correct 804 ms 107868 KB Output is correct
54 Correct 800 ms 107920 KB Output is correct
55 Correct 800 ms 107868 KB Output is correct
56 Correct 807 ms 107868 KB Output is correct
57 Correct 844 ms 107868 KB Output is correct
58 Correct 427 ms 107868 KB Output is correct
59 Correct 428 ms 107752 KB Output is correct
60 Correct 22 ms 28524 KB Output is correct
61 Correct 829 ms 113372 KB Output is correct
62 Correct 836 ms 113372 KB Output is correct
63 Correct 830 ms 113372 KB Output is correct
64 Correct 829 ms 113372 KB Output is correct
65 Correct 848 ms 113392 KB Output is correct
66 Correct 832 ms 113372 KB Output is correct
67 Correct 834 ms 113372 KB Output is correct
68 Correct 830 ms 113500 KB Output is correct
69 Correct 813 ms 109660 KB Output is correct
70 Correct 19 ms 28524 KB Output is correct