# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
818630 |
2023-08-10T05:53:26 Z |
반딧불(#10131) |
Fish 2 (JOI22_fish2) |
C++17 |
|
29 ms |
3932 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 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[100002];
ll sum[100002];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(int i=1; i<=n; 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, x, y;
scanf("%d %d %d", &t, &x, &y);
printf("%d\n", n - tree.query(1, 1, n, 1, n));
}
}
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, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 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 |
3788 KB |
Output is correct |
3 |
Correct |
28 ms |
3896 KB |
Output is correct |
4 |
Correct |
29 ms |
3836 KB |
Output is correct |
5 |
Correct |
27 ms |
3860 KB |
Output is correct |
6 |
Correct |
25 ms |
3728 KB |
Output is correct |
7 |
Correct |
22 ms |
3904 KB |
Output is correct |
8 |
Correct |
25 ms |
3776 KB |
Output is correct |
9 |
Correct |
21 ms |
3844 KB |
Output is correct |
10 |
Correct |
26 ms |
3812 KB |
Output is correct |
11 |
Correct |
24 ms |
3880 KB |
Output is correct |
12 |
Correct |
23 ms |
3932 KB |
Output is correct |
13 |
Correct |
22 ms |
3788 KB |
Output is correct |
14 |
Correct |
26 ms |
3780 KB |
Output is correct |
15 |
Correct |
27 ms |
3848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 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 |
3788 KB |
Output is correct |
3 |
Correct |
28 ms |
3896 KB |
Output is correct |
4 |
Correct |
29 ms |
3836 KB |
Output is correct |
5 |
Correct |
27 ms |
3860 KB |
Output is correct |
6 |
Correct |
25 ms |
3728 KB |
Output is correct |
7 |
Correct |
22 ms |
3904 KB |
Output is correct |
8 |
Correct |
25 ms |
3776 KB |
Output is correct |
9 |
Correct |
21 ms |
3844 KB |
Output is correct |
10 |
Correct |
26 ms |
3812 KB |
Output is correct |
11 |
Correct |
24 ms |
3880 KB |
Output is correct |
12 |
Correct |
23 ms |
3932 KB |
Output is correct |
13 |
Correct |
22 ms |
3788 KB |
Output is correct |
14 |
Correct |
26 ms |
3780 KB |
Output is correct |
15 |
Correct |
27 ms |
3848 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 |
28 ms |
3788 KB |
Output is correct |
3 |
Correct |
28 ms |
3896 KB |
Output is correct |
4 |
Correct |
29 ms |
3836 KB |
Output is correct |
5 |
Correct |
27 ms |
3860 KB |
Output is correct |
6 |
Correct |
25 ms |
3728 KB |
Output is correct |
7 |
Correct |
22 ms |
3904 KB |
Output is correct |
8 |
Correct |
25 ms |
3776 KB |
Output is correct |
9 |
Correct |
21 ms |
3844 KB |
Output is correct |
10 |
Correct |
26 ms |
3812 KB |
Output is correct |
11 |
Correct |
24 ms |
3880 KB |
Output is correct |
12 |
Correct |
23 ms |
3932 KB |
Output is correct |
13 |
Correct |
22 ms |
3788 KB |
Output is correct |
14 |
Correct |
26 ms |
3780 KB |
Output is correct |
15 |
Correct |
27 ms |
3848 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |