# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
467130 | aryan12 | Money (IZhO17_money) | C++17 | 1581 ms | 4852 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;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 5;
int bit[N];
//3 5 4 6
//4 5 6 3
//3 4 5 4
void Update(int pos, int val) {
for(int i = pos; i < N; i += (i & (-i))) {
bit[i] += val;
}
}
int Query(int pos) {
int ans = 0;
for(int i = pos; i > 0; i -= (i & (-i))) {
ans += bit[i];
}
return ans;
}
void Solve() {
int n;
cin >> n;
int a[n + 1];
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> temp;
int cur_min = a[1], cur_max = a[1];
int prev = 1;
int ans = 1;
for(int i = 2; i <= n; i++) {
if(a[i] < a[i - 1]) {
ans++;
for(int j = 0; j < temp.size(); j++) {
if(temp[j] > cur_min && temp[j] < cur_max) {
ans++;
break;
}
}
for(int j = i - 1; j >= prev; j--) {
temp.push_back(a[j]);
}
prev = i;
cur_min = a[i];
cur_max = a[i];
}
else {
cur_max = max(cur_max, a[i]);
cur_min = min(cur_min, a[i]);
int f = 0;
for(int j = 0; j < temp.size(); j++) {
if(temp[j] > cur_min && temp[j] < cur_max) {
ans++;
f = 1;
break;
}
}
if(f == 1) {
for(int j = i - 1; j >= prev; j--) {
temp.push_back(a[j]);
}
prev = i;
cur_min = a[i];
cur_max = a[i];
}
}
}
for(int j = 0; j < temp.size(); j++) {
if(temp[j] > cur_min && temp[j] < cur_max) {
ans++;
break;
}
}
cout << ans << "\n";
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
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... |