Submission #51341

#TimeUsernameProblemLanguageResultExecution timeMemory
51341NicksechkoMoney (IZhO17_money)C++11
100 / 100
975 ms57192 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; int ans = 0; bitset<1000502> s; ll a[1000500]; int t[4000500]; int p[1000500]; int sz = 1000001; inline void upd(int v, int tl, int tr, int p) { if(tl == tr) { t[v] = 1; return; } int tm = tl + tr >> 1; if(p <= tm) upd(v << 1, tl, tm, p); else upd((v << 1) + 1, tm + 1, tr, p); t[v] = t[v << 1] + t[(v << 1) + 1]; } inline int get(int v, int tl , int tr, int l, int r) { if(l > r) return 0; if(tl == l && tr == r) return t[v]; int tm = tl + tr >> 1; return get((v << 1), tl, tm, l, min(r, tm)) + get((v << 1) + 1, tm + 1, tr, max(tm + 1, l), r); } inline int fnd(int v, int tl, int tr, int need) { if(tl == tr) return tl; int tm = tl + tr >> 1; if(need <= t[(v << 1)]) return fnd((v << 1), tl, tm, need); else return fnd((v << 1) + 1, tm + 1, tr, need- t[(v << 1)]); } int main() { // freopen("money.in", "r", stdin); // freopen("money.out", "w", stdout); scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%lld", a + i); upd(1, 1, sz, sz); for(int i = 1; i <= n;) { int f = get(1, 1, sz, 1, a[i]) + 1; int nxt = fnd(1, 1, sz, f); ll last = a[i]; while(i <= n && a[i] <= nxt && a[i] >= last) upd(1, 1, sz, a[i]), last = a[i], i++; ans++; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

money.cpp: In function 'void upd(int, int, int, int)':
money.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int get(int, int, int, int, int)':
money.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int fnd(int, int, int, int)':
money.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int main()':
money.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
money.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", 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...