Submission #92517

#TimeUsernameProblemLanguageResultExecution timeMemory
92517Nodir_BobievMoney (IZhO17_money)C++14
0 / 100
2 ms376 KiB
// solved by using fenvick tree // + binary search # include <iostream> using namespace std; const int N = 1e6 + 100; int n, ans = 1; int a[N]; int cnt[N]; void update(int i) { while(i < N){ cnt[i]++; i += i & -i; } } int get(int i){ int ret = 0; while(i > 0){ ret += cnt[i]; i -= i & -i; } return ret; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; update(N - 99); update(a[1]); int x = N - 99; for (int i = 2; i <= n; i++){ if(a[i] < a[i - 1] || x < a[i]){ int l = a[i], m, r = N; while(r > l){ m = (r + l) >> 1; if(get(a[m]) > a[i]) r = m; else l = m + 1; } x = l; ++ ans; } update(a[i]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...