Submission #36470

#TimeUsernameProblemLanguageResultExecution timeMemory
36470szawinisMoney (IZhO17_money)C++14
0 / 100
0 ms9828 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = (1e6)+1; int n, ans, a[MAX], f[MAX]; vector<pair<int,int> > segs; void update(int i) { ++i; while(i < MAX) ++f[i], i += i & -i; } int query(int i) { ++i; int ret = 0; while(i > 0) ret += f[i], i -= i & -i; return ret; } int main() { scanf("%d",&n); int curr = 0; for(int i = 0; i < n; i++) { scanf("%d",a+i); if(i && a[i] < a[i-1]) { segs.emplace_back(curr, i-1); curr = i; } } segs.emplace_back(curr, n-1); for(auto p: segs) { int l, r; tie(l, r) = p; int last = l; for(int i = l+1; i <= r; i++) if(query(a[i]-1) - query(a[l])) { while(last < i) update(last++); ++ans; } while(last <= r) update(last++); ++ans; } printf("%d", ans); }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:15:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
money.cpp:18:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   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...