# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
596891 |
2022-07-15T08:48:29 Z |
장태환(#8448) |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4652 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int par[100100];
int lc[100100];
int rc[100100];
int sum[100100];
int arr[100100];
int N;
int dfs(int n)
{
if (n == -1)
return 0;
sum[n] = arr[n];
sum[n] += dfs(lc[n]);
sum[n] += dfs(rc[n]);
return sum[n];
}
int build(int s,int e)
{
memset(par, -1, sizeof(par));
memset(lc, -1, sizeof(lc));
memset(rc, -1, sizeof(rc));
memset(sum,0, sizeof(sum));
int i;
int rt = s;
for (i = s+1; i <=e; i++)
{
int c = i - 1;
while (c!=-1&&arr[c] <= arr[i])
{
c = par[c];
}
if (c != -1)
{
par[rc[c]] = i;
lc[i] = rc[c];
par[i] = c;
rc[c] = i;
}
else
{
par[rt] = i;
lc[i] = rt;
rt = i;
}
}
dfs(rt);
return rt;
}
int calcu(int n)
{
if (n == -1)
return 0;
int ans = 1;
if (lc[n] != -1 && sum[lc[n]] >= arr[n])
{
ans += calcu(lc[n]);
}
if (rc[n] != -1 && sum[rc[n]] >= arr[n])
{
ans += calcu(rc[n]);
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
int i;
for (i = 0; i < N; i++)
{
cin >> arr[i];
}
int Q;
cin >> Q;
while (Q--)
{
int a, b, c;
cin >> a >> b >> c;
if (a == 1)
{
arr[b - 1] = c;
}
else
{
cout << calcu(build(b - 1, c - 1))<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
9 ms |
3472 KB |
Output is correct |
6 |
Correct |
43 ms |
3412 KB |
Output is correct |
7 |
Correct |
10 ms |
3460 KB |
Output is correct |
8 |
Correct |
28 ms |
3412 KB |
Output is correct |
9 |
Correct |
32 ms |
3468 KB |
Output is correct |
10 |
Correct |
13 ms |
3468 KB |
Output is correct |
11 |
Correct |
34 ms |
3412 KB |
Output is correct |
12 |
Correct |
12 ms |
3464 KB |
Output is correct |
13 |
Correct |
32 ms |
3464 KB |
Output is correct |
14 |
Correct |
10 ms |
3412 KB |
Output is correct |
15 |
Correct |
20 ms |
3468 KB |
Output is correct |
16 |
Correct |
45 ms |
3412 KB |
Output is correct |
17 |
Correct |
22 ms |
3412 KB |
Output is correct |
18 |
Correct |
53 ms |
3412 KB |
Output is correct |
19 |
Correct |
17 ms |
3412 KB |
Output is correct |
20 |
Correct |
33 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
10 ms |
4180 KB |
Output is correct |
3 |
Correct |
11 ms |
4236 KB |
Output is correct |
4 |
Correct |
11 ms |
4180 KB |
Output is correct |
5 |
Correct |
10 ms |
4180 KB |
Output is correct |
6 |
Correct |
20 ms |
4164 KB |
Output is correct |
7 |
Correct |
15 ms |
4180 KB |
Output is correct |
8 |
Correct |
15 ms |
4220 KB |
Output is correct |
9 |
Correct |
11 ms |
4228 KB |
Output is correct |
10 |
Correct |
11 ms |
4216 KB |
Output is correct |
11 |
Correct |
8 ms |
4180 KB |
Output is correct |
12 |
Correct |
9 ms |
4204 KB |
Output is correct |
13 |
Correct |
9 ms |
4248 KB |
Output is correct |
14 |
Correct |
11 ms |
4436 KB |
Output is correct |
15 |
Correct |
16 ms |
4500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
9 ms |
3472 KB |
Output is correct |
6 |
Correct |
43 ms |
3412 KB |
Output is correct |
7 |
Correct |
10 ms |
3460 KB |
Output is correct |
8 |
Correct |
28 ms |
3412 KB |
Output is correct |
9 |
Correct |
32 ms |
3468 KB |
Output is correct |
10 |
Correct |
13 ms |
3468 KB |
Output is correct |
11 |
Correct |
34 ms |
3412 KB |
Output is correct |
12 |
Correct |
12 ms |
3464 KB |
Output is correct |
13 |
Correct |
32 ms |
3464 KB |
Output is correct |
14 |
Correct |
10 ms |
3412 KB |
Output is correct |
15 |
Correct |
20 ms |
3468 KB |
Output is correct |
16 |
Correct |
45 ms |
3412 KB |
Output is correct |
17 |
Correct |
22 ms |
3412 KB |
Output is correct |
18 |
Correct |
53 ms |
3412 KB |
Output is correct |
19 |
Correct |
17 ms |
3412 KB |
Output is correct |
20 |
Correct |
33 ms |
3412 KB |
Output is correct |
21 |
Correct |
1 ms |
3412 KB |
Output is correct |
22 |
Correct |
10 ms |
4180 KB |
Output is correct |
23 |
Correct |
11 ms |
4236 KB |
Output is correct |
24 |
Correct |
11 ms |
4180 KB |
Output is correct |
25 |
Correct |
10 ms |
4180 KB |
Output is correct |
26 |
Correct |
20 ms |
4164 KB |
Output is correct |
27 |
Correct |
15 ms |
4180 KB |
Output is correct |
28 |
Correct |
15 ms |
4220 KB |
Output is correct |
29 |
Correct |
11 ms |
4228 KB |
Output is correct |
30 |
Correct |
11 ms |
4216 KB |
Output is correct |
31 |
Correct |
8 ms |
4180 KB |
Output is correct |
32 |
Correct |
9 ms |
4204 KB |
Output is correct |
33 |
Correct |
9 ms |
4248 KB |
Output is correct |
34 |
Correct |
11 ms |
4436 KB |
Output is correct |
35 |
Correct |
16 ms |
4500 KB |
Output is correct |
36 |
Correct |
227 ms |
4372 KB |
Output is correct |
37 |
Correct |
407 ms |
4216 KB |
Output is correct |
38 |
Correct |
431 ms |
4180 KB |
Output is correct |
39 |
Correct |
119 ms |
4308 KB |
Output is correct |
40 |
Correct |
475 ms |
4224 KB |
Output is correct |
41 |
Correct |
779 ms |
4228 KB |
Output is correct |
42 |
Correct |
962 ms |
4224 KB |
Output is correct |
43 |
Correct |
567 ms |
4220 KB |
Output is correct |
44 |
Correct |
671 ms |
4220 KB |
Output is correct |
45 |
Correct |
325 ms |
4248 KB |
Output is correct |
46 |
Correct |
424 ms |
4352 KB |
Output is correct |
47 |
Correct |
521 ms |
4220 KB |
Output is correct |
48 |
Correct |
231 ms |
4244 KB |
Output is correct |
49 |
Correct |
739 ms |
4388 KB |
Output is correct |
50 |
Correct |
425 ms |
4508 KB |
Output is correct |
51 |
Correct |
1654 ms |
4652 KB |
Output is correct |
52 |
Correct |
1787 ms |
4520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
10 ms |
4180 KB |
Output is correct |
3 |
Correct |
11 ms |
4236 KB |
Output is correct |
4 |
Correct |
11 ms |
4180 KB |
Output is correct |
5 |
Correct |
10 ms |
4180 KB |
Output is correct |
6 |
Correct |
20 ms |
4164 KB |
Output is correct |
7 |
Correct |
15 ms |
4180 KB |
Output is correct |
8 |
Correct |
15 ms |
4220 KB |
Output is correct |
9 |
Correct |
11 ms |
4228 KB |
Output is correct |
10 |
Correct |
11 ms |
4216 KB |
Output is correct |
11 |
Correct |
8 ms |
4180 KB |
Output is correct |
12 |
Correct |
9 ms |
4204 KB |
Output is correct |
13 |
Correct |
9 ms |
4248 KB |
Output is correct |
14 |
Correct |
11 ms |
4436 KB |
Output is correct |
15 |
Correct |
16 ms |
4500 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Execution timed out |
4094 ms |
4220 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
10 ms |
4180 KB |
Output is correct |
3 |
Correct |
11 ms |
4236 KB |
Output is correct |
4 |
Correct |
11 ms |
4180 KB |
Output is correct |
5 |
Correct |
10 ms |
4180 KB |
Output is correct |
6 |
Correct |
20 ms |
4164 KB |
Output is correct |
7 |
Correct |
15 ms |
4180 KB |
Output is correct |
8 |
Correct |
15 ms |
4220 KB |
Output is correct |
9 |
Correct |
11 ms |
4228 KB |
Output is correct |
10 |
Correct |
11 ms |
4216 KB |
Output is correct |
11 |
Correct |
8 ms |
4180 KB |
Output is correct |
12 |
Correct |
9 ms |
4204 KB |
Output is correct |
13 |
Correct |
9 ms |
4248 KB |
Output is correct |
14 |
Correct |
11 ms |
4436 KB |
Output is correct |
15 |
Correct |
16 ms |
4500 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Execution timed out |
4096 ms |
4348 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
9 ms |
3472 KB |
Output is correct |
6 |
Correct |
43 ms |
3412 KB |
Output is correct |
7 |
Correct |
10 ms |
3460 KB |
Output is correct |
8 |
Correct |
28 ms |
3412 KB |
Output is correct |
9 |
Correct |
32 ms |
3468 KB |
Output is correct |
10 |
Correct |
13 ms |
3468 KB |
Output is correct |
11 |
Correct |
34 ms |
3412 KB |
Output is correct |
12 |
Correct |
12 ms |
3464 KB |
Output is correct |
13 |
Correct |
32 ms |
3464 KB |
Output is correct |
14 |
Correct |
10 ms |
3412 KB |
Output is correct |
15 |
Correct |
20 ms |
3468 KB |
Output is correct |
16 |
Correct |
45 ms |
3412 KB |
Output is correct |
17 |
Correct |
22 ms |
3412 KB |
Output is correct |
18 |
Correct |
53 ms |
3412 KB |
Output is correct |
19 |
Correct |
17 ms |
3412 KB |
Output is correct |
20 |
Correct |
33 ms |
3412 KB |
Output is correct |
21 |
Correct |
1 ms |
3412 KB |
Output is correct |
22 |
Correct |
10 ms |
4180 KB |
Output is correct |
23 |
Correct |
11 ms |
4236 KB |
Output is correct |
24 |
Correct |
11 ms |
4180 KB |
Output is correct |
25 |
Correct |
10 ms |
4180 KB |
Output is correct |
26 |
Correct |
20 ms |
4164 KB |
Output is correct |
27 |
Correct |
15 ms |
4180 KB |
Output is correct |
28 |
Correct |
15 ms |
4220 KB |
Output is correct |
29 |
Correct |
11 ms |
4228 KB |
Output is correct |
30 |
Correct |
11 ms |
4216 KB |
Output is correct |
31 |
Correct |
8 ms |
4180 KB |
Output is correct |
32 |
Correct |
9 ms |
4204 KB |
Output is correct |
33 |
Correct |
9 ms |
4248 KB |
Output is correct |
34 |
Correct |
11 ms |
4436 KB |
Output is correct |
35 |
Correct |
16 ms |
4500 KB |
Output is correct |
36 |
Correct |
227 ms |
4372 KB |
Output is correct |
37 |
Correct |
407 ms |
4216 KB |
Output is correct |
38 |
Correct |
431 ms |
4180 KB |
Output is correct |
39 |
Correct |
119 ms |
4308 KB |
Output is correct |
40 |
Correct |
475 ms |
4224 KB |
Output is correct |
41 |
Correct |
779 ms |
4228 KB |
Output is correct |
42 |
Correct |
962 ms |
4224 KB |
Output is correct |
43 |
Correct |
567 ms |
4220 KB |
Output is correct |
44 |
Correct |
671 ms |
4220 KB |
Output is correct |
45 |
Correct |
325 ms |
4248 KB |
Output is correct |
46 |
Correct |
424 ms |
4352 KB |
Output is correct |
47 |
Correct |
521 ms |
4220 KB |
Output is correct |
48 |
Correct |
231 ms |
4244 KB |
Output is correct |
49 |
Correct |
739 ms |
4388 KB |
Output is correct |
50 |
Correct |
425 ms |
4508 KB |
Output is correct |
51 |
Correct |
1654 ms |
4652 KB |
Output is correct |
52 |
Correct |
1787 ms |
4520 KB |
Output is correct |
53 |
Correct |
3 ms |
3412 KB |
Output is correct |
54 |
Execution timed out |
4094 ms |
4220 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |