# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361814 | Lawliet | Money (IZhO17_money) | C++17 | 1334 ms | 51408 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>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;
const int MAXN = 1000010;
const int INF = 1000000010;
int n;
int v[MAXN];
set<int> s;
void add(int L, int R)
{
while( L <= R )
s.insert( v[L++] );
}
void solveTestCase()
{
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
scanf("%d",&v[i]);
int Lord = 1;
int ans = 1, opt = 1;
int Lvalue = v[1], Rvalue = INF;
for(int i = 2 ; i <= n ; i++)
{
if( v[i - 1] > v[i] )
{
add( Lord , i - 1 );
Lord = i;
}
if( Lord == 1 ) continue;
if( Lord != i && v[i] <= Rvalue ) continue;
// opt = i;
// add( opt , i - 1 );
ans++;
auto it = s.upper_bound( v[i] );
if( it == s.end() ) Rvalue = INF;
else Rvalue = *it;
if( it == s.begin() ) Lvalue = -INF;
else it--, Lvalue = *it;
}
printf("%d\n",ans);
}
int main()
{
int t = 1;
// scanf("%d",&t);
while( t-- )
solveTestCase();
}
Compilation message (stderr)
# | 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... |