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 <iostream>
#include <set>
#include <vector>
using namespace std;
int N;
int B[1000006];
vector<int> A;
set<int> S;
int ans;
bool flag;
int readInt()
{
int res = 0;
char ch = 0;
while(ch < '0') ch = getchar_unlocked();
for(; ch >= '0'; ch = getchar_unlocked()) res = res * 10 + ch - '0';
return res;
}
void writeInt(int v)
{
char buf[14];
int p = 0;
if(v == 0) buf[p++] = 0;
for(; v; v /= 10) buf[p++] = v % 10;
while(p--) putchar_unlocked(buf[p] + '0');
}
int main(){
N=readInt();
for(int i=0;i<N;i++)
B[i]=readInt();
A.push_back(B[0]);
for(int i=1;i<N;i++)
if(B[i]!=B[i-1])
A.push_back(B[i]);
N=A.size();
S.insert(1e9);
for(int i=0;i<N-1;i++){
if((A[i]>A[i+1]) or (A[i]<A[i+1] and *S.lower_bound(A[i]-flag+1)<A[i+1])){
flag=false;
ans++;
}
else
flag=true;
S.insert(A[i]);
}
writeInt(ans+1);
}
# | 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... |