# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823740 | peteza | Stranded Far From Home (BOI22_island) | C++14 | 39 ms | 19584 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;
int n, m;
int s[200005];
int ans[200005];
struct node {
int idx=0;
long long sum = 0;
node *l, *r;
node(int x):l(0),r(0),sum(s[x]),idx(x){}
};
stack<node*> curs;
node* root;
long long dfssum(node* cur) {
if(!cur) return 0;
return cur->sum = dfssum(cur->l) + dfssum(cur->r) + s[cur->idx];
}
void dfsans(node *cur, long long parsum = -1, bool parres = 1) {
if(!cur) return;
ans[cur->idx] = ((cur->sum) >= parsum && parres);
dfsans(cur->l, s[cur->idx], ans[cur->idx]);
dfsans(cur->r, s[cur->idx], ans[cur->idx]);
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) {
cin >> s[i];
auto neu = new node(i);
while(!curs.empty() && s[curs.top()->idx] < s[i]) {
curs.top()->r = neu->l;
neu->l = curs.top();
curs.pop();
}
curs.push(neu);
}
root = curs.top(); curs.pop();
while(!curs.empty()) {
curs.top()->r = root;
root = curs.top(); curs.pop();
}
dfssum(root); dfsans(root);
for(int i=1;i<=n;i++) cout << ans[i];
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |