Submission #563555

# Submission time Handle Problem Language Result Execution time Memory
563555 2022-05-17T13:21:40 Z Cookie Mountains (NOI20_mountains) C++14
100 / 100
287 ms 27084 KB
#include <bits/stdc++.h>
using namespace std;
#define LIFESUCKS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ar array
#include<cstdio>
#define vt vector
#include<fstream>
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define length(x) (int)(x).size()
#define fi first
#define se second
#define vt vector
int n;
ll a[300000];
ll b[300000];
vt<int>tree; vt<int>tr;
ll gett(int nd, int l, int r, int q_l, int q_r){
	if(q_l > r || q_r < l)return(0);
	if(q_l <= l && q_r >= r)return(tree[nd]);
	int mid = (l + r) >> 1;
	return(gett((nd << 1), l, mid, q_l, q_r) + gett((nd << 1) + 1, mid + 1, r, q_l, q_r));
}
ll get(int nd, int l, int r, int q_l, int q_r){
	if(q_l > r || q_r < l)return(0);
	if(q_l <= l && q_r >= r)return(tr[nd]);
	int mid = (l + r) >> 1;
	return(get((nd << 1), l, mid, q_l, q_r) + get((nd << 1) + 1, mid + 1, r, q_l, q_r));
}
void upd(int p){
	tree[p + n]++;
	for(int i = (p + n) >> 1; i >= 1; i = i >> 1){
		tree[i]++;
	}
}
void updd(int p, ll v){
	tr[p + n] += v;
	for(int i = (p + n) >> 1; i >= 1; i = i >> 1){
		tr[i] += v;
	}
}

int main(){
    LIFESUCKS;
    cin >> n;
    int cr = n;
    for(int i = 0; i < n; i++){
        cin >> a[i]; b[i] = a[i];
    }
    sort(b, b + n);
    for(int i = 0; i < n; i++){
        a[i] = lower_bound(b, b + n, a[i]) - b;
    }
	while(__builtin_popcount(n) != 1)n++;
	
	tree.resize(2 * n, 0);
	ll left[n] = {0};
	for(int i = cr - 1; i >= 0; i--){
	    left[i] = gett(1, 0, n - 1, 0, a[i] - 1);
	    upd(a[i]);
	}
	ll right[n] = {0};
	tr.resize(2 * n, 0);
	for(int i = 0; i < cr; i++ ){
	    right[i] = get(1, 0, n - 1, 0, a[i] - 1);
	    updd(a[i], 1);
	}
	ll ans = 0;
	for(int i = 1; i < n - 1; i++){
	    ans += (right[i] * left[i]);
	}
	cout << ans;
}

Compilation message

Mountains.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    7 | #pragma GCC optimization ("O3")
      | 
