Submission #36475

#TimeUsernameProblemLanguageResultExecution timeMemory
36475szawinisMoney (IZhO17_money)C++14
100 / 100
286 ms9828 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = (1e6)+1; int n, ans = 1, a[MAX], f[MAX]; void update(int i) { while(i < MAX) ++f[i], i += i & -i; } int query(int i) { int ret = 0; while(i > 0) ret += f[i], i -= i & -i; return ret; } int main() { scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d", a+i); for(int i = 1, last = 0; i < n; i++) { if(a[i] < a[i-1] || query(a[i]-1) - query(a[last]) > 0) { ++ans; while(last < i) update(a[last++]); } } printf("%d", ans); }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:13:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
money.cpp:14:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < n; i++) scanf("%d", a+i);
                                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...