import java.io.*; import java.util.*;
public class money{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
public static class Pair implements Comparable<Pair>{
int vtx; int val;
public Pair(int a, int b){
this.vtx=a; this.val=b;
}
public int compareTo(Pair other){
if(this.val<other.val)return -1;
if(this.val>other.val)return 1;
if(this.vtx<other.vtx)return -1;
return 1;
}
}
static int MOD=998244353;
static int[] tree; static int MAXN=1000001;
public static void main(String[] args){
FastReader br=new FastReader();
int N=br.nextInt(); int[] a=new int[N];
for(int i=0;i<N;i++){
a[i]=br.nextInt();
}
tree=new int[MAXN];
int ans=0; int ii;
for(int i=0; i<N; i++){
ii=i+1; ans++;
while(ii<N && a[ii]>=a[ii-1] && sum(a[ii])==sum(a[ii-1])){
ii++;
}
for(int j=i;j<ii; j++){
upd(a[j]);
}
//The segment [i,ii-1] can be used
i=ii-1;
}
System.out.println(ans);
}
//tree[i]=sum(i-2^{\nu_2(i)}+1,i)
public static int sum(int i){//This is a consequence of unique expression in base 2
int ans=0;
while(i>0){
ans+=tree[i];
i-=(i&-i);
}
return ans;
}
public static void upd(int i){//Increment arr[i] by k
while(i<MAXN){
tree[i]++;
i+=(i&-i);// Note (k&-k) is the largest power of 2 dividing k
//These intervals all contain i
}
}
}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
12776 KB |
Output is correct |
2 |
Correct |
72 ms |
12524 KB |
Output is correct |
3 |
Correct |
73 ms |
12396 KB |
Output is correct |
4 |
Incorrect |
74 ms |
12652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
12776 KB |
Output is correct |
2 |
Correct |
72 ms |
12524 KB |
Output is correct |
3 |
Correct |
73 ms |
12396 KB |
Output is correct |
4 |
Incorrect |
74 ms |
12652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
12776 KB |
Output is correct |
2 |
Correct |
72 ms |
12524 KB |
Output is correct |
3 |
Correct |
73 ms |
12396 KB |
Output is correct |
4 |
Incorrect |
74 ms |
12652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
12776 KB |
Output is correct |
2 |
Correct |
72 ms |
12524 KB |
Output is correct |
3 |
Correct |
73 ms |
12396 KB |
Output is correct |
4 |
Incorrect |
74 ms |
12652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |