# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977455 | shoryu386 | Money (IZhO17_money) | C++17 | 5 ms | 4700 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MX 1000007
int fwt[MX];
#define lsb(x) (x&(-x))
void update(int x, int k){
x++;
for (; x < MX; x += lsb(x)){
fwt[x] += k;
}
}
int sum(int x){
x++;
int res = 0;
for (; x != 0; x -= lsb(x)){
res += fwt[x];
}
return res;
}
int query(int a, int b){
return sum(b) - sum(a-1);
}
main(){ ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
//attempt greedy
int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
bitset<1000007> taken;
int ans = 0;
for (int zzz = 0; zzz < n; zzz++){
if (taken[zzz]){
continue;
}
ans++;
taken[zzz] = 1;
vector<int> items; items.push_back(arr[zzz]);
for (int y = zzz+1; y < n; y++){
if (items.back() <= arr[y] && query(arr[zzz]+1, arr[y]-1) == 0){
taken[y] = 1;
items.push_back(arr[y]);
}
else{
break;
}
}
for (auto y : items){
update(y, 1);
}
}
cout << ans;
}
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... |