Submission #168937

#TimeUsernameProblemLanguageResultExecution timeMemory
168937beso123Money (IZhO17_money)C++14
100 / 100
1198 ms62072 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N=1000006; int n,a[N],fen[N],ans; set <int> st; void UPD(int x,int val){ while(x<=N){ fen[x]+=val; x=x+(x&(-x)); } } int GET(int x){ int sum=0; while(x>=1){ sum+=fen[x]; x=x-(x&(-x)); } return sum; } int get(int l,int r){ if(l>r) return 0; return GET(r)-GET(l-1); } main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); scanf("%lld",&n); for(int k=1;k<=n;k++){ scanf("%lld",&a[k]); } int l=1; for(int r=1;r<=n+1;r++){ if(a[r-1]>a[r]){ ans++; for(int j=l;j<=r-1;j++) st.insert(a[j]); l=r; continue; } auto it=st.upper_bound(a[l]); if(it!=st.end() && *it<a[r]){ ans++; for(int j=l;j<=r-1;j++) st.insert(a[j]); l=r; } } printf("%lld",ans); return 0; }

Compilation message (stderr)

money.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
money.cpp: In function 'int main()':
money.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
money.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[k]);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...