# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
596884 |
2022-07-15T08:43:08 Z |
반딧불(#8447) |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4444 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){
arr[l] = r;
tree.update(1, 1, n, l, r);
fenwick.add(l, r-arr[l]);
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);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
25 ms |
2876 KB |
Output is correct |
3 |
Correct |
14 ms |
2788 KB |
Output is correct |
4 |
Correct |
20 ms |
2896 KB |
Output is correct |
5 |
Correct |
18 ms |
2888 KB |
Output is correct |
6 |
Correct |
49 ms |
2880 KB |
Output is correct |
7 |
Correct |
15 ms |
2796 KB |
Output is correct |
8 |
Correct |
34 ms |
2932 KB |
Output is correct |
9 |
Correct |
19 ms |
2772 KB |
Output is correct |
10 |
Correct |
21 ms |
2896 KB |
Output is correct |
11 |
Correct |
13 ms |
2852 KB |
Output is correct |
12 |
Correct |
22 ms |
2772 KB |
Output is correct |
13 |
Correct |
18 ms |
2840 KB |
Output is correct |
14 |
Correct |
26 ms |
4296 KB |
Output is correct |
15 |
Correct |
31 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
25 ms |
2876 KB |
Output is correct |
3 |
Correct |
14 ms |
2788 KB |
Output is correct |
4 |
Correct |
20 ms |
2896 KB |
Output is correct |
5 |
Correct |
18 ms |
2888 KB |
Output is correct |
6 |
Correct |
49 ms |
2880 KB |
Output is correct |
7 |
Correct |
15 ms |
2796 KB |
Output is correct |
8 |
Correct |
34 ms |
2932 KB |
Output is correct |
9 |
Correct |
19 ms |
2772 KB |
Output is correct |
10 |
Correct |
21 ms |
2896 KB |
Output is correct |
11 |
Correct |
13 ms |
2852 KB |
Output is correct |
12 |
Correct |
22 ms |
2772 KB |
Output is correct |
13 |
Correct |
18 ms |
2840 KB |
Output is correct |
14 |
Correct |
26 ms |
4296 KB |
Output is correct |
15 |
Correct |
31 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4038 ms |
3088 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
25 ms |
2876 KB |
Output is correct |
3 |
Correct |
14 ms |
2788 KB |
Output is correct |
4 |
Correct |
20 ms |
2896 KB |
Output is correct |
5 |
Correct |
18 ms |
2888 KB |
Output is correct |
6 |
Correct |
49 ms |
2880 KB |
Output is correct |
7 |
Correct |
15 ms |
2796 KB |
Output is correct |
8 |
Correct |
34 ms |
2932 KB |
Output is correct |
9 |
Correct |
19 ms |
2772 KB |
Output is correct |
10 |
Correct |
21 ms |
2896 KB |
Output is correct |
11 |
Correct |
13 ms |
2852 KB |
Output is correct |
12 |
Correct |
22 ms |
2772 KB |
Output is correct |
13 |
Correct |
18 ms |
2840 KB |
Output is correct |
14 |
Correct |
26 ms |
4296 KB |
Output is correct |
15 |
Correct |
31 ms |
4444 KB |
Output is correct |
16 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |