Submission #632495

# Submission time Handle Problem Language Result Execution time Memory
632495 2022-08-20T07:49:48 Z shmad Mountains (NOI20_mountains) C++17
24 / 100
362 ms 46496 KB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" 	
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

//#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvt = vt< vt<int> >;

const int N = 1e6 + 5, mod = 1e9 + 7, B = 500;
const ll inf = 1e18 + 7, LIM = (1ll << 60);
const double eps = 1e-6;

int n;
map<int, int> m;
set<int> st;
int h[N];
ll t[4 * N];

void upd (int pos, int v = 1, int tl = 1, int tr = 	N) {
	if (tl == tr) {                                
		t[v]++;         
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd(pos, v << 1, tl, tm);
	else upd(pos, v << 1 | 1, tm + 1, tr);
	t[v] = t[v << 1] + t[v << 1 | 1];
}

ll get (int l, int r, int v = 1, int tl = 1, int tr = N) {
	if (tl > r || tr < l) return 0ll;
	if (tl >= l && tr <= r) return t[v];
	int tm = tl + tr >> 1;
	ll a = get(l, r, v << 1, tl, tm);
	ll b = get(l, r, v << 1 | 1, tm + 1, tr);
	return (a + b);
}

ll l[N], r[N];

void solve () {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> h[i], st.insert(h[i]);
	for (int i: st) m[i] = sz(m) + 1;
	for (int i = 1; i <= n; i++) h[i] = m[h[i]];
	for (int i = 1; i <= n; i++) l[i] = get(1, h[i] - 1), upd(h[i]);
	fill(t, t + 4 * N, 0);
	for (int i = n; i >= 1; i--) r[i] = get(1, h[i] - 1), upd(h[i]);
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += (l[i] * 1ll * r[i]);
	cout << ans;
	cout << '\n';
}

bool testcases = 0;

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	int test = 1;
	if (testcases) cin >> test;
	for (int cs = 1; cs <= test; cs++) {
		solve();
	}
}

Compilation message

Mountains.cpp: In function 'void upd(int, int, int, int)':
Mountains.cpp:36:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
Mountains.cpp: In function 'll get(int, int, int, int, int)':
Mountains.cpp:45:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31572 KB Output is correct
2 Correct 50 ms 37432 KB Output is correct
3 Correct 48 ms 37412 KB Output is correct
4 Correct 49 ms 37404 KB Output is correct
5 Correct 49 ms 37412 KB Output is correct
6 Correct 51 ms 37452 KB Output is correct
7 Correct 52 ms 37452 KB Output is correct
8 Correct 49 ms 37516 KB Output is correct
9 Correct 51 ms 37448 KB Output is correct
10 Correct 53 ms 37472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 37472 KB Output is correct
2 Correct 101 ms 37488 KB Output is correct
3 Correct 90 ms 37404 KB Output is correct
4 Correct 96 ms 37440 KB Output is correct
5 Correct 90 ms 37508 KB Output is correct
6 Correct 87 ms 37428 KB Output is correct
7 Correct 104 ms 37516 KB Output is correct
8 Correct 82 ms 37452 KB Output is correct
9 Correct 82 ms 37612 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 37472 KB Output is correct
2 Correct 101 ms 37488 KB Output is correct
3 Correct 90 ms 37404 KB Output is correct
4 Correct 96 ms 37440 KB Output is correct
5 Correct 90 ms 37508 KB Output is correct
6 Correct 87 ms 37428 KB Output is correct
7 Correct 104 ms 37516 KB Output is correct
8 Correct 82 ms 37452 KB Output is correct
9 Correct 82 ms 37612 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
11 Correct 148 ms 37432 KB Output is correct
12 Correct 147 ms 37496 KB Output is correct
13 Correct 157 ms 37444 KB Output is correct
14 Correct 157 ms 37420 KB Output is correct
15 Correct 152 ms 37484 KB Output is correct
16 Correct 149 ms 37436 KB Output is correct
17 Correct 149 ms 37436 KB Output is correct
18 Correct 105 ms 37472 KB Output is correct
19 Correct 101 ms 37448 KB Output is correct
20 Correct 13 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 31576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 31576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 37472 KB Output is correct
2 Correct 101 ms 37488 KB Output is correct
3 Correct 90 ms 37404 KB Output is correct
4 Correct 96 ms 37440 KB Output is correct
5 Correct 90 ms 37508 KB Output is correct
6 Correct 87 ms 37428 KB Output is correct
7 Correct 104 ms 37516 KB Output is correct
8 Correct 82 ms 37452 KB Output is correct
9 Correct 82 ms 37612 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
11 Correct 148 ms 37432 KB Output is correct
12 Correct 147 ms 37496 KB Output is correct
13 Correct 157 ms 37444 KB Output is correct
14 Correct 157 ms 37420 KB Output is correct
15 Correct 152 ms 37484 KB Output is correct
16 Correct 149 ms 37436 KB Output is correct
17 Correct 149 ms 37436 KB Output is correct
18 Correct 105 ms 37472 KB Output is correct
19 Correct 101 ms 37448 KB Output is correct
20 Correct 13 ms 31572 KB Output is correct
21 Correct 362 ms 46356 KB Output is correct
22 Correct 346 ms 46324 KB Output is correct
23 Correct 348 ms 46376 KB Output is correct
24 Correct 346 ms 46412 KB Output is correct
25 Correct 345 ms 46496 KB Output is correct
26 Correct 349 ms 46412 KB Output is correct
27 Correct 359 ms 46448 KB Output is correct
28 Correct 184 ms 46324 KB Output is correct
29 Correct 185 ms 46416 KB Output is correct
30 Correct 12 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31572 KB Output is correct
2 Correct 50 ms 37432 KB Output is correct
3 Correct 48 ms 37412 KB Output is correct
4 Correct 49 ms 37404 KB Output is correct
5 Correct 49 ms 37412 KB Output is correct
6 Correct 51 ms 37452 KB Output is correct
7 Correct 52 ms 37452 KB Output is correct
8 Correct 49 ms 37516 KB Output is correct
9 Correct 51 ms 37448 KB Output is correct
10 Correct 53 ms 37472 KB Output is correct
11 Correct 91 ms 37472 KB Output is correct
12 Correct 101 ms 37488 KB Output is correct
13 Correct 90 ms 37404 KB Output is correct
14 Correct 96 ms 37440 KB Output is correct
15 Correct 90 ms 37508 KB Output is correct
16 Correct 87 ms 37428 KB Output is correct
17 Correct 104 ms 37516 KB Output is correct
18 Correct 82 ms 37452 KB Output is correct
19 Correct 82 ms 37612 KB Output is correct
20 Correct 12 ms 31572 KB Output is correct
21 Correct 148 ms 37432 KB Output is correct
22 Correct 147 ms 37496 KB Output is correct
23 Correct 157 ms 37444 KB Output is correct
24 Correct 157 ms 37420 KB Output is correct
25 Correct 152 ms 37484 KB Output is correct
26 Correct 149 ms 37436 KB Output is correct
27 Correct 149 ms 37436 KB Output is correct
28 Correct 105 ms 37472 KB Output is correct
29 Correct 101 ms 37448 KB Output is correct
30 Correct 13 ms 31572 KB Output is correct
31 Incorrect 12 ms 31576 KB Output isn't correct
32 Halted 0 ms 0 KB -