Mountains.cpp:8: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    8 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 151 ms 27040 KB Output is correct
3 Correct 150 ms 26932 KB Output is correct
4 Correct 158 ms 26852 KB Output is correct
5 Correct 151 ms 26932 KB Output is correct
6 Correct 147 ms 26828 KB Output is correct
7 Correct 155 ms 26936 KB Output is correct
8 Correct 145 ms 26928 KB Output is correct
9 Correct 148 ms 27084 KB Output is correct
10 Correct 151 ms 26944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 21324 KB Output is correct
2 Correct 76 ms 21304 KB Output is correct
3 Correct 69 ms 21412 KB Output is correct
4 Correct 79 ms 21412 KB Output is correct
5 Correct 78 ms 21436 KB Output is correct
6 Correct 74 ms 21324 KB Output is correct
7 Correct 81 ms 21424 KB Output is correct
8 Correct 74 ms 21424 KB Output is correct
9 Correct 72 ms 21356 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 21324 KB Output is correct
2 Correct 76 ms 21304 KB Output is correct
3 Correct 69 ms 21412 KB Output is correct
4 Correct 79 ms 21412 KB Output is correct
5 Correct 78 ms 21436 KB Output is correct
6 Correct 74 ms 21324 KB Output is correct
7 Correct 81 ms 21424 KB Output is correct
8 Correct 74 ms 21424 KB Output is correct
9 Correct 72 ms 21356 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 160 ms 21352 KB Output is correct
12 Correct 167 ms 21380 KB Output is correct
13 Correct 157 ms 21380 KB Output is correct
14 Correct 157 ms 21396 KB Output is correct
15 Correct 167 ms 21524 KB Output is correct
16 Correct 175 ms 21424 KB Output is correct
17 Correct 160 ms 21380 KB Output is correct
18 Correct 90 ms 21324 KB Output is correct
19 Correct 93 ms 21352 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 0 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 0 ms 328 KB Output is correct
11 Correct 7 ms 1108 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 7 ms 1108 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 6 ms 1120 KB Output is correct
16 Correct 7 ms 1124 KB Output is correct
17 Correct 7 ms 1128 KB Output is correct
18 Correct 7 ms 1104 KB Output is correct
19 Correct 5 ms 980 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 21324 KB Output is correct
2 Correct 76 ms 21304 KB Output is correct
3 Correct 69 ms 21412 KB Output is correct
4 Correct 79 ms 21412 KB Output is correct
5 Correct 78 ms 21436 KB Output is correct
6 Correct 74 ms 21324 KB Output is correct
7 Correct 81 ms 21424 KB Output is correct
8 Correct 74 ms 21424 KB Output is correct
9 Correct 72 ms 21356 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 160 ms 21352 KB Output is correct
12 Correct 167 ms 21380 KB Output is correct
13 Correct 157 ms 21380 KB Output is correct
14 Correct 157 ms 21396 KB Output is correct
15 Correct 167 ms 21524 KB Output is correct
16 Correct 175 ms 21424 KB Output is correct
17 Correct 160 ms 21380 KB Output is correct
18 Correct 90 ms 21324 KB Output is correct
19 Correct 93 ms 21352 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 210 ms 21324 KB Output is correct
22 Correct 210 ms 21428 KB Output is correct
23 Correct 212 ms 21452 KB Output is correct
24 Correct 207 ms 21412 KB Output is correct
25 Correct 214 ms 21516 KB Output is correct
26 Correct 216 ms 21404 KB Output is correct
27 Correct 212 ms 21532 KB Output is correct
28 Correct 116 ms 21416 KB Output is correct
29 Correct 115 ms 21308 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 151 ms 27040 KB Output is correct
3 Correct 150 ms 26932 KB Output is correct
4 Correct 158 ms 26852 KB Output is correct
5 Correct 151 ms 26932 KB Output is correct
6 Correct 147 ms 26828 KB Output is correct
7 Correct 155 ms 26936 KB Output is correct
8 Correct 145 ms 26928 KB Output is correct
9 Correct 148 ms 27084 KB Output is correct
10 Correct 151 ms 26944 KB Output is correct
11 Correct 72 ms 21324 KB Output is correct
12 Correct 76 ms 21304 KB Output is correct
13 Correct 69 ms 21412 KB Output is correct
14 Correct 79 ms 21412 KB Output is correct
15 Correct 78 ms 21436 KB Output is correct
16 Correct 74 ms 21324 KB Output is correct
17 Correct 81 ms 21424 KB Output is correct
18 Correct 74 ms 21424 KB Output is correct
19 Correct 72 ms 21356 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 160 ms 21352 KB Output is correct
22 Correct 167 ms 21380 KB Output is correct
23 Correct 157 ms 21380 KB Output is correct
24 Correct 157 ms 21396 KB Output is correct
25 Correct 167 ms 21524 KB Output is correct
26 Correct 175 ms 21424 KB Output is correct
27 Correct 160 ms 21380 KB Output is correct
28 Correct 90 ms 21324 KB Output is correct
29 Correct 93 ms 21352 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 328 KB Output is correct
40 Correct 0 ms 328 KB Output is correct
41 Correct 7 ms 1108 KB Output is correct
42 Correct 7 ms 1108 KB Output is correct
43 Correct 7 ms 1108 KB Output is correct
44 Correct 7 ms 1108 KB Output is correct
45 Correct 6 ms 1120 KB Output is correct
46 Correct 7 ms 1124 KB Output is correct
47 Correct 7 ms 1128 KB Output is correct
48 Correct 7 ms 1104 KB Output is correct
49 Correct 5 ms 980 KB Output is correct
50 Correct 1 ms 328 KB Output is correct
51 Correct 210 ms 21324 KB Output is correct
52 Correct 210 ms 21428 KB Output is correct
53 Correct 212 ms 21452 KB Output is correct
54 Correct 207 ms 21412 KB Output is correct
55 Correct 214 ms 21516 KB Output is correct
56 Correct 216 ms 21404 KB Output is correct
57 Correct 212 ms 21532 KB Output is correct
58 Correct 116 ms 21416 KB Output is correct
59 Correct 115 ms 21308 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 236 ms 27004 KB Output is correct
62 Correct 238 ms 26896 KB Output is correct
63 Correct 240 ms 26928 KB Output is correct
64 Correct 246 ms 26952 KB Output is correct
65 Correct 235 ms 26972 KB Output is correct
66 Correct 287 ms 26932 KB Output is correct
67 Correct 242 ms 27032 KB Output is correct
68 Correct 238 ms 26892 KB Output is correct
69 Correct 209 ms 23244 KB Output is correct
70 Correct 0 ms 212 KB Output is correct