# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
963903 |
2024-04-16T02:36:13 Z |
Pring |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4604 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 100005;
int n, m, t, x, y;
ll a[MXN];
int L[MXN], R[MXN], hl[MXN], hr[MXN];
struct BIT {
ll p[MXN];
void init(int n, ll *a) {
p[0] = 0;
FOR(i, 1, n + 1) p[i] = p[i - 1] + a[i];
}
ll query(int l, int r) {
return p[r] - p[l - 1];
}
} B;
void MODIFY(int p, int v) {
a[p] = v;
B.init(n, a);
}
void BUILD(int l, int r) {
vector<pii> st;
{
st.push_back(mp(INT_MAX, -1));
FOR(i, l, r) {
L[i] = -1;
while (st.back().fs <= a[i]) {
L[i] = st.back().sc;
st.pop_back();
}
st.push_back(mp(a[i], i));
}
st.clear();
}
{
st.push_back(mp(INT_MAX, -1));
for (int i = r - 1; i >= l; i--) {
R[i] = -1;
while (st.back().fs < a[i]) {
R[i] = st.back().sc;
st.pop_back();
}
st.push_back(mp(a[i], i));
}
st.clear();
}
{
st.push_back(mp(INT_MAX, l - 1));
FOR(i, l, r) {
while (st.back().fs <= a[i]) st.pop_back();
hl[i] = st.back().sc;
st.push_back(mp(a[i], i));
}
st.clear();
}
{
st.push_back(mp(INT_MAX, r));
for (int i = r - 1; i >= l; i--) {
while (st.back().fs < a[i]) st.pop_back();
hr[i] = st.back().sc;
st.push_back(mp(a[i], i));
}
st.clear();
}
}
void DFS(int id, int bnd, int &ans) {
if (id == -1) return;
debug(id);
if (B.query(hl[id] + 1, hr[id] - 1) < bnd) return;
ans++;
DFS(L[id], a[id], ans);
DFS(R[id], a[id], ans);
}
int MAX_ID(int l, int r) {
int id = l;
FOR(i, l + 1, r) if (a[i] >= a[id]) id = i;
return id;
}
int QUERY(int l, int r) {
BUILD(l, r);
int rt = MAX_ID(l, r);
int ans = 0;
DFS(rt, 0, ans);
return ans;
}
void miku() {
cin >> n;
FOR(i, 1, n + 1) cin >> a[i];
B.init(n, a);
cin >> m;
while (m--) {
cin >> t >> x >> y;
if (t == 1) MODIFY(x, y);
else cout << QUERY(x, y + 1) << '\n';
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message
fish2.cpp: In function 'void DFS(int, int, int&)':
fish2.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
fish2.cpp:90:5: note: in expansion of macro 'debug'
90 | debug(id);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2540 KB |
Output is correct |
9 |
Correct |
4 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2524 KB |
Output is correct |
11 |
Correct |
4 ms |
2544 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
4 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2520 KB |
Output is correct |
20 |
Correct |
8 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
11 ms |
3496 KB |
Output is correct |
3 |
Correct |
13 ms |
3680 KB |
Output is correct |
4 |
Correct |
11 ms |
3928 KB |
Output is correct |
5 |
Correct |
11 ms |
3932 KB |
Output is correct |
6 |
Correct |
20 ms |
4448 KB |
Output is correct |
7 |
Correct |
11 ms |
3672 KB |
Output is correct |
8 |
Correct |
15 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3672 KB |
Output is correct |
10 |
Correct |
14 ms |
3932 KB |
Output is correct |
11 |
Correct |
9 ms |
3676 KB |
Output is correct |
12 |
Correct |
10 ms |
3672 KB |
Output is correct |
13 |
Correct |
10 ms |
3676 KB |
Output is correct |
14 |
Correct |
11 ms |
4444 KB |
Output is correct |
15 |
Correct |
13 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2540 KB |
Output is correct |
9 |
Correct |
4 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2524 KB |
Output is correct |
11 |
Correct |
4 ms |
2544 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
4 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2520 KB |
Output is correct |
20 |
Correct |
8 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
11 ms |
3496 KB |
Output is correct |
23 |
Correct |
13 ms |
3680 KB |
Output is correct |
24 |
Correct |
11 ms |
3928 KB |
Output is correct |
25 |
Correct |
11 ms |
3932 KB |
Output is correct |
26 |
Correct |
20 ms |
4448 KB |
Output is correct |
27 |
Correct |
11 ms |
3672 KB |
Output is correct |
28 |
Correct |
15 ms |
4444 KB |
Output is correct |
29 |
Correct |
12 ms |
3672 KB |
Output is correct |
30 |
Correct |
14 ms |
3932 KB |
Output is correct |
31 |
Correct |
9 ms |
3676 KB |
Output is correct |
32 |
Correct |
10 ms |
3672 KB |
Output is correct |
33 |
Correct |
10 ms |
3676 KB |
Output is correct |
34 |
Correct |
11 ms |
4444 KB |
Output is correct |
35 |
Correct |
13 ms |
4556 KB |
Output is correct |
36 |
Correct |
640 ms |
4364 KB |
Output is correct |
37 |
Correct |
948 ms |
3932 KB |
Output is correct |
38 |
Correct |
1079 ms |
3928 KB |
Output is correct |
39 |
Correct |
290 ms |
4188 KB |
Output is correct |
40 |
Correct |
1189 ms |
3924 KB |
Output is correct |
41 |
Correct |
1338 ms |
4552 KB |
Output is correct |
42 |
Correct |
1694 ms |
4556 KB |
Output is correct |
43 |
Correct |
1200 ms |
3788 KB |
Output is correct |
44 |
Correct |
1409 ms |
3788 KB |
Output is correct |
45 |
Correct |
679 ms |
4176 KB |
Output is correct |
46 |
Correct |
901 ms |
4180 KB |
Output is correct |
47 |
Correct |
1325 ms |
3860 KB |
Output is correct |
48 |
Correct |
475 ms |
3868 KB |
Output is correct |
49 |
Correct |
1474 ms |
3928 KB |
Output is correct |
50 |
Correct |
786 ms |
4596 KB |
Output is correct |
51 |
Correct |
3389 ms |
4604 KB |
Output is correct |
52 |
Correct |
3727 ms |
4596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
11 ms |
3496 KB |
Output is correct |
3 |
Correct |
13 ms |
3680 KB |
Output is correct |
4 |
Correct |
11 ms |
3928 KB |
Output is correct |
5 |
Correct |
11 ms |
3932 KB |
Output is correct |
6 |
Correct |
20 ms |
4448 KB |
Output is correct |
7 |
Correct |
11 ms |
3672 KB |
Output is correct |
8 |
Correct |
15 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3672 KB |
Output is correct |
10 |
Correct |
14 ms |
3932 KB |
Output is correct |
11 |
Correct |
9 ms |
3676 KB |
Output is correct |
12 |
Correct |
10 ms |
3672 KB |
Output is correct |
13 |
Correct |
10 ms |
3676 KB |
Output is correct |
14 |
Correct |
11 ms |
4444 KB |
Output is correct |
15 |
Correct |
13 ms |
4556 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Execution timed out |
4003 ms |
4064 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
11 ms |
3496 KB |
Output is correct |
3 |
Correct |
13 ms |
3680 KB |
Output is correct |
4 |
Correct |
11 ms |
3928 KB |
Output is correct |
5 |
Correct |
11 ms |
3932 KB |
Output is correct |
6 |
Correct |
20 ms |
4448 KB |
Output is correct |
7 |
Correct |
11 ms |
3672 KB |
Output is correct |
8 |
Correct |
15 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3672 KB |
Output is correct |
10 |
Correct |
14 ms |
3932 KB |
Output is correct |
11 |
Correct |
9 ms |
3676 KB |
Output is correct |
12 |
Correct |
10 ms |
3672 KB |
Output is correct |
13 |
Correct |
10 ms |
3676 KB |
Output is correct |
14 |
Correct |
11 ms |
4444 KB |
Output is correct |
15 |
Correct |
13 ms |
4556 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Execution timed out |
4069 ms |
4324 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2540 KB |
Output is correct |
9 |
Correct |
4 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2524 KB |
Output is correct |
11 |
Correct |
4 ms |
2544 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
4 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2520 KB |
Output is correct |
20 |
Correct |
8 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
11 ms |
3496 KB |
Output is correct |
23 |
Correct |
13 ms |
3680 KB |
Output is correct |
24 |
Correct |
11 ms |
3928 KB |
Output is correct |
25 |
Correct |
11 ms |
3932 KB |
Output is correct |
26 |
Correct |
20 ms |
4448 KB |
Output is correct |
27 |
Correct |
11 ms |
3672 KB |
Output is correct |
28 |
Correct |
15 ms |
4444 KB |
Output is correct |
29 |
Correct |
12 ms |
3672 KB |
Output is correct |
30 |
Correct |
14 ms |
3932 KB |
Output is correct |
31 |
Correct |
9 ms |
3676 KB |
Output is correct |
32 |
Correct |
10 ms |
3672 KB |
Output is correct |
33 |
Correct |
10 ms |
3676 KB |
Output is correct |
34 |
Correct |
11 ms |
4444 KB |
Output is correct |
35 |
Correct |
13 ms |
4556 KB |
Output is correct |
36 |
Correct |
640 ms |
4364 KB |
Output is correct |
37 |
Correct |
948 ms |
3932 KB |
Output is correct |
38 |
Correct |
1079 ms |
3928 KB |
Output is correct |
39 |
Correct |
290 ms |
4188 KB |
Output is correct |
40 |
Correct |
1189 ms |
3924 KB |
Output is correct |
41 |
Correct |
1338 ms |
4552 KB |
Output is correct |
42 |
Correct |
1694 ms |
4556 KB |
Output is correct |
43 |
Correct |
1200 ms |
3788 KB |
Output is correct |
44 |
Correct |
1409 ms |
3788 KB |
Output is correct |
45 |
Correct |
679 ms |
4176 KB |
Output is correct |
46 |
Correct |
901 ms |
4180 KB |
Output is correct |
47 |
Correct |
1325 ms |
3860 KB |
Output is correct |
48 |
Correct |
475 ms |
3868 KB |
Output is correct |
49 |
Correct |
1474 ms |
3928 KB |
Output is correct |
50 |
Correct |
786 ms |
4596 KB |
Output is correct |
51 |
Correct |
3389 ms |
4604 KB |
Output is correct |
52 |
Correct |
3727 ms |
4596 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Execution timed out |
4003 ms |
4064 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |