# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
818677 |
2023-08-10T06:17:02 Z |
반딧불(#10131) |
Fish 2 (JOI22_fish2) |
C++17 |
|
980 ms |
4500 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
struct segTree{
int cnt[400002], sum[400002];
void update(int i, int l, int r, int s, int e, int v){
if(r<s || e<l) return;
if(s<=l && r<=e){
cnt[i] += v;
sum[i] = cnt[i] ? r-l+1 : l==r ? 0 : sum[i*2] + sum[i*2+1];
return;
}
int m = (l+r)>>1;
update(i*2, l, m, s, e, v);
update(i*2+1, m+1, r, s, e, v);
sum[i] = cnt[i] ? r-l+1 : l==r ? 0 : sum[i*2] + sum[i*2+1];
}
int query(int i, int l, int r, int s, int e){
if(cnt[i]) return max(0, min(r, e) - max(l, s) + 1);
if(r<s || e<l) return 0;
if(s<=l && r<=e) return sum[i];
int m = (l+r)>>1;
return query(i*2, l, m, s, e) + query(i*2+1, m+1, r, s, e);
}
} tree;
int n, q;
ll arr[100005];
ll sum[100005];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(int i=1; i<=n+1; i++) sum[i] = sum[i-1] + arr[i];
vector<pair<int, ll> > vec;
vec.push_back(make_pair(0, INF));
for(int i=1; i<=n+1; i++){
while(!vec.empty() && vec.back().second <= (i==n+1?INF:arr[i])){
int l = vec.back().first, r = i;
if(l==0 && r==n+1) break;
vec.pop_back();
if(sum[r-1] - sum[l] < min(l==0?INF:arr[l], r==n+1?INF:arr[r])) tree.update(1, 1, n, l+1, r-1, 1);
}
int l = vec.back().first, r = i;
if(!(l==0 && r==n+1) && sum[r-1] - sum[l] < min(l==0?INF:arr[l], r==n+1?INF:arr[r]))
tree.update(1, 1, n, l+1, r-1, 1);
vec.push_back(make_pair(i, arr[i]));
}
scanf("%d", &q);
for(int i=1; i<=q; i++){
int t, l, r;
scanf("%d %d %d", &t, &l, &r);
vector<pair<int, int> > updates;
for(int d=0; d<60; d++){ /// l ~ ?
auto it = lower_bound(sum+1, sum+n+1, sum[l-1] + (1LL<<d));
if(it >= sum+r+1) break;
int s = l-1, e = it - sum;
if(arr[e] > sum[e-1] - sum[s] && s+1<e){
updates.push_back(make_pair(s+1, e-1));
tree.update(1, 1, n, s+1, e-1, 1);
}
}
for(int d=0; d<60; d++){ /// ? ~ r
auto it = upper_bound(sum+1, sum+n+1, sum[r] - (1LL<<d)) - 1;
if(it <= sum+l-1) break;
int s = it - sum, e = r+1;
if(arr[s] > sum[e-1] - sum[s] && s+1<e){
updates.push_back(make_pair(s+1, e-1));
tree.update(1, 1, n, s+1, e-1, 1);
}
}
printf("%d\n", (r-l+1) - tree.query(1, 1, n, l, r));
for(auto [l, r]: updates){
tree.update(1, 1, n, l, r, -1);
}
}
}
Compilation message
fish2.cpp: In function 'int main()':
fish2.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
fish2.cpp:39:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
fish2.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
fish2.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d %d %d", &t, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
28 ms |
3868 KB |
Output is correct |
3 |
Correct |
27 ms |
3808 KB |
Output is correct |
4 |
Correct |
29 ms |
3808 KB |
Output is correct |
5 |
Correct |
29 ms |
3796 KB |
Output is correct |
6 |
Correct |
25 ms |
3660 KB |
Output is correct |
7 |
Correct |
21 ms |
3812 KB |
Output is correct |
8 |
Correct |
24 ms |
3796 KB |
Output is correct |
9 |
Correct |
21 ms |
3924 KB |
Output is correct |
10 |
Correct |
25 ms |
3824 KB |
Output is correct |
11 |
Correct |
23 ms |
3808 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
27 ms |
3816 KB |
Output is correct |
14 |
Correct |
26 ms |
3792 KB |
Output is correct |
15 |
Correct |
28 ms |
3776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
28 ms |
3868 KB |
Output is correct |
3 |
Correct |
27 ms |
3808 KB |
Output is correct |
4 |
Correct |
29 ms |
3808 KB |
Output is correct |
5 |
Correct |
29 ms |
3796 KB |
Output is correct |
6 |
Correct |
25 ms |
3660 KB |
Output is correct |
7 |
Correct |
21 ms |
3812 KB |
Output is correct |
8 |
Correct |
24 ms |
3796 KB |
Output is correct |
9 |
Correct |
21 ms |
3924 KB |
Output is correct |
10 |
Correct |
25 ms |
3824 KB |
Output is correct |
11 |
Correct |
23 ms |
3808 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
27 ms |
3816 KB |
Output is correct |
14 |
Correct |
26 ms |
3792 KB |
Output is correct |
15 |
Correct |
28 ms |
3776 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Incorrect |
980 ms |
4500 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
28 ms |
3868 KB |
Output is correct |
3 |
Correct |
27 ms |
3808 KB |
Output is correct |
4 |
Correct |
29 ms |
3808 KB |
Output is correct |
5 |
Correct |
29 ms |
3796 KB |
Output is correct |
6 |
Correct |
25 ms |
3660 KB |
Output is correct |
7 |
Correct |
21 ms |
3812 KB |
Output is correct |
8 |
Correct |
24 ms |
3796 KB |
Output is correct |
9 |
Correct |
21 ms |
3924 KB |
Output is correct |
10 |
Correct |
25 ms |
3824 KB |
Output is correct |
11 |
Correct |
23 ms |
3808 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
27 ms |
3816 KB |
Output is correct |
14 |
Correct |
26 ms |
3792 KB |
Output is correct |
15 |
Correct |
28 ms |
3776 KB |
Output is correct |
16 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |