# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169160 | tselmegkh | Money (IZhO17_money) | C++14 | 1581 ms | 3276 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
inline vector<int> mergesort(vector<int> a, vector<int> b){
int i = 0, j = 0;
vector<int> res;
while(i < a.size() && j < b.size()){
if(a[i] < b[j]){
res.push_back(a[i]);
i++;
}else{
res.push_back(b[j]);
j++;
}
}
while(i < a.size()){
res.push_back(a[i]);
i++;
}
while(j < b.size()){
res.push_back(b[j]);
j++;
}
return res;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
int ans = 1;
for(int i = 0; i < n; i++){
cin >> a[i];
}
int j = 1;
vector<int> b;
b.push_back(a[0]);
while(a[j] >= a[j - 1] && j < n){
b.push_back(a[j]);
j++;
}
int cnt = 0, bound = 0;
vector<int> cursegment;
while(j < n){
int l = 0, r = b.size() - 1;
if(cnt == 0){
ans++;
while(l != r){
int mid = (l + r + 1) / 2;
if(b[mid] <= a[j]){
l = mid;
}else{
r = mid - 1;
}
}
if(b[l] > a[j]){
l = -1;
}
int sz = b.size() - 1;
if(l < sz){
bound = b[l + 1];
}else{
bound = 1e9;
}
cnt++;
cursegment.push_back(a[j]);
j++;
}else{
if(a[j] < a[j - 1]){
cnt = 0;
b = mergesort(b, cursegment);
cursegment.clear();
continue;
}else{
if(a[j] <= bound){
cursegment.push_back(a[j]);
cnt++;
j++;
}else{
cnt = 0;
b = mergesort(b, cursegment);
cursegment.clear();
}
}
}
}
cout << ans << '\n';
}
Compilation message (stderr)
# | 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... |