Submission #250710

# Submission time Handle Problem Language Result Execution time Memory
250710 2020-07-18T20:10:08 Z Blagojce Mountains (NOI20_mountains) C++11
100 / 100
149 ms 19944 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>

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

const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5e5;
 
const ll A = 911382323;
const ll B = 972663749;
 
ll modpow(ll x, ll n){
	if(n == 0) return 1%mod;
	ll u = modpow(x, n/2);
	u = (u * u) % mod;
	if(n % 2) u = (u * x) % mod;
	return u;
}
ll inverse(ll x){
	return modpow(x, mod-2);
}
ll add(ll ans, ll val){
	ans = (ans + val) % mod;
	return ans;
}
ll mul(ll ans, ll val){
	ans = (ans * val) % mod;
	return ans;
}
ll sub(ll ans, ll val){
	ans = (ans - val) % mod;
	if(ans < 0) ans += mod;
	return ans;
}
ll _div(ll ans, ll val){
	ans = (ans * inverse(val)) % mod;
	return ans;
}
ll fakt[mxn];
ll bc(ll n, ll k){
	return (fakt[n]*inverse((fakt[k]*fakt[n-k])%mod))%mod;
}
ll sq(ll x){
	return x*x;
}
ll rsum(ll a, ll b){
	return (b-a+1)*(a+b)/2;
}
void prec(){
	fakt[0] = 1;
	fr(i, 1, mxn){
		fakt[i] = mul(fakt[i-1], i);
	}
}

int bit[mxn];
void update(int k, int val){
	while(k < mxn){
		bit[k] += val;
		k += k&-k;
	}
}

