Submission #761993

# Submission time Handle Problem Language Result Execution time Memory
761993 2023-06-20T13:54:27 Z KN200711 Mountains (NOI20_mountains) C++14
22 / 100
290 ms 24620 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

const int MXN = 3e5;
int fen[300001];
map<int, int> M;

void upd(int a) {
	while(a <= MXN) {
		fen[a]++;
		a += a&(-a);
	}
	return;
}

int qry(int a) {
	int res = 0;
	while(a > 0) {
		res += fen[a];
		a -= a&(-a);
	}
	return res;
}

int main() {
	int N;
	scanf("%d", &N);
	
	vector<int> arr(N);
	for(int i=0;i<N;i++) {
		scanf("%d", &arr[i]);
		M[arr[i]] = 1;
	}
	int cnt = 1;
	for(auto p : M) {
		M[p.fi] = cnt;
		cnt++;
	}
	for(int i=0;i<N;i++) {
		arr[i] = M[arr[i]];
	//	cout<<arr[i]<<endl;
	}
	
	vector<int> pref(N);
	for(int i=0;i<N;i++) {
		pref[i] = qry(arr[i] - 1);
		upd(arr[i]);
	}
	
	ll ans = 0ll;
	
	for(int i=0;i<=MXN;i++) fen[i] = 0;
	vector<int> suff(N);
	for(int i=N-1;i>=0;i--) {
		suff[i] = qry(arr[i] - 1);
		upd(arr[i]);
		
	//	cout<<pref[i]<<" "<<suff[i]<<endl;
		
		ans += (1ll * pref[i]) * (1ll * suff[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d", &arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1364 KB Output is correct
2 Incorrect 290 ms 24620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5576 KB Output is correct
2 Correct 43 ms 5524 KB Output is correct
3 Correct 43 ms 5532 KB Output is correct
4 Correct 43 ms 5556 KB Output is correct
5 Correct 44 ms 5528 KB Output is correct
6 Correct 43 ms 5572 KB Output is correct
7 Correct 43 ms 5572 KB Output is correct
8 Correct 41 ms 5560 KB Output is correct
9 Correct 41 ms 5580 KB Output is correct
10 Correct 1 ms 1464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5576 KB Output is correct
2 Correct 43 ms 5524 KB Output is correct
3 Correct 43 ms 5532 KB Output is correct
4 Correct 43 ms 5556 KB Output is correct
5 Correct 44 ms 5528 KB Output is correct
6 Correct 43 ms 5572 KB Output is correct
7 Correct 43 ms 5572 KB Output is correct
8 Correct 41 ms 5560 KB Output is correct
9 Correct 41 ms 5580 KB Output is correct
10 Correct 1 ms 1464 KB Output is correct
11 Correct 55 ms 5820 KB Output is correct
12 Correct 56 ms 5836 KB Output is correct
13 Correct 58 ms 5824 KB Output is correct
14 Correct 55 ms 5828 KB Output is correct
15 Correct 54 ms 5848 KB Output is correct
16 Correct 55 ms 5844 KB Output is correct
17 Correct 56 ms 5800 KB Output is correct
18 Correct 38 ms 5724 KB Output is correct
19 Correct 38 ms 5844 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5576 KB Output is correct
2 Correct 43 ms 5524 KB Output is correct
3 Correct 43 ms 5532 KB Output is correct
4 Correct 43 ms 5556 KB Output is correct
5 Correct 44 ms 5528 KB Output is correct
6 Correct 43 ms 5572 KB Output is correct
7 Correct 43 ms 5572 KB Output is correct
8 Correct 41 ms 5560 KB Output is correct
9 Correct 41 ms 5580 KB Output is correct
10 Correct 1 ms 1464 KB Output is correct
11 Correct 55 ms 5820 KB Output is correct
12 Correct 56 ms 5836 KB Output is correct
13 Correct 58 ms 5824 KB Output is correct
14 Correct 55 ms 5828 KB Output is correct
15 Correct 54 ms 5848 KB Output is correct
16 Correct 55 ms 5844 KB Output is correct
17 Correct 56 ms 5800 KB Output is correct
18 Correct 38 ms 5724 KB Output is correct
19 Correct 38 ms 5844 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 169 ms 11124 KB Output is correct
22 Correct 155 ms 11116 KB Output is correct
23 Correct 156 ms 11060 KB Output is correct
24 Correct 155 ms 11112 KB Output is correct
25 Correct 157 ms 11068 KB Output is correct
26 Correct 155 ms 11128 KB Output is correct
27 Correct 155 ms 11160 KB Output is correct
28 Correct 90 ms 11084 KB Output is correct
29 Correct 93 ms 11060 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1364 KB Output is correct
2 Incorrect 290 ms 24620 KB Output isn't correct
3 Halted 0 ms 0 KB -