Submission #329141

# Submission time Handle Problem Language Result Execution time Memory
329141 2020-11-19T13:01:00 Z M_W Mountains (NOI20_mountains) C++14
0 / 100
2000 ms 7204 KB
#include <bits/stdc++.h>
using namespace std;
int h[300300];
vector<int> v;

int main(){
	int N;
	vector<long long> cnt;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &h[i]);
		if(i == 0){
			v.push_back(h[i]);
			cnt.push_back(0);
			continue;
		}
		auto it = upper_bound(v.begin(), v.end(), h[i]);
		v.insert(it, h[i]);
		cnt.push_back(lower_bound(v.begin(), v.end(), h[i]) - v.begin());
	}
	v.clear();
	long long sum = 0;
	for(int i = N - 1; i >= 0; i--){
		if(i == 0){
			v.push_back(h[i]);
			cnt.push_back(0);
			continue;
		}
		auto it = upper_bound(v.begin(), v.end(), h[i]);
		v.insert(it, h[i]);
		sum += cnt[i] * 1ll * (lower_bound(v.begin(), v.end(), h[i]) - v.begin()) * 1ll;
	}
	printf("%lld", sum);
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |   scanf("%d", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 2095 ms 6728 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 7204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 7204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 7204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 2095 ms 6728 KB Time limit exceeded
3 Halted 0 ms 0 KB -