Submission #230992

# Submission time Handle Problem Language Result Execution time Memory
230992 2020-05-12T09:29:08 Z keta_tsimakuridze Mountains (NOI20_mountains) C++14
100 / 100
1047 ms 34296 KB
#include<bits/stdc++.h>
using namespace std;
long long n,a[300005],b[300005],tree_bef[600005],tree_aft[600005],i,k,ans;
map<long long,int>ind;
void update(int idx,int val,int w){
	for(int x=idx;x<=n;x+=x&(-x)){
		if(w==1){
		tree_aft[x]+=val; } 
		else tree_bef[x]+=val;
	}
}

long long getans(int idx,int w){
	long long pas=0;
	for(int x=idx;x>=1;x-=x&(-x)){
	  if(w==1)	pas+=tree_aft[x];
	  else pas+=tree_bef[x];
	}
	return pas;
}

int main(){
	cin>>n;
	for(k=1;k<=n;k++){
		cin>>a[k];
		b[k]=a[k];
	}
	sort(b+1,b+n+1);
	for(k=1;k<=n;k++){
		if(!ind[b[k]]){
			i++;
			ind[b[k]]=i; 
		}
		
		update(ind[b[k]],1,1);
	} 
	for(k=1;k<=n;k++){
		update(ind[a[k]],-1,1);
		update(ind[a[k]],1,2);
		ans+=getans(ind[a[k]]-1,1)*getans(ind[a[k]]-1,2);
		//cout<<ans<<endl;
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 641 ms 34296 KB Output is correct
3 Correct 641 ms 34296 KB Output is correct
4 Correct 636 ms 34044 KB Output is correct
5 Correct 632 ms 34168 KB Output is correct
6 Correct 639 ms 34168 KB Output is correct
7 Correct 639 ms 34040 KB Output is correct
8 Correct 639 ms 34040 KB Output is correct
9 Correct 581 ms 22776 KB Output is correct
10 Correct 578 ms 22904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 5752 KB Output is correct
2 Correct 116 ms 5624 KB Output is correct
3 Correct 115 ms 5752 KB Output is correct
4 Correct 119 ms 5836 KB Output is correct
5 Correct 119 ms 5752 KB Output is correct
6 Correct 113 ms 5624 KB Output is correct
7 Correct 115 ms 5752 KB Output is correct
8 Correct 107 ms 5752 KB Output is correct
9 Correct 111 ms 5624 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 5752 KB Output is correct
2 Correct 116 ms 5624 KB Output is correct
3 Correct 115 ms 5752 KB Output is correct
4 Correct 119 ms 5836 KB Output is correct
5 Correct 119 ms 5752 KB Output is correct
6 Correct 113 ms 5624 KB Output is correct
7 Correct 115 ms 5752 KB Output is correct
8 Correct 107 ms 5752 KB Output is correct
9 Correct 111 ms 5624 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 161 ms 6008 KB Output is correct
12 Correct 161 ms 6008 KB Output is correct
13 Correct 163 ms 5956 KB Output is correct
14 Correct 161 ms 6008 KB Output is correct
15 Correct 156 ms 6008 KB Output is correct
16 Correct 162 ms 6008 KB Output is correct
17 Correct 163 ms 6008 KB Output is correct
18 Correct 131 ms 6008 KB Output is correct
19 Correct 132 ms 6008 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 416 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 416 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 24 ms 1536 KB Output is correct
12 Correct 25 ms 1536 KB Output is correct
13 Correct 25 ms 1408 KB Output is correct
14 Correct 25 ms 1536 KB Output is correct
15 Correct 25 ms 1408 KB Output is correct
16 Correct 25 ms 1408 KB Output is correct
17 Correct 25 ms 1408 KB Output is correct
18 Correct 22 ms 1024 KB Output is correct
19 Correct 11 ms 640 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 5752 KB Output is correct
2 Correct 116 ms 5624 KB Output is correct
3 Correct 115 ms 5752 KB Output is correct
4 Correct 119 ms 5836 KB Output is correct
5 Correct 119 ms 5752 KB Output is correct
6 Correct 113 ms 5624 KB Output is correct
7 Correct 115 ms 5752 KB Output is correct
8 Correct 107 ms 5752 KB Output is correct
9 Correct 111 ms 5624 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 161 ms 6008 KB Output is correct
12 Correct 161 ms 6008 KB Output is correct
13 Correct 163 ms 5956 KB Output is correct
14 Correct 161 ms 6008 KB Output is correct
15 Correct 156 ms 6008 KB Output is correct
16 Correct 162 ms 6008 KB Output is correct
17 Correct 163 ms 6008 KB Output is correct
18 Correct 131 ms 6008 KB Output is correct
19 Correct 132 ms 6008 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 569 ms 14200 KB Output is correct
22 Correct 593 ms 14328 KB Output is correct
23 Correct 620 ms 14276 KB Output is correct
24 Correct 594 ms 14328 KB Output is correct
25 Correct 567 ms 14284 KB Output is correct
26 Correct 579 ms 14456 KB Output is correct
27 Correct 587 ms 14328 KB Output is correct
28 Correct 351 ms 14200 KB Output is correct
29 Correct 357 ms 14328 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 641 ms 34296 KB Output is correct
3 Correct 641 ms 34296 KB Output is correct
4 Correct 636 ms 34044 KB Output is correct
5 Correct 632 ms 34168 KB Output is correct
6 Correct 639 ms 34168 KB Output is correct
7 Correct 639 ms 34040 KB Output is correct
8 Correct 639 ms 34040 KB Output is correct
9 Correct 581 ms 22776 KB Output is correct
10 Correct 578 ms 22904 KB Output is correct
11 Correct 113 ms 5752 KB Output is correct
12 Correct 116 ms 5624 KB Output is correct
13 Correct 115 ms 5752 KB Output is correct
14 Correct 119 ms 5836 KB Output is correct
15 Correct 119 ms 5752 KB Output is correct
16 Correct 113 ms 5624 KB Output is correct
17 Correct 115 ms 5752 KB Output is correct
18 Correct 107 ms 5752 KB Output is correct
19 Correct 111 ms 5624 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 161 ms 6008 KB Output is correct
22 Correct 161 ms 6008 KB Output is correct
23 Correct 163 ms 5956 KB Output is correct
24 Correct 161 ms 6008 KB Output is correct
25 Correct 156 ms 6008 KB Output is correct
26 Correct 162 ms 6008 KB Output is correct
27 Correct 163 ms 6008 KB Output is correct
28 Correct 131 ms 6008 KB Output is correct
29 Correct 132 ms 6008 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 416 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 24 ms 1536 KB Output is correct
42 Correct 25 ms 1536 KB Output is correct
43 Correct 25 ms 1408 KB Output is correct
44 Correct 25 ms 1536 KB Output is correct
45 Correct 25 ms 1408 KB Output is correct
46 Correct 25 ms 1408 KB Output is correct
47 Correct 25 ms 1408 KB Output is correct
48 Correct 22 ms 1024 KB Output is correct
49 Correct 11 ms 640 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 569 ms 14200 KB Output is correct
52 Correct 593 ms 14328 KB Output is correct
53 Correct 620 ms 14276 KB Output is correct
54 Correct 594 ms 14328 KB Output is correct
55 Correct 567 ms 14284 KB Output is correct
56 Correct 579 ms 14456 KB Output is correct
57 Correct 587 ms 14328 KB Output is correct
58 Correct 351 ms 14200 KB Output is correct
59 Correct 357 ms 14328 KB Output is correct
60 Correct 4 ms 384 KB Output is correct
61 Correct 1018 ms 34172 KB Output is correct
62 Correct 1004 ms 34108 KB Output is correct
63 Correct 1026 ms 34168 KB Output is correct
64 Correct 1047 ms 34168 KB Output is correct
65 Correct 1012 ms 34168 KB Output is correct
66 Correct 1012 ms 34168 KB Output is correct
67 Correct 1043 ms 34168 KB Output is correct
68 Correct 889 ms 23008 KB Output is correct
69 Correct 645 ms 17016 KB Output is correct
70 Correct 5 ms 384 KB Output is correct