#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int n, ans = 1, v[1000002];
bool iz[1000002];
set<int> s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> v[i];
s.insert(v[1]);
int i = 2;
while(i <= n && v[i] >= v[i-1])
s.insert(v[i]), ++i;
for(; i <= n; )
{
++ans;
set<int> ::iterator it = s.lower_bound(v[i]);
set<int> ::iterator it2 = it;
if(it == s.end())
{
int j = i+1;
if(!iz[v[i]])
iz[v[i]] = 1, s.insert(v[i]);
while(j <= n && v[j] >= v[j-1])
{
if(!iz[v[j]])
iz[v[j]] = 1, s.insert(v[j]);
++j;
}
i = j;
}
else
{
int val = *it;
if(it == s.begin() && v[i] < val)
{
int j = i+1;
if(!iz[v[i]])
iz[v[i]] = 1, s.insert(v[i]);
while(j <= n && v[j] >= v[j-1] && v[j] <= val)
{
if(!iz[v[j]])
iz[v[j]] = 1, s.insert(v[j]);
++j;
}
i = j;
}
else
{
if(val == v[i])
{
++it2;
if(it2 == s.end())
{
int j = i+1;
if(!iz[v[i]])
iz[v[i]] = 1, s.insert(v[i]);
while(j <= n && v[j] >= v[j-1])
{
if(!iz[v[j]])
iz[v[j]] = 1, s.insert(v[j]);
++j;
}
i = j;
}
else
{
int j = i+1;
int val2 = *it2;
if(!iz[v[i]])
iz[v[i]] = 1, s.insert(v[i]);
while(j <= n && v[j] >= v[j-1] && v[j] <= val2)
{
if(!iz[v[j]])
iz[v[j]] = 1, s.insert(v[j]);
++j;
}
i = j;
}
}
else
{
int j = i+1;
if(!iz[v[i]])
iz[v[i]] = 1, s.insert(v[i]);
while(j <= n && v[j] >= v[j-1] && v[j] <= val)
{
if(!iz[v[j]])
iz[v[j]] = 1, s.insert(v[j]);
++j;
}
i = j;
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
424 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
424 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
6 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
888 KB |
Output is correct |
38 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
424 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
6 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
888 KB |
Output is correct |
38 |
Correct |
3 ms |
760 KB |
Output is correct |
39 |
Correct |
65 ms |
3036 KB |
Output is correct |
40 |
Correct |
113 ms |
4204 KB |
Output is correct |
41 |
Correct |
53 ms |
2680 KB |
Output is correct |
42 |
Correct |
52 ms |
2552 KB |
Output is correct |
43 |
Correct |
38 ms |
2168 KB |
Output is correct |
44 |
Correct |
137 ms |
5008 KB |
Output is correct |
45 |
Correct |
135 ms |
4984 KB |
Output is correct |
46 |
Correct |
136 ms |
5172 KB |
Output is correct |
47 |
Correct |
120 ms |
4996 KB |
Output is correct |
48 |
Correct |
126 ms |
4964 KB |
Output is correct |
49 |
Correct |
756 ms |
24440 KB |
Output is correct |
50 |
Correct |
718 ms |
24520 KB |
Output is correct |
51 |
Correct |
643 ms |
24696 KB |
Output is correct |
52 |
Correct |
611 ms |
24568 KB |
Output is correct |
53 |
Correct |
585 ms |
24528 KB |
Output is correct |
54 |
Correct |
582 ms |
24624 KB |
Output is correct |
55 |
Correct |
1342 ms |
52916 KB |
Output is correct |
56 |
Correct |
1345 ms |
59128 KB |
Output is correct |
57 |
Correct |
1423 ms |
58912 KB |
Output is correct |
58 |
Correct |
1312 ms |
58976 KB |
Output is correct |
59 |
Correct |
1349 ms |
58932 KB |
Output is correct |
60 |
Correct |
1341 ms |
58972 KB |
Output is correct |
61 |
Execution timed out |
1577 ms |
59060 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |