# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
596852 |
2022-07-15T07:41:36 Z |
박상훈(#8446) |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
3424 KB |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n, a[100100], L[100100], R[100100];
ll S[100100];
int dnc(int l, int r, int m, ll need){
ll ok = S[r] - S[l-1];
if (ok < need) return 0;
int ret = 1;
if (l<m) ret += dnc(l, m-1, L[m], a[m]);
if (m<r) ret += dnc(m+1, r, R[m], a[m]);
return ret;
}
int query(int l, int r){
vector<int> st;
for (int i=l;i<=r;i++){
while(!st.empty() && a[st.back()] <= a[i]){
int j = st.back(); st.pop_back();
int tmp = st.empty()?1e9+100:a[st.back()];
if (tmp<=a[i]) R[st.back()] = j;
else L[i] = j;
}
st.push_back(i);
}
int mx = st[0];
while(!st.empty()){
int j = st.back(); st.pop_back();
if (!st.empty()) R[st.back()] = j;
}
return dnc(l, r, mx, 0);
}
void update(int p, int x){
a[p] = x;
for (int i=p;i<=n;i++) S[i] = S[i-1] + a[i];
}
int main(){
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", a+i);
for (int i=1;i<=n;i++) S[i] = S[i-1] + a[i];
int q;
scanf("%d", &q);
while(q--){
int op, x, y;
scanf("%d %d %d", &op, &x, &y);
if (op==1) update(x, y);
else printf("%d\n", query(x, y));
}
return 0;
}
Compilation message
fish2.cpp: In function 'int main()':
fish2.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
fish2.cpp:45:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | for (int i=1;i<=n;i++) scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
fish2.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
fish2.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d %d %d", &op, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
2732 KB |
Output is correct |
3 |
Correct |
10 ms |
2496 KB |
Output is correct |
4 |
Correct |
18 ms |
2704 KB |
Output is correct |
5 |
Correct |
10 ms |
2476 KB |
Output is correct |
6 |
Correct |
17 ms |
3128 KB |
Output is correct |
7 |
Correct |
9 ms |
2388 KB |
Output is correct |
8 |
Correct |
14 ms |
3136 KB |
Output is correct |
9 |
Correct |
9 ms |
2388 KB |
Output is correct |
10 |
Correct |
12 ms |
2772 KB |
Output is correct |
11 |
Correct |
11 ms |
2516 KB |
Output is correct |
12 |
Correct |
10 ms |
2496 KB |
Output is correct |
13 |
Correct |
10 ms |
2496 KB |
Output is correct |
14 |
Correct |
12 ms |
3156 KB |
Output is correct |
15 |
Correct |
13 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
15 ms |
2732 KB |
Output is correct |
23 |
Correct |
10 ms |
2496 KB |
Output is correct |
24 |
Correct |
18 ms |
2704 KB |
Output is correct |
25 |
Correct |
10 ms |
2476 KB |
Output is correct |
26 |
Correct |
17 ms |
3128 KB |
Output is correct |
27 |
Correct |
9 ms |
2388 KB |
Output is correct |
28 |
Correct |
14 ms |
3136 KB |
Output is correct |
29 |
Correct |
9 ms |
2388 KB |
Output is correct |
30 |
Correct |
12 ms |
2772 KB |
Output is correct |
31 |
Correct |
11 ms |
2516 KB |
Output is correct |
32 |
Correct |
10 ms |
2496 KB |
Output is correct |
33 |
Correct |
10 ms |
2496 KB |
Output is correct |
34 |
Correct |
12 ms |
3156 KB |
Output is correct |
35 |
Correct |
13 ms |
3132 KB |
Output is correct |
36 |
Correct |
154 ms |
3020 KB |
Output is correct |
37 |
Correct |
218 ms |
2576 KB |
Output is correct |
38 |
Correct |
165 ms |
2516 KB |
Output is correct |
39 |
Correct |
152 ms |
2960 KB |
Output is correct |
40 |
Correct |
192 ms |
2616 KB |
Output is correct |
41 |
Correct |
489 ms |
3228 KB |
Output is correct |
42 |
Correct |
590 ms |
3424 KB |
Output is correct |
43 |
Correct |
291 ms |
2388 KB |
Output is correct |
44 |
Correct |
324 ms |
2432 KB |
Output is correct |
45 |
Correct |
165 ms |
2812 KB |
Output is correct |
46 |
Correct |
219 ms |
2828 KB |
Output is correct |
47 |
Correct |
212 ms |
2532 KB |
Output is correct |
48 |
Correct |
201 ms |
2504 KB |
Output is correct |
49 |
Correct |
381 ms |
2588 KB |
Output is correct |
50 |
Correct |
292 ms |
3188 KB |
Output is correct |
51 |
Correct |
1033 ms |
3276 KB |
Output is correct |
52 |
Correct |
1057 ms |
3236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
2732 KB |
Output is correct |
3 |
Correct |
10 ms |
2496 KB |
Output is correct |
4 |
Correct |
18 ms |
2704 KB |
Output is correct |
5 |
Correct |
10 ms |
2476 KB |
Output is correct |
6 |
Correct |
17 ms |
3128 KB |
Output is correct |
7 |
Correct |
9 ms |
2388 KB |
Output is correct |
8 |
Correct |
14 ms |
3136 KB |
Output is correct |
9 |
Correct |
9 ms |
2388 KB |
Output is correct |
10 |
Correct |
12 ms |
2772 KB |
Output is correct |
11 |
Correct |
11 ms |
2516 KB |
Output is correct |
12 |
Correct |
10 ms |
2496 KB |
Output is correct |
13 |
Correct |
10 ms |
2496 KB |
Output is correct |
14 |
Correct |
12 ms |
3156 KB |
Output is correct |
15 |
Correct |
13 ms |
3132 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4048 ms |
3304 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
2732 KB |
Output is correct |
3 |
Correct |
10 ms |
2496 KB |
Output is correct |
4 |
Correct |
18 ms |
2704 KB |
Output is correct |
5 |
Correct |
10 ms |
2476 KB |
Output is correct |
6 |
Correct |
17 ms |
3128 KB |
Output is correct |
7 |
Correct |
9 ms |
2388 KB |
Output is correct |
8 |
Correct |
14 ms |
3136 KB |
Output is correct |
9 |
Correct |
9 ms |
2388 KB |
Output is correct |
10 |
Correct |
12 ms |
2772 KB |
Output is correct |
11 |
Correct |
11 ms |
2516 KB |
Output is correct |
12 |
Correct |
10 ms |
2496 KB |
Output is correct |
13 |
Correct |
10 ms |
2496 KB |
Output is correct |
14 |
Correct |
12 ms |
3156 KB |
Output is correct |
15 |
Correct |
13 ms |
3132 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4067 ms |
3128 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
15 ms |
2732 KB |
Output is correct |
23 |
Correct |
10 ms |
2496 KB |
Output is correct |
24 |
Correct |
18 ms |
2704 KB |
Output is correct |
25 |
Correct |
10 ms |
2476 KB |
Output is correct |
26 |
Correct |
17 ms |
3128 KB |
Output is correct |
27 |
Correct |
9 ms |
2388 KB |
Output is correct |
28 |
Correct |
14 ms |
3136 KB |
Output is correct |
29 |
Correct |
9 ms |
2388 KB |
Output is correct |
30 |
Correct |
12 ms |
2772 KB |
Output is correct |
31 |
Correct |
11 ms |
2516 KB |
Output is correct |
32 |
Correct |
10 ms |
2496 KB |
Output is correct |
33 |
Correct |
10 ms |
2496 KB |
Output is correct |
34 |
Correct |
12 ms |
3156 KB |
Output is correct |
35 |
Correct |
13 ms |
3132 KB |
Output is correct |
36 |
Correct |
154 ms |
3020 KB |
Output is correct |
37 |
Correct |
218 ms |
2576 KB |
Output is correct |
38 |
Correct |
165 ms |
2516 KB |
Output is correct |
39 |
Correct |
152 ms |
2960 KB |
Output is correct |
40 |
Correct |
192 ms |
2616 KB |
Output is correct |
41 |
Correct |
489 ms |
3228 KB |
Output is correct |
42 |
Correct |
590 ms |
3424 KB |
Output is correct |
43 |
Correct |
291 ms |
2388 KB |
Output is correct |
44 |
Correct |
324 ms |
2432 KB |
Output is correct |
45 |
Correct |
165 ms |
2812 KB |
Output is correct |
46 |
Correct |
219 ms |
2828 KB |
Output is correct |
47 |
Correct |
212 ms |
2532 KB |
Output is correct |
48 |
Correct |
201 ms |
2504 KB |
Output is correct |
49 |
Correct |
381 ms |
2588 KB |
Output is correct |
50 |
Correct |
292 ms |
3188 KB |
Output is correct |
51 |
Correct |
1033 ms |
3276 KB |
Output is correct |
52 |
Correct |
1057 ms |
3236 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Execution timed out |
4048 ms |
3304 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |