# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
818421 |
2023-08-10T04:47:47 Z |
반딧불(#10131) |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
5036 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){
fenwick.add(l, r-arr[l]);
arr[l] = r;
tree.update(1, 1, n, 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
312 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
3380 KB |
Output is correct |
3 |
Correct |
10 ms |
3132 KB |
Output is correct |
4 |
Correct |
12 ms |
3412 KB |
Output is correct |
5 |
Correct |
10 ms |
3156 KB |
Output is correct |
6 |
Correct |
24 ms |
3744 KB |
Output is correct |
7 |
Correct |
9 ms |
3104 KB |
Output is correct |
8 |
Correct |
23 ms |
3784 KB |
Output is correct |
9 |
Correct |
9 ms |
3028 KB |
Output is correct |
10 |
Correct |
12 ms |
3412 KB |
Output is correct |
11 |
Correct |
9 ms |
3172 KB |
Output is correct |
12 |
Correct |
12 ms |
3028 KB |
Output is correct |
13 |
Correct |
10 ms |
3028 KB |
Output is correct |
14 |
Correct |
18 ms |
4992 KB |
Output is correct |
15 |
Correct |
18 ms |
4948 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
312 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
12 ms |
3380 KB |
Output is correct |
23 |
Correct |
10 ms |
3132 KB |
Output is correct |
24 |
Correct |
12 ms |
3412 KB |
Output is correct |
25 |
Correct |
10 ms |
3156 KB |
Output is correct |
26 |
Correct |
24 ms |
3744 KB |
Output is correct |
27 |
Correct |
9 ms |
3104 KB |
Output is correct |
28 |
Correct |
23 ms |
3784 KB |
Output is correct |
29 |
Correct |
9 ms |
3028 KB |
Output is correct |
30 |
Correct |
12 ms |
3412 KB |
Output is correct |
31 |
Correct |
9 ms |
3172 KB |
Output is correct |
32 |
Correct |
12 ms |
3028 KB |
Output is correct |
33 |
Correct |
10 ms |
3028 KB |
Output is correct |
34 |
Correct |
18 ms |
4992 KB |
Output is correct |
35 |
Correct |
18 ms |
4948 KB |
Output is correct |
36 |
Correct |
152 ms |
4240 KB |
Output is correct |
37 |
Correct |
85 ms |
3156 KB |
Output is correct |
38 |
Correct |
52 ms |
3236 KB |
Output is correct |
39 |
Correct |
75 ms |
3796 KB |
Output is correct |
40 |
Correct |
52 ms |
3228 KB |
Output is correct |
41 |
Correct |
2451 ms |
3860 KB |
Output is correct |
42 |
Correct |
3295 ms |
3860 KB |
Output is correct |
43 |
Correct |
14 ms |
3000 KB |
Output is correct |
44 |
Correct |
15 ms |
3028 KB |
Output is correct |
45 |
Correct |
215 ms |
3604 KB |
Output is correct |
46 |
Correct |
317 ms |
3484 KB |
Output is correct |
47 |
Correct |
29 ms |
3168 KB |
Output is correct |
48 |
Correct |
13 ms |
3284 KB |
Output is correct |
49 |
Correct |
54 ms |
3484 KB |
Output is correct |
50 |
Correct |
1102 ms |
5016 KB |
Output is correct |
51 |
Execution timed out |
4070 ms |
5036 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
3380 KB |
Output is correct |
3 |
Correct |
10 ms |
3132 KB |
Output is correct |
4 |
Correct |
12 ms |
3412 KB |
Output is correct |
5 |
Correct |
10 ms |
3156 KB |
Output is correct |
6 |
Correct |
24 ms |
3744 KB |
Output is correct |
7 |
Correct |
9 ms |
3104 KB |
Output is correct |
8 |
Correct |
23 ms |
3784 KB |
Output is correct |
9 |
Correct |
9 ms |
3028 KB |
Output is correct |
10 |
Correct |
12 ms |
3412 KB |
Output is correct |
11 |
Correct |
9 ms |
3172 KB |
Output is correct |
12 |
Correct |
12 ms |
3028 KB |
Output is correct |
13 |
Correct |
10 ms |
3028 KB |
Output is correct |
14 |
Correct |
18 ms |
4992 KB |
Output is correct |
15 |
Correct |
18 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
3893 ms |
4924 KB |
Output is correct |
18 |
Execution timed out |
4081 ms |
4956 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
3380 KB |
Output is correct |
3 |
Correct |
10 ms |
3132 KB |
Output is correct |
4 |
Correct |
12 ms |
3412 KB |
Output is correct |
5 |
Correct |
10 ms |
3156 KB |
Output is correct |
6 |
Correct |
24 ms |
3744 KB |
Output is correct |
7 |
Correct |
9 ms |
3104 KB |
Output is correct |
8 |
Correct |
23 ms |
3784 KB |
Output is correct |
9 |
Correct |
9 ms |
3028 KB |
Output is correct |
10 |
Correct |
12 ms |
3412 KB |
Output is correct |
11 |
Correct |
9 ms |
3172 KB |
Output is correct |
12 |
Correct |
12 ms |
3028 KB |
Output is correct |
13 |
Correct |
10 ms |
3028 KB |
Output is correct |
14 |
Correct |
18 ms |
4992 KB |
Output is correct |
15 |
Correct |
18 ms |
4948 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4080 ms |
3764 KB |
Time limit exceeded |
18 |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
312 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
12 ms |
3380 KB |
Output is correct |
23 |
Correct |
10 ms |
3132 KB |
Output is correct |
24 |
Correct |
12 ms |
3412 KB |
Output is correct |
25 |
Correct |
10 ms |
3156 KB |
Output is correct |
26 |
Correct |
24 ms |
3744 KB |
Output is correct |
27 |
Correct |
9 ms |
3104 KB |
Output is correct |
28 |
Correct |
23 ms |
3784 KB |
Output is correct |
29 |
Correct |
9 ms |
3028 KB |
Output is correct |
30 |
Correct |
12 ms |
3412 KB |
Output is correct |
31 |
Correct |
9 ms |
3172 KB |
Output is correct |
32 |
Correct |
12 ms |
3028 KB |
Output is correct |
33 |
Correct |
10 ms |
3028 KB |
Output is correct |
34 |
Correct |
18 ms |
4992 KB |
Output is correct |
35 |
Correct |
18 ms |
4948 KB |
Output is correct |
36 |
Correct |
152 ms |
4240 KB |
Output is correct |
37 |
Correct |
85 ms |
3156 KB |
Output is correct |
38 |
Correct |
52 ms |
3236 KB |
Output is correct |
39 |
Correct |
75 ms |
3796 KB |
Output is correct |
40 |
Correct |
52 ms |
3228 KB |
Output is correct |
41 |
Correct |
2451 ms |
3860 KB |
Output is correct |
42 |
Correct |
3295 ms |
3860 KB |
Output is correct |
43 |
Correct |
14 ms |
3000 KB |
Output is correct |
44 |
Correct |
15 ms |
3028 KB |
Output is correct |
45 |
Correct |
215 ms |
3604 KB |
Output is correct |
46 |
Correct |
317 ms |
3484 KB |
Output is correct |
47 |
Correct |
29 ms |
3168 KB |
Output is correct |
48 |
Correct |
13 ms |
3284 KB |
Output is correct |
49 |
Correct |
54 ms |
3484 KB |
Output is correct |
50 |
Correct |
1102 ms |
5016 KB |
Output is correct |
51 |
Execution timed out |
4070 ms |
5036 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |