Submission #831719

#TimeUsernameProblemLanguageResultExecution timeMemory
831719Chal1shkanMoney (IZhO17_money)C++14
0 / 100
3 ms4180 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 FenwickTree { vector<int> bit; // binary indexed tree int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<int> const &a) : FenwickTree(a.size()) { for (size_t i = 0; i < a.size(); i++) add(i, a[i]); } int sum(int r) { int ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); } void add(int idx, int delta) { for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta; } }; void ma1n (/* SABR */) { FenwickTree st(1000000); 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.sum(a[i] + 1, a[j + 1] - 1)) break; ++j; } ans++; for (ll k = i; k <= j; ++k) st.add(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...