# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
114606 | 2019-06-02T04:23:42 Z | FutymyClone | Money (IZhO17_money) | C++14 | 2 ms | 384 KB |
#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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Incorrect | 2 ms | 376 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Incorrect | 2 ms | 376 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Incorrect | 2 ms | 376 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Incorrect | 2 ms | 376 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |