# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
596881 |
2022-07-15T08:42:02 Z |
반딧불(#8447) |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4436 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[100002];
struct segTree{
int tree[400002];
void init(int i, int l, int r, ll* A){
if(l==r){
tree[i] = l;
return;
}
int m = (l+r)>>1;
init(i*2, l, m, A);
init(i*2+1, m+1, r, A);
tree[i] = (arr[tree[i*2]] > arr[tree[i*2+1]]) ? tree[i*2] : tree[i*2+1];
}
void update(int i, int l, int r, int x, int v){
if(l==r) return;
int m = (l+r)>>1;
if(x<=m) update(i*2, l, m, x, v);
else update(i*2+1, m+1, r, x, v);
tree[i] = (arr[tree[i*2]] > arr[tree[i*2+1]]) ? tree[i*2] : tree[i*2+1];
}
int query(int i, int l, int r, int s, int e){
if(r<s || e<l) return 0;
if(s<=l && r<=e) return tree[i];
int m = (l+r)>>1;
int t1 = query(i*2, l, m, s, e), t2 = query(i*2+1, m+1, r, s, e);
return (arr[t1] > arr[t2]) ? t1 : t2;
}
} tree;
struct Fenwick{
int n;
ll tree[100002];
void init(int _n){
n = _n;
for(int i=0; i<=n; i++) tree[i] = 0;
}
void add(int x, int v){
while(x<=n){
tree[x] += v;
x += x&-x;
}
}
ll sum(int x){
ll ret = 0;
while(x){
ret += tree[x];
x -= x&-x;
}
return ret;
}
ll sum(int l, int r){
return sum(r) - sum(l-1);
}
} fenwick;
int n, q;
int dnc(int l, int r, ll lim = 0){
if(l>r) return 0;
int m = tree.query(1, 1, n, l, r);
ll sum = fenwick.sum(l, r);
if(sum < lim) return 0;
int ret = 1;
ll tsum = fenwick.sum(l, m-1);
if(tsum >= arr[m]) ret += dnc(l, m-1, arr[m]);
tsum = fenwick.sum(m+1, r);
if(tsum >= arr[m]) ret += dnc(m+1, r, arr[m]);
return ret;
}
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
tree.init(1, 1, n, arr);
fenwick.init(n);
for(int i=1; i<=n; i++) fenwick.add(i, arr[i]);
scanf("%d", &q);
while(q--){
int t, l, r;
scanf("%d %d %d", &t, &l, &r);
if(t==1){
tree.update(1, 1, n, l, r);
fenwick.add(l, r-arr[l]);
arr[l] = r;
continue;
}
printf("%d\n", dnc(l, r));
}
}
Compilation message
fish2.cpp: In function 'int main()':
fish2.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
fish2.cpp:88:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
fish2.cpp:93:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
fish2.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | scanf("%d %d %d", &t, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2820 KB |
Output is correct |
3 |
Correct |
16 ms |
2788 KB |
Output is correct |
4 |
Correct |
18 ms |
2784 KB |
Output is correct |
5 |
Correct |
12 ms |
2868 KB |
Output is correct |
6 |
Correct |
27 ms |
2872 KB |
Output is correct |
7 |
Correct |
11 ms |
2868 KB |
Output is correct |
8 |
Correct |
29 ms |
2900 KB |
Output is correct |
9 |
Correct |
11 ms |
2772 KB |
Output is correct |
10 |
Correct |
17 ms |
2812 KB |
Output is correct |
11 |
Correct |
13 ms |
2868 KB |
Output is correct |
12 |
Correct |
12 ms |
2888 KB |
Output is correct |
13 |
Correct |
12 ms |
2832 KB |
Output is correct |
14 |
Correct |
21 ms |
4344 KB |
Output is correct |
15 |
Correct |
21 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2820 KB |
Output is correct |
3 |
Correct |
16 ms |
2788 KB |
Output is correct |
4 |
Correct |
18 ms |
2784 KB |
Output is correct |
5 |
Correct |
12 ms |
2868 KB |
Output is correct |
6 |
Correct |
27 ms |
2872 KB |
Output is correct |
7 |
Correct |
11 ms |
2868 KB |
Output is correct |
8 |
Correct |
29 ms |
2900 KB |
Output is correct |
9 |
Correct |
11 ms |
2772 KB |
Output is correct |
10 |
Correct |
17 ms |
2812 KB |
Output is correct |
11 |
Correct |
13 ms |
2868 KB |
Output is correct |
12 |
Correct |
12 ms |
2888 KB |
Output is correct |
13 |
Correct |
12 ms |
2832 KB |
Output is correct |
14 |
Correct |
21 ms |
4344 KB |
Output is correct |
15 |
Correct |
21 ms |
4436 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4065 ms |
3168 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2820 KB |
Output is correct |
3 |
Correct |
16 ms |
2788 KB |
Output is correct |
4 |
Correct |
18 ms |
2784 KB |
Output is correct |
5 |
Correct |
12 ms |
2868 KB |
Output is correct |
6 |
Correct |
27 ms |
2872 KB |
Output is correct |
7 |
Correct |
11 ms |
2868 KB |
Output is correct |
8 |
Correct |
29 ms |
2900 KB |
Output is correct |
9 |
Correct |
11 ms |
2772 KB |
Output is correct |
10 |
Correct |
17 ms |
2812 KB |
Output is correct |
11 |
Correct |
13 ms |
2868 KB |
Output is correct |
12 |
Correct |
12 ms |
2888 KB |
Output is correct |
13 |
Correct |
12 ms |
2832 KB |
Output is correct |
14 |
Correct |
21 ms |
4344 KB |
Output is correct |
15 |
Correct |
21 ms |
4436 KB |
Output is correct |
16 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |