Submission #383310

# Submission time Handle Problem Language Result Execution time Memory
383310 2021-03-29T14:48:43 Z MODDI Mountains (NOI20_mountains) C++14
2 / 100
2000 ms 113508 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{
		int 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]));
	}
}
int query(int node, int l, int r, int L, int R, int k){
	if(r < L || l > R)	return 0;
	if(L <= l && r <= R){
		int cnt = 0;
		while(tree[node][cnt] < k && cnt < (r - l + 1))
			cnt++;
		return cnt;
	}
	int mid = (l + r) / 2;
	int 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(){
	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 28672 KB Output is correct
2 Correct 492 ms 113236 KB Output is correct
3 Correct 489 ms 113380 KB Output is correct
4 Correct 499 ms 113368 KB Output is correct
5 Correct 511 ms 113304 KB Output is correct
6 Correct 492 ms 113508 KB Output is correct
7 Correct 491 ms 113364 KB Output is correct
8 Correct 500 ms 113492 KB Output is correct
9 Correct 547 ms 113364 KB Output is correct
10 Correct 497 ms 113384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 108288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 108288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 28524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 28524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 108288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28672 KB Output is correct
2 Correct 492 ms 113236 KB Output is correct
3 Correct 489 ms 113380 KB Output is correct
4 Correct 499 ms 113368 KB Output is correct
5 Correct 511 ms 113304 KB Output is correct
6 Correct 492 ms 113508 KB Output is correct
7 Correct 491 ms 113364 KB Output is correct
8 Correct 500 ms 113492 KB Output is correct
9 Correct 547 ms 113364 KB Output is correct
10 Correct 497 ms 113384 KB Output is correct
11 Execution timed out 2088 ms 108288 KB Time limit exceeded
12 Halted 0 ms 0 KB -