Submission #329920

# Submission time Handle Problem Language Result Execution time Memory
329920 2020-11-23T06:33:20 Z M_W Mountains (NOI20_mountains) C++14
66 / 100
362 ms 32736 KB
#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
long long a[300300], b[300300];
int fwt[300300];

void add(int v){
	for(;v <= 300300; v += (v & -v))
		fwt[v]++;
}

int query(int v){
	int ret = 0;
	for(;v > 0; v -= (v & -v)){
		ret += fwt[v];
	}	
	return ret;
}

int main(){
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%lld", &a[i]);
		b[i] = a[i];
	}	
	
	sort(a, a + N);
	int k = 1;
	for(int i = 0; i < N; i++){
		if(mp[a[i]] == 0) mp[a[i]] = k++;
	}
	vector<int> l;
	for(int i = 0; i < N; i++){
		l.push_back(query(mp[b[i]] - 1));
		add(mp[b[i]]);
	}
	memset(fwt, 0, sizeof fwt);
	long long ans = 0;
	for(int i = N - 1; i >= 0; i--){
		ans += (query(mp[b[i]] - 1) * l[i]) * 1ll;
		add(mp[b[i]]);
	}
	printf("%lld", ans);
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |   scanf("%lld", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 346 ms 32736 KB Output is correct
3 Correct 352 ms 32608 KB Output is correct
4 Correct 350 ms 32608 KB Output is correct
5 Correct 348 ms 32608 KB Output is correct
6 Correct 362 ms 32608 KB Output is correct
7 Correct 362 ms 32608 KB Output is correct
8 Correct 352 ms 32608 KB Output is correct
9 Correct 304 ms 23012 KB Output is correct
10 Correct 287 ms 23140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 8048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 8048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 2 ms 1516 KB Output is correct
5 Correct 2 ms 1516 KB Output is correct
6 Correct 2 ms 1516 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1516 KB Output is correct
9 Correct 1 ms 1516 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 2 ms 1516 KB Output is correct
5 Correct 2 ms 1516 KB Output is correct
6 Correct 2 ms 1516 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1516 KB Output is correct
9 Correct 1 ms 1516 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
11 Correct 14 ms 2680 KB Output is correct
12 Correct 13 ms 2540 KB Output is correct
13 Correct 13 ms 2540 KB Output is correct
14 Correct 14 ms 2540 KB Output is correct
15 Correct 14 ms 2684 KB Output is correct
16 Correct 13 ms 2668 KB Output is correct
17 Correct 14 ms 2540 KB Output is correct
18 Correct 11 ms 2284 KB Output is correct
19 Correct 6 ms 1900 KB Output is correct
20 Correct 1 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 8048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 346 ms 32736 KB Output is correct
3 Correct 352 ms 32608 KB Output is correct
4 Correct 350 ms 32608 KB Output is correct
5 Correct 348 ms 32608 KB Output is correct
6 Correct 362 ms 32608 KB Output is correct
7 Correct 362 ms 32608 KB Output is correct
8 Correct 352 ms 32608 KB Output is correct
9 Correct 304 ms 23012 KB Output is correct
10 Correct 287 ms 23140 KB Output is correct
11 Incorrect 71 ms 8048 KB Output isn't correct
12 Halted 0 ms 0 KB -