#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct segTree{
pair<ll, int> tree[800002];
void init(int i, int l, int r, ll *A){
if(l==r){
tree[i] = make_pair(A[l], l);
return;
}
int m = (l+r)>>1;
init(i*2, l, m, A);
init(i*2+1, m+1, r, A);
tree[i] = max(tree[i*2], tree[i*2+1]);
}
pair<ll, int> query(int i, int l, int r, int s, int e){
if(r<s || e<l) return make_pair(0LL, 0);
if(s<=l && r<=e) return tree[i];
int m = (l+r)>>1;
return max(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
}
} tree;
int n, m;
ll arr[200002];
ll sum[200002];
bool ans[200002];
vector<int> link[200002];
void dnc(int l, int r, ll lim=0){
if(l>r || sum[r]-sum[l-1] < lim) return;
pair<ll, int> tp = tree.query(1, 1, n, l, r);
int x = tp.second;
ans[x] = 1;
dnc(l, x-1, max(arr[x], lim-(sum[r]-sum[m-1])));
dnc(x+1, r, max(arr[x], lim-(sum[m]-sum[l-1])));
}
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
link[x].push_back(y);
link[y].push_back(x);
}
tree.init(1, 1, n, arr);
for(int i=1; i<=n; i++) sum[i] = sum[i-1] + arr[i];
dnc(1, n);
for(int i=1; i<=n; i++) printf("%d", ans[i]);
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
166 ms |
22992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
162 ms |
22832 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
142 ms |
25076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |