/*input
8
8 7 6 5 4 3 2 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
int raise(int a,int n,int m = MOD){
if(n == 0)return 1;
if(n == 1)return a;
int x = 1;
x *= raise(a,n/2,m);
x %= m;
x *= x;
x %= m;
if(n%2)x*= a;
x %= m;
return x;
}
int floor1(int n,int k){
if(n%k == 0 || n >= 0)return n/k;
return (n/k)-1;
}
int ceil1(int n,int k){
return floor1(n+k-1,k);
}
const int N = 1e6+1;
int n;
int a[N];
int seg[4*N];
int mark[N];
bool done[N];
#define mid (l+r)/2
void add(int node,int l,int r,int ind){
if(ind < l or ind > r)return;
if(l == r and r == ind){
seg[node]++;
return;
}
add(2*node,l,mid,ind);add(2*node+1,mid+1,r,ind);
seg[node]++;
}
int query(int node,int l,int r,int start,int end){
if(l > end or r < start)return 0;
if(l >= start and r <= end)return seg[node];
return query(2*node,l,mid,start,end)+query(2*node+1,mid+1,r,start,end);
}
#undef mid
bool check(int i,int j){
if(abs(a[i]-a[j]) < 2)return 1;
if(query(1,1,N-1,a[i]+1,a[j]-1))return 0;
return 1;
}
void solve(){
cin >> n;
// mark[n+1] = INF;
REP(i,4*N)seg[i] = 0;
RE(i,n){
cin >> a[i];
done[i] = 0;
if(i == 1)mark[i] = 1;
else{
mark[i] = mark[i-1]+(a[i] < a[i-1]);
}
// cout << mark[i] << " ";
}
//cout << endl;
int ans = 0;
int j = 2;
int donetill = 0;
RE(i,n){
if(donetill >= i){
add(1,1,N-1,a[i]);
continue;
}
while(check(i,j)){
if(j == n+1)break;
if(mark[i] != mark[j])break;
j++;
}
donetill = j-1;
//cout << i << ": " << j << endl;
ans++;
add(1,1,N-1,a[i]);
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".in","r",stdin);freopen(".out","w",stdout);
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31652 KB |
Output is correct |
3 |
Correct |
26 ms |
31744 KB |
Output is correct |
4 |
Correct |
27 ms |
31656 KB |
Output is correct |
5 |
Correct |
28 ms |
31608 KB |
Output is correct |
6 |
Correct |
29 ms |
31660 KB |
Output is correct |
7 |
Correct |
31 ms |
31716 KB |
Output is correct |
8 |
Correct |
29 ms |
31664 KB |
Output is correct |
9 |
Correct |
30 ms |
31612 KB |
Output is correct |
10 |
Correct |
26 ms |
31608 KB |
Output is correct |
11 |
Correct |
29 ms |
31608 KB |
Output is correct |
12 |
Correct |
29 ms |
31608 KB |
Output is correct |
13 |
Correct |
27 ms |
31616 KB |
Output is correct |
14 |
Correct |
32 ms |
31616 KB |
Output is correct |
15 |
Correct |
29 ms |
31716 KB |
Output is correct |
16 |
Correct |
28 ms |
31656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31652 KB |
Output is correct |
3 |
Correct |
26 ms |
31744 KB |
Output is correct |
4 |
Correct |
27 ms |
31656 KB |
Output is correct |
5 |
Correct |
28 ms |
31608 KB |
Output is correct |
6 |
Correct |
29 ms |
31660 KB |
Output is correct |
7 |
Correct |
31 ms |
31716 KB |
Output is correct |
8 |
Correct |
29 ms |
31664 KB |
Output is correct |
9 |
Correct |
30 ms |
31612 KB |
Output is correct |
10 |
Correct |
26 ms |
31608 KB |
Output is correct |
11 |
Correct |
29 ms |
31608 KB |
Output is correct |
12 |
Correct |
29 ms |
31608 KB |
Output is correct |
13 |
Correct |
27 ms |
31616 KB |
Output is correct |
14 |
Correct |
32 ms |
31616 KB |
Output is correct |
15 |
Correct |
29 ms |
31716 KB |
Output is correct |
16 |
Correct |
28 ms |
31656 KB |
Output is correct |
17 |
Correct |
30 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31708 KB |
Output is correct |
19 |
Correct |
33 ms |
31700 KB |
Output is correct |
20 |
Correct |
27 ms |
31736 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
27 ms |
31744 KB |
Output is correct |
23 |
Correct |
28 ms |
31612 KB |
Output is correct |
24 |
Correct |
34 ms |
31616 KB |
Output is correct |
25 |
Correct |
27 ms |
31616 KB |
Output is correct |
26 |
Correct |
28 ms |
31616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31652 KB |
Output is correct |
3 |
Correct |
26 ms |
31744 KB |
Output is correct |
4 |
Correct |
27 ms |
31656 KB |
Output is correct |
5 |
Correct |
28 ms |
31608 KB |
Output is correct |
6 |
Correct |
29 ms |
31660 KB |
Output is correct |
7 |
Correct |
31 ms |
31716 KB |
Output is correct |
8 |
Correct |
29 ms |
31664 KB |
Output is correct |
9 |
Correct |
30 ms |
31612 KB |
Output is correct |
10 |
Correct |
26 ms |
31608 KB |
Output is correct |
11 |
Correct |
29 ms |
31608 KB |
Output is correct |
12 |
Correct |
29 ms |
31608 KB |
Output is correct |
13 |
Correct |
27 ms |
31616 KB |
Output is correct |
14 |
Correct |
32 ms |
31616 KB |
Output is correct |
15 |
Correct |
29 ms |
31716 KB |
Output is correct |
16 |
Correct |
28 ms |
31656 KB |
Output is correct |
17 |
Correct |
30 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31708 KB |
Output is correct |
19 |
Correct |
33 ms |
31700 KB |
Output is correct |
20 |
Correct |
27 ms |
31736 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
27 ms |
31744 KB |
Output is correct |
23 |
Correct |
28 ms |
31612 KB |
Output is correct |
24 |
Correct |
34 ms |
31616 KB |
Output is correct |
25 |
Correct |
27 ms |
31616 KB |
Output is correct |
26 |
Correct |
28 ms |
31616 KB |
Output is correct |
27 |
Correct |
28 ms |
31616 KB |
Output is correct |
28 |
Correct |
27 ms |
31736 KB |
Output is correct |
29 |
Correct |
33 ms |
31736 KB |
Output is correct |
30 |
Correct |
31 ms |
31688 KB |
Output is correct |
31 |
Correct |
30 ms |
31640 KB |
Output is correct |
32 |
Correct |
28 ms |
31608 KB |
Output is correct |
33 |
Correct |
28 ms |
31616 KB |
Output is correct |
34 |
Correct |
30 ms |
31608 KB |
Output is correct |
35 |
Correct |
37 ms |
31608 KB |
Output is correct |
36 |
Correct |
29 ms |
31608 KB |
Output is correct |
37 |
Correct |
28 ms |
31744 KB |
Output is correct |
38 |
Correct |
28 ms |
31692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31652 KB |
Output is correct |
3 |
Correct |
26 ms |
31744 KB |
Output is correct |
4 |
Correct |
27 ms |
31656 KB |
Output is correct |
5 |
Correct |
28 ms |
31608 KB |
Output is correct |
6 |
Correct |
29 ms |
31660 KB |
Output is correct |
7 |
Correct |
31 ms |
31716 KB |
Output is correct |
8 |
Correct |
29 ms |
31664 KB |
Output is correct |
9 |
Correct |
30 ms |
31612 KB |
Output is correct |
10 |
Correct |
26 ms |
31608 KB |
Output is correct |
11 |
Correct |
29 ms |
31608 KB |
Output is correct |
12 |
Correct |
29 ms |
31608 KB |
Output is correct |
13 |
Correct |
27 ms |
31616 KB |
Output is correct |
14 |
Correct |
32 ms |
31616 KB |
Output is correct |
15 |
Correct |
29 ms |
31716 KB |
Output is correct |
16 |
Correct |
28 ms |
31656 KB |
Output is correct |
17 |
Correct |
30 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31708 KB |
Output is correct |
19 |
Correct |
33 ms |
31700 KB |
Output is correct |
20 |
Correct |
27 ms |
31736 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
27 ms |
31744 KB |
Output is correct |
23 |
Correct |
28 ms |
31612 KB |
Output is correct |
24 |
Correct |
34 ms |
31616 KB |
Output is correct |
25 |
Correct |
27 ms |
31616 KB |
Output is correct |
26 |
Correct |
28 ms |
31616 KB |
Output is correct |
27 |
Correct |
28 ms |
31616 KB |
Output is correct |
28 |
Correct |
27 ms |
31736 KB |
Output is correct |
29 |
Correct |
33 ms |
31736 KB |
Output is correct |
30 |
Correct |
31 ms |
31688 KB |
Output is correct |
31 |
Correct |
30 ms |
31640 KB |
Output is correct |
32 |
Correct |
28 ms |
31608 KB |
Output is correct |
33 |
Correct |
28 ms |
31616 KB |
Output is correct |
34 |
Correct |
30 ms |
31608 KB |
Output is correct |
35 |
Correct |
37 ms |
31608 KB |
Output is correct |
36 |
Correct |
29 ms |
31608 KB |
Output is correct |
37 |
Correct |
28 ms |
31744 KB |
Output is correct |
38 |
Correct |
28 ms |
31692 KB |
Output is correct |
39 |
Correct |
177 ms |
42872 KB |
Output is correct |
40 |
Correct |
286 ms |
50148 KB |
Output is correct |
41 |
Correct |
158 ms |
40844 KB |
Output is correct |
42 |
Correct |
142 ms |
39752 KB |
Output is correct |
43 |
Correct |
116 ms |
37400 KB |
Output is correct |
44 |
Correct |
339 ms |
55160 KB |
Output is correct |
45 |
Correct |
415 ms |
55040 KB |
Output is correct |
46 |
Correct |
374 ms |
55160 KB |
Output is correct |
47 |
Correct |
451 ms |
55152 KB |
Output is correct |
48 |
Correct |
390 ms |
55196 KB |
Output is correct |
49 |
Correct |
598 ms |
55104 KB |
Output is correct |
50 |
Correct |
632 ms |
55100 KB |
Output is correct |
51 |
Correct |
626 ms |
55036 KB |
Output is correct |
52 |
Correct |
589 ms |
55104 KB |
Output is correct |
53 |
Correct |
629 ms |
55236 KB |
Output is correct |
54 |
Correct |
630 ms |
54980 KB |
Output is correct |
55 |
Correct |
852 ms |
55044 KB |
Output is correct |
56 |
Correct |
792 ms |
55052 KB |
Output is correct |
57 |
Correct |
823 ms |
54960 KB |
Output is correct |
58 |
Correct |
833 ms |
55056 KB |
Output is correct |
59 |
Correct |
880 ms |
55060 KB |
Output is correct |
60 |
Correct |
848 ms |
55060 KB |
Output is correct |
61 |
Correct |
838 ms |
55064 KB |
Output is correct |
62 |
Correct |
837 ms |
55052 KB |
Output is correct |