Submission #831722

#TimeUsernameProblemLanguageResultExecution timeMemory
831722Chal1shkanMoney (IZhO17_money)C++14
100 / 100
157 ms22748 KiB
//Bismillahir-Rahmanir-Rahim # include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define all(x) (x).begin(), (x).end() # define deb(x) cerr << #x << " = " << x << endl; # define pll pair <ll, ll> # define pii pair <int, int> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 1e6 + 7; const ll inf = 2e18 + 0; const ll mod = 1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct fenwick { ll ft[maxn]; void upd (ll id, ll x) { for (; id < maxn; id += (id & -id)) { ft[id] += x; } } ll get (ll id) { ll res = 0; for (; id > 0; id -= (id & -id)) { res += ft[id]; } return res; } ll get (ll l, ll r) { if (l > r) return 0; return get(r) - get(l - 1); } } st; void ma1n (/* SABR */) { ll n; cin >> n; ll a[n + 3]; for (ll i = 1; i <= n; ++i) { cin >> a[i]; } ll ans = 0; for (ll i = 1; i <= n; ++i) { ll j = i; while (1) { if (j + 1 > n) break; if (a[j] > a[j + 1]) break; if (st.get(a[i] + 1, a[j + 1] - 1)) break; ++j; } ans++; for (ll k = i; k <= j; ++k) st.upd(a[k], 1); i = j; } cout << ans << nl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << '\n'; ma1n(); } return 0; } // 998batrr | BbIWEJI 3A TObOU!!! // tourist | BbIWEJI 3A TObOU!!!
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...