Submission #831709

#TimeUsernameProblemLanguageResultExecution timeMemory
831709Chal1shkanMoney (IZhO17_money)C++14
100 / 100
470 ms31440 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 segtree { ll t[maxn * 4]; void update (ll pos, ll x, ll v = 1, ll tl = 1, ll tr = 1000000) { if (tl == tr) { t[v] += x; return; } ll tm = (tl + tr) >> 1; if (pos <= tm) { update(pos, x, v * 2, tl, tm); } else { update(pos, x, v * 2 + 1, tm + 1, tr); } t[v] = t[v * 2] + t[v * 2 + 1]; } ll get (ll l, ll r, ll v = 1, ll tl = 1, ll tr = 1000000) { if (tr < l || r < tl) return 0; if (l <= tl && tr <= r) return t[v]; ll tm = (tl + tr) >> 1; return get (l, r, v * 2, tl, tm) + get(l, r, v * 2 + 1, tm + 1, tr); } } 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.update(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...