int sum(int k){
	int s = 0;
	while(k > 0){
		s += bit[k];
		k -= k&-k;
	}
	return s;
}
void solve(){
	memset(bit, 0, sizeof(bit));
	
	
	int n;
	cin >> n;
	ll a[n];
	vector<pair<ll, int> > v;
	fr(i, 0, n){
		cin >> a[i];
		v.pb({a[i], i});
	}
	
	
	sort(all(v));
	int val = 0;
	ll pr = -1;
	for(auto u : v){
		if(u.st != pr) pr = u.st, ++val;
		a[u.nd] = val;
	}
	ll le[n];
	ll ri[n];
	
	memset(le, 0, sizeof(le));
	memset(ri, 0, sizeof(ri));
	
	fr(i, 0, n){
		le[i] = sum(a[i]-1);
		update(a[i], +1);
	}
	
	fr(i, 0, n) update(a[i],-1);
	
	for(int i = n-1; i >= 0; i --){
		ri[i] = sum(a[i]-1);
		update(a[i], +1);
	}
	ll ans = 0;
	fr(i, 0, n){
		ans += le[i]*ri[i];
	}
	cout<<ans<<endl;
	
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2304 KB Output is correct
2 Correct 107 ms 14164 KB Output is correct
3 Correct 107 ms 14176 KB Output is correct
4 Correct 108 ms 14288 KB Output is correct
5 Correct 104 ms 14136 KB Output is correct
6 Correct 105 ms 14240 KB Output is correct
7 Correct 106 ms 14172 KB Output is correct
8 Correct 105 ms 14292 KB Output is correct
9 Correct 105 ms 14172 KB Output is correct
10 Correct 109 ms 14172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 14168 KB Output is correct
2 Correct 100 ms 14296 KB Output is correct
3 Correct 100 ms 14168 KB Output is correct
4 Correct 92 ms 14172 KB Output is correct
5 Correct 103 ms 14172 KB Output is correct
6 Correct 94 ms 14164 KB Output is correct
7 Correct 90 ms 14164 KB Output is correct
8 Correct 91 ms 14172 KB Output is correct
9 Correct 82 ms 14168 KB Output is correct
10 Correct 1 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 14168 KB Output is correct
2 Correct 100 ms 14296 KB Output is correct
3 Correct 100 ms 14168 KB Output is correct
4 Correct 92 ms 14172 KB Output is correct
5 Correct 103 ms 14172 KB Output is correct
6 Correct 94 ms 14164 KB Output is correct
7 Correct 90 ms 14164 KB Output is correct
8 Correct 91 ms 14172 KB Output is correct
9 Correct 82 ms 14168 KB Output is correct
10 Correct 1 ms 2304 KB Output is correct
11 Correct 105 ms 14164 KB Output is correct
12 Correct 104 ms 14164 KB Output is correct
13 Correct 103 ms 14292 KB Output is correct
14 Correct 102 ms 14168 KB Output is correct
15 Correct 106 ms 14164 KB Output is correct
16 Correct 99 ms 14164 KB Output is correct
17 Correct 101 ms 14164 KB Output is correct
18 Correct 70 ms 14172 KB Output is correct
19 Correct 73 ms 14292 KB Output is correct
20 Correct 1 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2304 KB Output is correct
2 Correct 2 ms 2304 KB Output is correct
3 Correct 1 ms 2304 KB Output is correct
4 Correct 2 ms 2304 KB Output is correct
5 Correct 1 ms 2304 KB Output is correct
6 Correct 2 ms 2304 KB Output is correct
7 Correct 2 ms 2304 KB Output is correct
8 Correct 2 ms 2304 KB Output is correct
9 Correct 2 ms 2360 KB Output is correct
10 Correct 1 ms 2364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2304 KB Output is correct
2 Correct 2 ms 2304 KB Output is correct
3 Correct 1 ms 2304 KB Output is correct
4 Correct 2 ms 2304 KB Output is correct
5 Correct 1 ms 2304 KB Output is correct
6 Correct 2 ms 2304 KB Output is correct
7 Correct 2 ms 2304 KB Output is correct
8 Correct 2 ms 2304 KB Output is correct
9 Correct 2 ms 2360 KB Output is correct
10 Correct 1 ms 2364 KB Output is correct
11 Correct 6 ms 3100 KB Output is correct
12 Correct 6 ms 3072 KB Output is correct
13 Correct 6 ms 3072 KB Output is correct
14 Correct 6 ms 3072 KB Output is correct
15 Correct 6 ms 3072 KB Output is correct
16 Correct 6 ms 3072 KB Output is correct
17 Correct 6 ms 3072 KB Output is correct
18 Correct 7 ms 3200 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Correct 1 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 14168 KB Output is correct
2 Correct 100 ms 14296 KB Output is correct
3 Correct 100 ms 14168 KB Output is correct
4 Correct 92 ms 14172 KB Output is correct
5 Correct 103 ms 14172 KB Output is correct
6 Correct 94 ms 14164 KB Output is correct
7 Correct 90 ms 14164 KB Output is correct
8 Correct 91 ms 14172 KB Output is correct
9 Correct 82 ms 14168 KB Output is correct
10 Correct 1 ms 2304 KB Output is correct
11 Correct 105 ms 14164 KB Output is correct
12 Correct 104 ms 14164 KB Output is correct
13 Correct 103 ms 14292 KB Output is correct
14 Correct 102 ms 14168 KB Output is correct
15 Correct 106 ms 14164 KB Output is correct
16 Correct 99 ms 14164 KB Output is correct
17 Correct 101 ms 14164 KB Output is correct
18 Correct 70 ms 14172 KB Output is correct
19 Correct 73 ms 14292 KB Output is correct
20 Correct 1 ms 2304 KB Output is correct
21 Correct 108 ms 14296 KB Output is correct
22 Correct 107 ms 14164 KB Output is correct
23 Correct 104 ms 14164 KB Output is correct
24 Correct 110 ms 14156 KB Output is correct
25 Correct 108 ms 14164 KB Output is correct
26 Correct 105 ms 14232 KB Output is correct
27 Correct 115 ms 14240 KB Output is correct
28 Correct 75 ms 14172 KB Output is correct
29 Correct 76 ms 14176 KB Output is correct
30 Correct 2 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2304 KB Output is correct
2 Correct 107 ms 14164 KB Output is correct
3 Correct 107 ms 14176 KB Output is correct
4 Correct 108 ms 14288 KB Output is correct
5 Correct 104 ms 14136 KB Output is correct
6 Correct 105 ms 14240 KB Output is correct
7 Correct 106 ms 14172 KB Output is correct
8 Correct 105 ms 14292 KB Output is correct
9 Correct 105 ms 14172 KB Output is correct
10 Correct 109 ms 14172 KB Output is correct
11 Correct 91 ms 14168 KB Output is correct
12 Correct 100 ms 14296 KB Output is correct
13 Correct 100 ms 14168 KB Output is correct
14 Correct 92 ms 14172 KB Output is correct
15 Correct 103 ms 14172 KB Output is correct
16 Correct 94 ms 14164 KB Output is correct
17 Correct 90 ms 14164 KB Output is correct
18 Correct 91 ms 14172 KB Output is correct
19 Correct 82 ms 14168 KB Output is correct
20 Correct 1 ms 2304 KB Output is correct
21 Correct 105 ms 14164 KB Output is correct
22 Correct 104 ms 14164 KB Output is correct
23 Correct 103 ms 14292 KB Output is correct
24 Correct 102 ms 14168 KB Output is correct
25 Correct 106 ms 14164 KB Output is correct
26 Correct 99 ms 14164 KB Output is correct
27 Correct 101 ms 14164 KB Output is correct
28 Correct 70 ms 14172 KB Output is correct
29 Correct 73 ms 14292 KB Output is correct
30 Correct 1 ms 2304 KB Output is correct
31 Correct 1 ms 2304 KB Output is correct
32 Correct 2 ms 2304 KB Output is correct
33 Correct 1 ms 2304 KB Output is correct
34 Correct 2 ms 2304 KB Output is correct
35 Correct 1 ms 2304 KB Output is correct
36 Correct 2 ms 2304 KB Output is correct
37 Correct 2 ms 2304 KB Output is correct
38 Correct 2 ms 2304 KB Output is correct
39 Correct 2 ms 2360 KB Output is correct
40 Correct 1 ms 2364 KB Output is correct
41 Correct 6 ms 3100 KB Output is correct
42 Correct 6 ms 3072 KB Output is correct
43 Correct 6 ms 3072 KB Output is correct
44 Correct 6 ms 3072 KB Output is correct
45 Correct 6 ms 3072 KB Output is correct
46 Correct 6 ms 3072 KB Output is correct
47 Correct 6 ms 3072 KB Output is correct
48 Correct 7 ms 3200 KB Output is correct
49 Correct 5 ms 2816 KB Output is correct
50 Correct 1 ms 2304 KB Output is correct
51 Correct 108 ms 14296 KB Output is correct
52 Correct 107 ms 14164 KB Output is correct
53 Correct 104 ms 14164 KB Output is correct
54 Correct 110 ms 14156 KB Output is correct
55 Correct 108 ms 14164 KB Output is correct
56 Correct 105 ms 14232 KB Output is correct
57 Correct 115 ms 14240 KB Output is correct
58 Correct 75 ms 14172 KB Output is correct
59 Correct 76 ms 14176 KB Output is correct
60 Correct 2 ms 2304 KB Output is correct
61 Correct 137 ms 19796 KB Output is correct
62 Correct 135 ms 19668 KB Output is correct
63 Correct 136 ms 19704 KB Output is correct
64 Correct 140 ms 19668 KB Output is correct
65 Correct 143 ms 19796 KB Output is correct
66 Correct 149 ms 19704 KB Output is correct
67 Correct 148 ms 19944 KB Output is correct
68 Correct 140 ms 19924 KB Output is correct
69 Correct 117 ms 16084 KB Output is correct
70 Correct 1 ms 2304 KB Output is correct