#include<bits/stdc++.h>
#define int long long
using namespace std;
int pot=1;
int drzewo[3000000];
int lazy[3000000];
int t[3000000];
void propaguj(int x,int l,int r)
{
drzewo[x*2]+=lazy[x]*(r-l+1)/2;
drzewo[x*2+1]+=lazy[x]*(r-l+1)/2;
lazy[x*2]+=lazy[x];
lazy[x*2+1]+=lazy[x];
lazy[x]=0;
}
int suma(int x,int l,int r,int a,int b)
{
if(r<a || l>b)
return 0;
propaguj(x,l,r);
if(a<=l && r<=b)
return drzewo[x];
int mid=(l+r)/2;
int L=suma(x*2,l,mid,a,b);
int R=suma(x*2+1,mid+1,r,a,b);
drzewo[x]=drzewo[x*2]+drzewo[x*2+1];
return L+R;
}
void dodaj(int x,int l,int r,int a,int b)
{
if(r<a || l>b)
return;
propaguj(x,l,r);
if(a<=l && r<=b)
{
drzewo[x]+=(r-l+1);
lazy[x]++;
return;
}
int mid=(l+r)/2;
dodaj(x*2,l,mid,a,b);
dodaj(x*2+1,mid+1,r,a,b);
drzewo[x]=drzewo[x*2]+drzewo[x*2+1];
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
while(pot<=n)
pot*=2;
pot--;
for(int i=1;i<=n;i++)
cin>>t[i];
int wynik=0;
for(int i=1;i<=n;i++)
{
int j=i;
while(j+1<=n && t[j+1]>t[j] && suma(1,pot+1,pot*2+1,t[i]+pot+1,pot+t[j+1]-1)==0)
j++;
for(int e=i;e<=j;e++)
dodaj(1,pot+1,pot*2+1,t[e]+pot,t[e]+pot);
i=j;
wynik++;
}
cout<<wynik;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |