이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAX_N = 1e6 + 5;
const int MAX_A = 1e6 + 5;
struct IndexTree {
private:
int data[MAX_A];
public:
void Add(int ind, int val);
int Get(int ind);
int GetInInterval(int low, int high);
};
void IndexTree::Add(int ind, int val) {
while(ind < MAX_A) {
data[ind] += val;
ind += (ind & (-ind));
}
}
int IndexTree::Get(int ind) {
int ans = 0;
while(ind > 0) {
ans += data[ind];
ind -= (ind & (-ind));
}
return ans;
}
int IndexTree::GetInInterval(int low, int high) {
return Get(high) - Get(low - 1);
}
int a[MAX_N];
IndexTree indexTree;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for(int i = 0; i < n; ) {
int j;
for(j = i + 1; j < n; j++) {
if(a[j] < a[j - 1] || indexTree.GetInInterval(a[i] + 1, a[j] - 1) > 0) {
break;
}
}
ans++;
for(int p = i; p < j; p++) {
indexTree.Add(a[p], 1);
}
i = j;
}
cout << ans << 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... |