# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
876302 |
2023-11-21T14:03:54 Z |
danikoynov |
Fish 2 (JOI22_fish2) |
C++14 |
|
4000 ms |
5008 KB |
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, q;
ll a[maxn], pref[maxn];
void input()
{
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
cin >> q;
a[0] = 1e9 + 10;
a[n + 1] = 1e9 + 10;
}
vector < pair < int, int > > ranges;
void get_ranges()
{
for (int i = 1; i <= n; i ++)
pref[i] = pref[i - 1] + a[i];
pref[n + 1] = pref[n];
ranges.clear();
stack < int > st;
st.push(0);
for (int i = 1; i <= n; i ++)
{
while(!st.empty() && a[st.top()] < a[i])
st.pop();
if (pref[i - 1] - pref[st.top()] < a[i])
ranges.push_back({st.top() + 1, i - 1});
st.push(i);
}
while(!st.empty())
st.pop();
st.push(n + 1);
for (int i = n; i > 0; i --)
{
while(!st.empty() && a[st.top()] < a[i])
st.pop();
if (pref[st.top() - 1] - pref[i] < a[i])
ranges.push_back({i + 1, st.top() - 1});
st.push(i);
}
}
int b[maxn];
void solve_query(int left, int right)
{
//for (pair < int, int > cur : ranges)
// cout << cur.first << " : " << cur.second << endl;
int lb = left, rb = right;
for (int i = left; i <= right; i ++)
{
if (a[i] > pref[i - 1] - pref[left - 1])
lb = max(lb, i);
if (a[i] > pref[right] - pref[i])
rb = min(rb, i);
}
int minx = 1e9;
for (int i = lb; i <= rb; i ++)
minx = min(minx, b[i]);
int ans = 0;
for (int i = lb; i <= rb; i ++)
if (b[i] == minx)
ans ++;
cout << ans << endl;
}
void simulate()
{
get_ranges();
for (int i = 1; i <= n; i ++)
b[i] = 0;
for (pair < int, int > cur : ranges)
for (int i = cur.first; i <= cur.second; i ++)
b[i] ++;
for (int i = 1; i <= q; i ++)
{
int type;
cin >> type;
if (type == 1)
{
int idx;
ll x;
cin >> idx >> x;
a[idx] = x;
get_ranges();
for (int i = 1; i <= n; i ++)
b[i] = 0;
for (pair < int, int > cur : ranges)
for (int i = cur.first; i <= cur.second; i ++)
b[i] ++;
}
else
{
int l, r;
cin >> l >> r;
solve_query(l, r);
}
}
}
void solve()
{
input();
simulate();
}
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
speed();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
4056 KB |
Output is correct |
3 |
Correct |
11 ms |
4104 KB |
Output is correct |
4 |
Correct |
12 ms |
4176 KB |
Output is correct |
5 |
Correct |
10 ms |
4056 KB |
Output is correct |
6 |
Correct |
13 ms |
4308 KB |
Output is correct |
7 |
Correct |
11 ms |
4056 KB |
Output is correct |
8 |
Correct |
15 ms |
4004 KB |
Output is correct |
9 |
Correct |
10 ms |
4060 KB |
Output is correct |
10 |
Correct |
12 ms |
4080 KB |
Output is correct |
11 |
Correct |
10 ms |
4056 KB |
Output is correct |
12 |
Correct |
11 ms |
4068 KB |
Output is correct |
13 |
Correct |
10 ms |
4068 KB |
Output is correct |
14 |
Correct |
10 ms |
4064 KB |
Output is correct |
15 |
Correct |
12 ms |
4060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
12 ms |
4056 KB |
Output is correct |
23 |
Correct |
11 ms |
4104 KB |
Output is correct |
24 |
Correct |
12 ms |
4176 KB |
Output is correct |
25 |
Correct |
10 ms |
4056 KB |
Output is correct |
26 |
Correct |
13 ms |
4308 KB |
Output is correct |
27 |
Correct |
11 ms |
4056 KB |
Output is correct |
28 |
Correct |
15 ms |
4004 KB |
Output is correct |
29 |
Correct |
10 ms |
4060 KB |
Output is correct |
30 |
Correct |
12 ms |
4080 KB |
Output is correct |
31 |
Correct |
10 ms |
4056 KB |
Output is correct |
32 |
Correct |
11 ms |
4068 KB |
Output is correct |
33 |
Correct |
10 ms |
4068 KB |
Output is correct |
34 |
Correct |
10 ms |
4064 KB |
Output is correct |
35 |
Correct |
12 ms |
4060 KB |
Output is correct |
36 |
Correct |
1472 ms |
4108 KB |
Output is correct |
37 |
Correct |
1008 ms |
4056 KB |
Output is correct |
38 |
Correct |
255 ms |
4056 KB |
Output is correct |
39 |
Correct |
2151 ms |
4056 KB |
Output is correct |
40 |
Correct |
238 ms |
4056 KB |
Output is correct |
41 |
Correct |
1147 ms |
4056 KB |
Output is correct |
42 |
Correct |
483 ms |
4056 KB |
Output is correct |
43 |
Correct |
1085 ms |
4388 KB |
Output is correct |
44 |
Correct |
403 ms |
4052 KB |
Output is correct |
45 |
Correct |
1488 ms |
4104 KB |
Output is correct |
46 |
Correct |
937 ms |
4196 KB |
Output is correct |
47 |
Correct |
235 ms |
4056 KB |
Output is correct |
48 |
Correct |
2479 ms |
4056 KB |
Output is correct |
49 |
Correct |
408 ms |
4056 KB |
Output is correct |
50 |
Correct |
1328 ms |
4060 KB |
Output is correct |
51 |
Correct |
1235 ms |
4060 KB |
Output is correct |
52 |
Correct |
360 ms |
4056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
4056 KB |
Output is correct |
3 |
Correct |
11 ms |
4104 KB |
Output is correct |
4 |
Correct |
12 ms |
4176 KB |
Output is correct |
5 |
Correct |
10 ms |
4056 KB |
Output is correct |
6 |
Correct |
13 ms |
4308 KB |
Output is correct |
7 |
Correct |
11 ms |
4056 KB |
Output is correct |
8 |
Correct |
15 ms |
4004 KB |
Output is correct |
9 |
Correct |
10 ms |
4060 KB |
Output is correct |
10 |
Correct |
12 ms |
4080 KB |
Output is correct |
11 |
Correct |
10 ms |
4056 KB |
Output is correct |
12 |
Correct |
11 ms |
4068 KB |
Output is correct |
13 |
Correct |
10 ms |
4068 KB |
Output is correct |
14 |
Correct |
10 ms |
4064 KB |
Output is correct |
15 |
Correct |
12 ms |
4060 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4080 ms |
5008 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
4056 KB |
Output is correct |
3 |
Correct |
11 ms |
4104 KB |
Output is correct |
4 |
Correct |
12 ms |
4176 KB |
Output is correct |
5 |
Correct |
10 ms |
4056 KB |
Output is correct |
6 |
Correct |
13 ms |
4308 KB |
Output is correct |
7 |
Correct |
11 ms |
4056 KB |
Output is correct |
8 |
Correct |
15 ms |
4004 KB |
Output is correct |
9 |
Correct |
10 ms |
4060 KB |
Output is correct |
10 |
Correct |
12 ms |
4080 KB |
Output is correct |
11 |
Correct |
10 ms |
4056 KB |
Output is correct |
12 |
Correct |
11 ms |
4068 KB |
Output is correct |
13 |
Correct |
10 ms |
4068 KB |
Output is correct |
14 |
Correct |
10 ms |
4064 KB |
Output is correct |
15 |
Correct |
12 ms |
4060 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4077 ms |
4056 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
12 ms |
4056 KB |
Output is correct |
23 |
Correct |
11 ms |
4104 KB |
Output is correct |
24 |
Correct |
12 ms |
4176 KB |
Output is correct |
25 |
Correct |
10 ms |
4056 KB |
Output is correct |
26 |
Correct |
13 ms |
4308 KB |
Output is correct |
27 |
Correct |
11 ms |
4056 KB |
Output is correct |
28 |
Correct |
15 ms |
4004 KB |
Output is correct |
29 |
Correct |
10 ms |
4060 KB |
Output is correct |
30 |
Correct |
12 ms |
4080 KB |
Output is correct |
31 |
Correct |
10 ms |
4056 KB |
Output is correct |
32 |
Correct |
11 ms |
4068 KB |
Output is correct |
33 |
Correct |
10 ms |
4068 KB |
Output is correct |
34 |
Correct |
10 ms |
4064 KB |
Output is correct |
35 |
Correct |
12 ms |
4060 KB |
Output is correct |
36 |
Correct |
1472 ms |
4108 KB |
Output is correct |
37 |
Correct |
1008 ms |
4056 KB |
Output is correct |
38 |
Correct |
255 ms |
4056 KB |
Output is correct |
39 |
Correct |
2151 ms |
4056 KB |
Output is correct |
40 |
Correct |
238 ms |
4056 KB |
Output is correct |
41 |
Correct |
1147 ms |
4056 KB |
Output is correct |
42 |
Correct |
483 ms |
4056 KB |
Output is correct |
43 |
Correct |
1085 ms |
4388 KB |
Output is correct |
44 |
Correct |
403 ms |
4052 KB |
Output is correct |
45 |
Correct |
1488 ms |
4104 KB |
Output is correct |
46 |
Correct |
937 ms |
4196 KB |
Output is correct |
47 |
Correct |
235 ms |
4056 KB |
Output is correct |
48 |
Correct |
2479 ms |
4056 KB |
Output is correct |
49 |
Correct |
408 ms |
4056 KB |
Output is correct |
50 |
Correct |
1328 ms |
4060 KB |
Output is correct |
51 |
Correct |
1235 ms |
4060 KB |
Output is correct |
52 |
Correct |
360 ms |
4056 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Execution timed out |
4080 ms |
5008 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |