# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
38235 | 2018-01-03T05:07:15 Z | mirbek01 | Money (IZhO17_money) | C++14 | 0 ms | 21548 KB |
# include <bits/stdc++.h> # define pb push_back # define fr first # define sc second # define mk make_pair using namespace std; const long long linf = 1e18 + 7; const int inf = 1e9 + 7; const int N = 1e6 + 5; typedef long long ll; int n, a[N], t[N * 4], ans = 1; void update(int pos, int v = 1, int tl = 1, int tr = n){ if(tl == tr) t[v] ++; else{ int tm = (tl + tr) >> 1; if(pos <= tm) update(pos, v << 1, tl, tm); else update(pos, (v << 1) | 1, tm + 1, tr); t[v] = t[v << 1] + t[(v << 1) | 1]; } } int get(int l, int r, int v = 1, int tl = 1, int tr = n){ if(l > tr || tl > r) return 0; if(l <= tl && tr <= r) return t[v]; int tm = (tl + tr) >> 1; return get(l, r, v << 1, tl, tm) + get(l, r, (v << 1) | 1, tm + 1, tr); } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i ++) scanf("%d", &a[i]); int f = 0; for(int i = 2; i <= n; i ++){ if(a[i] < a[i - 1]){ ans ++; while(f + 1 <= i) update(a[f ++]); } else { int sum = get(a[f] + 1, a[i] - 1); // cout << a[f + 1] + 1 << " " << a[i] - 1 << " " << sum << endl; if(sum){ ans ++; while(f + 1 <= i) update(a[f ++]); } } } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 21548 KB | Output is correct |
2 | Correct | 0 ms | 21548 KB | Output is correct |
3 | Correct | 0 ms | 21548 KB | Output is correct |
4 | Correct | 0 ms | 21548 KB | Output is correct |
5 | Correct | 0 ms | 21548 KB | Output is correct |
6 | Correct | 0 ms | 21548 KB | Output is correct |
7 | Correct | 0 ms | 21548 KB | Output is correct |
8 | Correct | 0 ms | 21548 KB | Output is correct |
9 | Correct | 0 ms | 21548 KB | Output is correct |
10 | Incorrect | 0 ms | 21548 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 21548 KB | Output is correct |
2 | Correct | 0 ms | 21548 KB | Output is correct |
3 | Correct | 0 ms | 21548 KB | Output is correct |
4 | Correct | 0 ms | 21548 KB | Output is correct |
5 | Correct | 0 ms | 21548 KB | Output is correct |
6 | Correct | 0 ms | 21548 KB | Output is correct |
7 | Correct | 0 ms | 21548 KB | Output is correct |
8 | Correct | 0 ms | 21548 KB | Output is correct |
9 | Correct | 0 ms | 21548 KB | Output is correct |
10 | Incorrect | 0 ms | 21548 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 21548 KB | Output is correct |
2 | Correct | 0 ms | 21548 KB | Output is correct |
3 | Correct | 0 ms | 21548 KB | Output is correct |
4 | Correct | 0 ms | 21548 KB | Output is correct |
5 | Correct | 0 ms | 21548 KB | Output is correct |
6 | Correct | 0 ms | 21548 KB | Output is correct |
7 | Correct | 0 ms | 21548 KB | Output is correct |
8 | Correct | 0 ms | 21548 KB | Output is correct |
9 | Correct | 0 ms | 21548 KB | Output is correct |
10 | Incorrect | 0 ms | 21548 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 21548 KB | Output is correct |
2 | Correct | 0 ms | 21548 KB | Output is correct |
3 | Correct | 0 ms | 21548 KB | Output is correct |
4 | Correct | 0 ms | 21548 KB | Output is correct |
5 | Correct | 0 ms | 21548 KB | Output is correct |
6 | Correct | 0 ms | 21548 KB | Output is correct |
7 | Correct | 0 ms | 21548 KB | Output is correct |
8 | Correct | 0 ms | 21548 KB | Output is correct |
9 | Correct | 0 ms | 21548 KB | Output is correct |
10 | Incorrect | 0 ms | 21548 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |