Submission #480056

# Submission time Handle Problem Language Result Execution time Memory
480056 2021-10-14T13:43:22 Z NachoLibre Po (COCI21_po) C++17
20 / 70
53 ms 6332 KB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) ((int)x.size())
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<pair<int, int>> b(n + 1);
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		b[i].first = a[i];
		b[i].second = i;
	}
	sort(b.begin() + 1, b.end());
	set<int> s;
	s.insert(n + 1);
	int ans = 0;
	for(int i = 1; i <= n; ) {
		int j = i;
		for(int ii = i; ii <= n; ++ii) {
			if(b[ii].first != b[i].first) break;
			j = ii;
		}
		++ans;
		for(int k = i + 1; k <= j; ++k) {
			int x = *s.upper_bound(b[k - 1].second);
			int y = *s.upper_bound(b[k].second);
			ans += (x != y);
		}
		for(int k = i; k <= j; ++k) {
			s.insert(b[k].second);
		}
		i = j + 1;
	}
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 216 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 25 ms 3268 KB Output isn't correct
5 Incorrect 36 ms 4792 KB Output isn't correct
6 Correct 53 ms 6248 KB Output is correct
7 Incorrect 36 ms 6332 KB Output isn't correct