Submission #210727

# Submission time Handle Problem Language Result Execution time Memory
210727 2020-03-18T07:11:49 Z grt Mountains (NOI20_mountains) C++17
100 / 100
613 ms 26748 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 300*1000+10;
int n,nr;
ll h[nax];
map<ll,int>sc;
int T[(1<<20)],R;
int l[nax];

void update(int a,int x) {
	a+=R;
	T[a]+=x;
	while(a>1) {
		a/=2;
		T[a] = T[2*a]+T[2*a+1];
	}
}


int query(int a,int b) {
	a+=R; b+=R;
	if(a>b) return 0;
	int w = T[a]+(a!=b?T[b]:0);
	while(a/2!=b/2) {
		if(a%2==0) w+=T[a+1];
		if(b%2==1) w+=T[b-1];
		a/=2;
		b/=2;
	}
	return w;
}

ll ans;

int main() {_
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>h[i];
		sc[h[i]];
	}
	for(auto &it:sc) it.ND = nr++;
	R=1;
	while(R<nr) R*=2;
	for(int i=1; i<=n; i++) h[i] = sc[h[i]];
	for(int i=1; i<=n; i++) {
		l[i] = query(0,h[i]-1);
		update(h[i],1);
	}
	for(int i=1; i<2*R; i++) T[i] = 0;
	for(int i=n; i>=1; i--) {
		int x = query(0,h[i]-1);
		update(h[i],1);
		ans += (ll)l[i]*x;
	}
	cout<<ans;
	
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 269 ms 26720 KB Output is correct
3 Correct 272 ms 26744 KB Output is correct
4 Correct 260 ms 26744 KB Output is correct
5 Correct 262 ms 26744 KB Output is correct
6 Correct 267 ms 26744 KB Output is correct
7 Correct 271 ms 26740 KB Output is correct
8 Correct 263 ms 26744 KB Output is correct
9 Correct 227 ms 15612 KB Output is correct
10 Correct 230 ms 15608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3832 KB Output is correct
2 Correct 33 ms 3832 KB Output is correct
3 Correct 32 ms 3832 KB Output is correct
4 Correct 33 ms 3832 KB Output is correct
5 Correct 35 ms 3832 KB Output is correct
6 Correct 35 ms 3832 KB Output is correct
7 Correct 33 ms 3832 KB Output is correct
8 Correct 26 ms 3832 KB Output is correct
9 Correct 27 ms 3832 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3832 KB Output is correct
2 Correct 33 ms 3832 KB Output is correct
3 Correct 32 ms 3832 KB Output is correct
4 Correct 33 ms 3832 KB Output is correct
5 Correct 35 ms 3832 KB Output is correct
6 Correct 35 ms 3832 KB Output is correct
7 Correct 33 ms 3832 KB Output is correct
8 Correct 26 ms 3832 KB Output is correct
9 Correct 27 ms 3832 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 79 ms 3832 KB Output is correct
12 Correct 82 ms 3884 KB Output is correct
13 Correct 83 ms 3832 KB Output is correct
14 Correct 83 ms 3864 KB Output is correct
15 Correct 81 ms 3904 KB Output is correct
16 Correct 87 ms 3876 KB Output is correct
17 Correct 84 ms 3832 KB Output is correct
18 Correct 45 ms 3832 KB Output is correct
19 Correct 47 ms 3836 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 15 ms 1272 KB Output is correct
12 Correct 15 ms 1272 KB Output is correct
13 Correct 13 ms 1272 KB Output is correct
14 Correct 13 ms 1272 KB Output is correct
15 Correct 13 ms 1272 KB Output is correct
16 Correct 13 ms 1272 KB Output is correct
17 Correct 13 ms 1272 KB Output is correct
18 Correct 12 ms 764 KB Output is correct
19 Correct 9 ms 504 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3832 KB Output is correct
2 Correct 33 ms 3832 KB Output is correct
3 Correct 32 ms 3832 KB Output is correct
4 Correct 33 ms 3832 KB Output is correct
5 Correct 35 ms 3832 KB Output is correct
6 Correct 35 ms 3832 KB Output is correct
7 Correct 33 ms 3832 KB Output is correct
8 Correct 26 ms 3832 KB Output is correct
9 Correct 27 ms 3832 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 79 ms 3832 KB Output is correct
12 Correct 82 ms 3884 KB Output is correct
13 Correct 83 ms 3832 KB Output is correct
14 Correct 83 ms 3864 KB Output is correct
15 Correct 81 ms 3904 KB Output is correct
16 Correct 87 ms 3876 KB Output is correct
17 Correct 84 ms 3832 KB Output is correct
18 Correct 45 ms 3832 KB Output is correct
19 Correct 47 ms 3836 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 337 ms 10872 KB Output is correct
22 Correct 339 ms 10872 KB Output is correct
23 Correct 335 ms 10872 KB Output is correct
24 Correct 357 ms 10872 KB Output is correct
25 Correct 326 ms 10872 KB Output is correct
26 Correct 334 ms 10872 KB Output is correct
27 Correct 338 ms 10872 KB Output is correct
28 Correct 171 ms 10872 KB Output is correct
29 Correct 172 ms 10872 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 269 ms 26720 KB Output is correct
3 Correct 272 ms 26744 KB Output is correct
4 Correct 260 ms 26744 KB Output is correct
5 Correct 262 ms 26744 KB Output is correct
6 Correct 267 ms 26744 KB Output is correct
7 Correct 271 ms 26740 KB Output is correct
8 Correct 263 ms 26744 KB Output is correct
9 Correct 227 ms 15612 KB Output is correct
10 Correct 230 ms 15608 KB Output is correct
11 Correct 34 ms 3832 KB Output is correct
12 Correct 33 ms 3832 KB Output is correct
13 Correct 32 ms 3832 KB Output is correct
14 Correct 33 ms 3832 KB Output is correct
15 Correct 35 ms 3832 KB Output is correct
16 Correct 35 ms 3832 KB Output is correct
17 Correct 33 ms 3832 KB Output is correct
18 Correct 26 ms 3832 KB Output is correct
19 Correct 27 ms 3832 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 79 ms 3832 KB Output is correct
22 Correct 82 ms 3884 KB Output is correct
23 Correct 83 ms 3832 KB Output is correct
24 Correct 83 ms 3864 KB Output is correct
25 Correct 81 ms 3904 KB Output is correct
26 Correct 87 ms 3876 KB Output is correct
27 Correct 84 ms 3832 KB Output is correct
28 Correct 45 ms 3832 KB Output is correct
29 Correct 47 ms 3836 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 15 ms 1272 KB Output is correct
42 Correct 15 ms 1272 KB Output is correct
43 Correct 13 ms 1272 KB Output is correct
44 Correct 13 ms 1272 KB Output is correct
45 Correct 13 ms 1272 KB Output is correct
46 Correct 13 ms 1272 KB Output is correct
47 Correct 13 ms 1272 KB Output is correct
48 Correct 12 ms 764 KB Output is correct
49 Correct 9 ms 504 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 337 ms 10872 KB Output is correct
52 Correct 339 ms 10872 KB Output is correct
53 Correct 335 ms 10872 KB Output is correct
54 Correct 357 ms 10872 KB Output is correct
55 Correct 326 ms 10872 KB Output is correct
56 Correct 334 ms 10872 KB Output is correct
57 Correct 338 ms 10872 KB Output is correct
58 Correct 171 ms 10872 KB Output is correct
59 Correct 172 ms 10872 KB Output is correct
60 Correct 4 ms 376 KB Output is correct
61 Correct 598 ms 26744 KB Output is correct
62 Correct 598 ms 26744 KB Output is correct
63 Correct 597 ms 26744 KB Output is correct
64 Correct 599 ms 26744 KB Output is correct
65 Correct 613 ms 26744 KB Output is correct
66 Correct 601 ms 26744 KB Output is correct
67 Correct 603 ms 26748 KB Output is correct
68 Correct 450 ms 15612 KB Output is correct
69 Correct 389 ms 13048 KB Output is correct
70 Correct 5 ms 376 KB Output is correct