Submission #229341

#TimeUsernameProblemLanguageResultExecution timeMemory
229341DodgeBallManMoney (IZhO17_money)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, a[N], s[N], cnt, ans; set<int> se; void process( int idx ) { //printf("%d\n",idx); int l = s[idx], r = s[idx+1] - 1; //printf("L : %d R : %d\n",l,r); while( l < r ) { int mid = l + r + 1 >> 1; //printf("MID : %d %d\n",mid,s[mid]); if( se.upper_bound( a[s[idx]] ) == se.lower_bound( a[mid] ) ) l = mid; else r = mid - 1; } for( int i = s[idx] ; i <= l ; i++ ) se.insert( a[i] ); s[idx] = l + 1; //printf("L : %d\n",l); ans++; return ; } int main() { scanf("%d",&n); for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]); a[0] = 2e9; for( int i = 1 ; i <= n ; i++ ) if( a[i] < a[i-1] ) s[++cnt] = i; s[++cnt] = n+1; /*for( int i = 1 ; i <= cnt ; i++ ) printf("%d ", s[i]); printf("\n");*/ for( int i = 1 ; i < cnt ; i++ ) { do{ process( i ); }while( s[i] < s[i+1] ); } printf("%d",ans); return 0; }

Compilation message (stderr)

money.cpp: In function 'void process(int)':
money.cpp:13:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r + 1 >> 1;
                   ~~~~~~^~~
money.cpp: In function 'int main()':
money.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
money.cpp:28:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for( int i = 1 ; 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...