# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
479276 | keta_tsimakuridze | Po (COCI21_po) | C++14 | 125 ms | 21556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t,n,a[N];
map<int,int> id;
set<int> s;
vector<int> x, v[N];
main(){
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
x.push_back(a[i]);
}
sort(x.begin(),x.end());
int ans = 0, idx = 0;
for(int i = 0; i < n; i++) {
if(!i || x[i] != x[i - 1]) idx++;
id[x[i]] = idx;
}
for(int i = 1; i <= n; i++) v[id[a[i]]].push_back(i);
for(int i = 1; i <= idx; i++) {
for(int j = 1; j < v[i].size(); j++) {
int prev = v[i][j - 1], cur = v[i][j];
if(s.upper_bound(prev) != s.end()) {
if(*s.upper_bound(prev) < cur) ans++;
}
}
ans++;
for(int j = 0; j < v[i].size(); j++) s.insert(v[i][j]);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |