제출 #173450

#제출 시각아이디문제언어결과실행 시간메모리
173450srvltMoney (IZhO17_money)C++14
100 / 100
235 ms15056 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; #define ll long long #define db double #define pb push_back #define ppb pop_back #define fi first #define se second #define mp make_pair #define size(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define low_b lower_bound #define endl "\n" //#define int long long using namespace std; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair <int, int> pii; const int N = 1000003, M = 1000000; int n, a[N], fen[N]; void upd(int x) { for (; x <= M; x |= (x + 1)) { fen[x]++; } } int get(int x) { int res = 0; for (; x >= 0; x = (x & (x + 1)) - 1) { res += fen[x]; } return res; } void solve(int tc) { // check for (int i = 0; i < n; j++) cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int j = 1, ans = 0, i = 1; while (i <= n) { while (j <= n && ((a[j] >= a[j - 1] && get(a[j] - 1) - get(a[i]) <= 0) || j == i)) { j++; } for (int k = i; k < j; k++) { upd(a[k]); } ans++; i = j; } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int i = 0; i < tc; i++) { solve(i); // cleanup(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...