This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// banii banii banii
/// 2 locuri in masina ca milionarii
#include <iostream>
#include <set>
using namespace std;
const int maxN = 1000005;
int n, v[maxN], ans = 1;
set <int> values;
int solve(int poz)
{
auto it = values.upper_bound(v[poz]);
int aux, maxval;
if(it == values.end())
maxval = maxN;
else
maxval = (*it);
bool ok = 1;
for(aux = poz + 1; aux <= n; aux++)
if(v[aux] < v[aux - 1] || v[aux] > maxval)
{ok = 0; break;}
for(int i = poz; i < aux; i++)
values.insert(v[i]);
return aux + ok;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> v[i];
int poz = n + 1;
for(int i = 2; i <= n && (poz == n + 1); i++)
if(v[i] < v[i - 1])
poz = i;
for(int i = 1; i < poz; i++)
values.insert(v[i]);
while(poz <= n)
{
poz = solve(poz);
ans++;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |