제출 #541037

#제출 시각아이디문제언어결과실행 시간메모리
541037vinnipuh01Money (IZhO17_money)C++17
100 / 100
1208 ms56136 KiB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    freopen ( "sum.in", "r", stdin )
*/

int n, a[ 1000001 ];
set <int> st;

main () {
	cin >> n;
	for ( int i = 1; i <= n; i ++ )
		cin >> a[ i ];
	ans = 1;
	st.insert( a[ 1 ] );
	for ( int i = 2; i <= n; i ++ ) {
		if ( pos && a[ i ] != pos ) {
			pos = 0;
			ans ++;
			st.insert( a[ i ] );
			continue;
		}
		else if ( pos && a[ i ] == pos )
			continue;
		auto itt = st.upper_bound( a[ i ] );
		if ( itt == st.begin() )
			ans ++;
		else {
			itt = --itt;
			if ( *itt != a[ i - 1 ] ) {
				if ( *itt == a[ i ] && itt != st.begin() ) {
					itt = --itt;
					if ( *itt != a[ i - 1 ] )
						ans ++;
					else
						pos = a[ i ];
				}
				else
					ans ++;
			}
		}
		st.insert( a[ i ] );
	}
	cout << ans;
}

/*
6
3 6 4 5 1 2

*/

컴파일 시 표준 에러 (stderr) 메시지

money.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...