제출 #1152401

#제출 시각아이디문제언어결과실행 시간메모리
1152401hamzabcMoney (IZhO17_money)C++20
100 / 100
1131 ms55164 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define mod 1000000007 #define sp << " " << #define endl << '\n' inline int val(set<long long> &st, long long val, bool flag){ set<long long>::iterator y; if (flag) y = st.lower_bound(val); else y = st.upper_bound(val); if (y == st.end()) return -1; return *y; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long int N; cin >> N; vector<long long int> lst(N); for (int i = 0; i < N; i++){ cin >> lst[i]; } long long int ret = 1; set<long long int> st; st.insert(lst[0]); long long frst = -1; for (int i = 1; i < N; i++){ if (lst[i] < lst[i - 1] || (lst[i - 1] != lst[i] && frst != val(st, lst[i], true))){ ret++; frst = val(st, lst[i], false); } st.insert(lst[i]); } cout << ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...