이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Murad Eynizade */
#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 1000001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);
#define MOD 1000000007
using namespace std;
int n , a[SIZE] , co = 1 , tree[4 * SIZE];
void update(int v,int l,int r,int in) {
if (l == r) {
tree[v] = 1;
return;
}
int m = (l + r) >> 1;
if (in <= m)update(v << 1,l,m,in);
else update(v << 1 | 1,m + 1,r,in);
tree[v] = tree[v << 1] + tree[v << 1 | 1];
}
int getans(int v,int l,int r,int le,int ri) {
if (l > ri || r < le)return 0;
if (l >= le && r <= ri)return tree[v];
int m = (l + r) >> 1;
return getans(v << 1,l,m,le,ri) + getans(v << 1 | 1,m + 1,r,le,ri);
}
int main()
{
FAST_READ;
cin>>n;
for (int i = 1;i<=n;i++)cin>>a[i];
int f = 1;
for (int i = 2;i<=n;i++) {
if (a[i] < a[i - 1]) {
//cout<<i<<endl;
int in = i - 1;
while (in >= f) {
update(1,1,SIZE - 1,a[in]);
in--;
}
f = i;
co++;
}
else if (getans(1,1,SIZE - 1,a[f],a[i]) - getans(1,1,SIZE - 1,a[f],a[f]) - getans(1,1,SIZE - 1,a[i],a[i]) > 0) {
//cout<<i<<" --- "<<endl;
int in = i - 1;
while (in >= f) {
update(1,1,SIZE - 1,a[in]);
in--;
}
f = i;
co++;
}
}
cout<<co<<endl;
return 0;
}
# | 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... |