Submission #169685

#TimeUsernameProblemLanguageResultExecution timeMemory
169685stefdascaMoney (IZhO17_money)C++14
45 / 100
1540 ms52956 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("Ofast") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 using namespace std; typedef long long ll; int n, ans = 1, v[1000002]; bool iz[1000002]; set<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i) cin >> v[i]; s.insert(v[1]); iz[v[1]] = 1; int i = 2; while(i <= n && v[i] >= v[i-1]) { if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); ++i; } for(; i <= n; ) { ++ans; set<int> ::iterator it = s.lower_bound(v[i]); if(it == s.end()) { int j = i+1; if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); while(j <= n && v[j] >= v[j-1]) { if(!iz[v[j]]) iz[v[j]] = 1, s.insert(v[j]); ++j; } i = j; } else { int val = *it; if(it == s.begin() && v[i] < val) { int j = i+1; if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); while(j <= n && v[j] >= v[j-1] && v[j] <= val) { if(!iz[v[j]]) iz[v[j]] = 1, s.insert(v[j]); ++j; } i = j; } else { if(val == v[i]) { ++it; if(it == s.end()) { int j = i+1; if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); while(j <= n && v[j] >= v[j-1]) { if(!iz[v[j]]) iz[v[j]] = 1, s.insert(v[j]); ++j; } i = j; } else { int j = i+1; int val2 = *it; if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); while(j <= n && v[j] >= v[j-1] && v[j] <= val2) { if(!iz[v[j]]) iz[v[j]] = 1, s.insert(v[j]); ++j; } i = j; } } else { int j = i+1; if(!iz[v[i]]) iz[v[i]] = 1, s.insert(v[i]); while(j <= n && v[j] >= v[j-1] && v[j] <= val) { if(!iz[v[j]]) iz[v[j]] = 1, s.insert(v[j]); ++j; } i = j; } } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...