# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
467125 | aryan12 | Money (IZhO17_money) | C++17 | 0 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
map<int, int> cc;
for(int i = 1; i <= n; i++) {
cin >> a[i];
cc[a[i]] = 1;
}
int tem = 1;
for(auto i: cc) {
cc[i.first] = tem++;
}
for(int i = 1; i <= n; i++) {
a[i] = cc[a[i]];
}
vector<int> temp;
temp.push_back(a[1]);
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 = INT_MAX;
cur_max = -1;
}
cur_max = max(cur_max, a[i]);
cur_min = min(cur_min, 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;
}
컴파일 시 표준 에러 (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... |