| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 114606 | FutymyClone | Money (IZhO17_money) | C++14 | 2 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N], nxt[N], bit[N];
stack <int> st;
void update (int x, int val) {
for (int i = x; i < N; i += i & -i) bit[i] += val;
}
int query (int x) {
int ans = 0;
for (int i = x; i > 0; i -= i & -i) ans += bit[i];
return ans;
}
int main(){
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (st.empty() || a[st.top()] <= a[i]) st.push(i);
else {
while (!st.empty()) nxt[st.top()] = i, st.pop();
st.push(i);
}
}
while (!st.empty()) nxt[st.top()] = n + 1, st.pop();
int cur = 1, ans = 0;
while (cur <= n) {
int l = cur, r = nxt[cur] - 1;
while (l <= r) {
int mid = (l + r) / 2;
int res = query(a[mid]) - query(a[cur] - 1);
if (res == 0 || res == a[mid] - a[cur] + 1) l = mid + 1;
else r = mid - 1;
}
ans++;
update(a[cur], 1); update(a[r] + 1, -1);
cur = l;
}
printf("%d", ans);
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... | ||||
