| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1351239 | dex111222333444555 | Money (IZhO17_money) | C++20 | 75 ms | 8244 KiB |
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define dbg(x) "[" #x " = " << x << "]"
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
using namespace std;
const int mod = 1e9 + 7, infINT = 1e9 + 1321;
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
struct fenwickTree{
int n;
vector<int > bit;
fenwickTree(int _n = 0): n(_n){
bit.assign(n + 1, infINT);
}
void update(int pos, const int &v){
for(; pos > 0; pos ^= pos & -pos)
minimize(bit[pos], v);
}
int get(int pos){
int mi = infINT;
for(; pos <= n; pos += pos & -pos) mi = min(mi, bit[pos]);
return mi;
}
};
const int MAXN = 1e6 + 6;
int numVal, val[MAXN];
void input(){
cin >> numVal;
for(int i = 1; i <= numVal; i++) cin >> val[i];
}
void solve(){
int res = 0;
fenwickTree bit(MAXN);
int cur = 1;
while(cur <= numVal){
int nxt = cur + 1;
while(nxt <= numVal && val[nxt - 1] <= val[nxt] && bit.get(val[cur] + 1) >= val[nxt]) nxt++;
for(int i = cur; i < nxt; i++) bit.update(val[i], val[i]);
cur = nxt;
res++;
}
cout << res << '\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
