# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
963900 |
2024-04-16T02:30:10 Z |
Pring |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4808 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 {
int n;
ll val[MXN];
void modify(int id, int v) {
for (; id <= n; id += (id & -id)) val[id] += v;
}
ll query(int id) {
ll ans = 0;
for (; id > 0; id -= (id & -id)) ans += val[id];
return ans;
}
ll query(int l, int r) {
return query(r) - query(l - 1);
}
void init(int _n, ll *a) {
n = _n;
fill(val + 1, val + n + 1, 0);
FOR(i, 1, n + 1) modify(i, a[i]);
}
} B;
void MODIFY(int p, int v) {
B.modify(p, v - a[p]);
a[p] = v;
}
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);
// BUILD(1, n + 1);
// FOR(i, 1, n + 1) debug(i, L[i], R[i], hl[i], hr[i]);
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:100:5: note: in expansion of macro 'debug'
100 | debug(id);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
3936 KB |
Output is correct |
3 |
Correct |
11 ms |
3680 KB |
Output is correct |
4 |
Correct |
14 ms |
3932 KB |
Output is correct |
5 |
Correct |
11 ms |
3912 KB |
Output is correct |
6 |
Correct |
20 ms |
4312 KB |
Output is correct |
7 |
Correct |
11 ms |
3676 KB |
Output is correct |
8 |
Correct |
17 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3676 KB |
Output is correct |
10 |
Correct |
12 ms |
4184 KB |
Output is correct |
11 |
Correct |
12 ms |
3676 KB |
Output is correct |
12 |
Correct |
11 ms |
3676 KB |
Output is correct |
13 |
Correct |
11 ms |
3676 KB |
Output is correct |
14 |
Correct |
14 ms |
4444 KB |
Output is correct |
15 |
Correct |
15 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
14 ms |
3936 KB |
Output is correct |
23 |
Correct |
11 ms |
3680 KB |
Output is correct |
24 |
Correct |
14 ms |
3932 KB |
Output is correct |
25 |
Correct |
11 ms |
3912 KB |
Output is correct |
26 |
Correct |
20 ms |
4312 KB |
Output is correct |
27 |
Correct |
11 ms |
3676 KB |
Output is correct |
28 |
Correct |
17 ms |
4444 KB |
Output is correct |
29 |
Correct |
12 ms |
3676 KB |
Output is correct |
30 |
Correct |
12 ms |
4184 KB |
Output is correct |
31 |
Correct |
12 ms |
3676 KB |
Output is correct |
32 |
Correct |
11 ms |
3676 KB |
Output is correct |
33 |
Correct |
11 ms |
3676 KB |
Output is correct |
34 |
Correct |
14 ms |
4444 KB |
Output is correct |
35 |
Correct |
15 ms |
4444 KB |
Output is correct |
36 |
Correct |
631 ms |
4368 KB |
Output is correct |
37 |
Correct |
940 ms |
3924 KB |
Output is correct |
38 |
Correct |
1076 ms |
4164 KB |
Output is correct |
39 |
Correct |
260 ms |
4440 KB |
Output is correct |
40 |
Correct |
1184 ms |
4176 KB |
Output is correct |
41 |
Correct |
1690 ms |
4556 KB |
Output is correct |
42 |
Correct |
2199 ms |
4808 KB |
Output is correct |
43 |
Correct |
1180 ms |
3788 KB |
Output is correct |
44 |
Correct |
1416 ms |
3788 KB |
Output is correct |
45 |
Correct |
686 ms |
4188 KB |
Output is correct |
46 |
Correct |
942 ms |
4160 KB |
Output is correct |
47 |
Correct |
1320 ms |
3868 KB |
Output is correct |
48 |
Correct |
438 ms |
3932 KB |
Output is correct |
49 |
Correct |
1476 ms |
3936 KB |
Output is correct |
50 |
Correct |
959 ms |
4600 KB |
Output is correct |
51 |
Execution timed out |
4021 ms |
4600 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
3936 KB |
Output is correct |
3 |
Correct |
11 ms |
3680 KB |
Output is correct |
4 |
Correct |
14 ms |
3932 KB |
Output is correct |
5 |
Correct |
11 ms |
3912 KB |
Output is correct |
6 |
Correct |
20 ms |
4312 KB |
Output is correct |
7 |
Correct |
11 ms |
3676 KB |
Output is correct |
8 |
Correct |
17 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3676 KB |
Output is correct |
10 |
Correct |
12 ms |
4184 KB |
Output is correct |
11 |
Correct |
12 ms |
3676 KB |
Output is correct |
12 |
Correct |
11 ms |
3676 KB |
Output is correct |
13 |
Correct |
11 ms |
3676 KB |
Output is correct |
14 |
Correct |
14 ms |
4444 KB |
Output is correct |
15 |
Correct |
15 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4050 ms |
4080 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
3936 KB |
Output is correct |
3 |
Correct |
11 ms |
3680 KB |
Output is correct |
4 |
Correct |
14 ms |
3932 KB |
Output is correct |
5 |
Correct |
11 ms |
3912 KB |
Output is correct |
6 |
Correct |
20 ms |
4312 KB |
Output is correct |
7 |
Correct |
11 ms |
3676 KB |
Output is correct |
8 |
Correct |
17 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
3676 KB |
Output is correct |
10 |
Correct |
12 ms |
4184 KB |
Output is correct |
11 |
Correct |
12 ms |
3676 KB |
Output is correct |
12 |
Correct |
11 ms |
3676 KB |
Output is correct |
13 |
Correct |
11 ms |
3676 KB |
Output is correct |
14 |
Correct |
14 ms |
4444 KB |
Output is correct |
15 |
Correct |
15 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4051 ms |
4460 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
14 ms |
3936 KB |
Output is correct |
23 |
Correct |
11 ms |
3680 KB |
Output is correct |
24 |
Correct |
14 ms |
3932 KB |
Output is correct |
25 |
Correct |
11 ms |
3912 KB |
Output is correct |
26 |
Correct |
20 ms |
4312 KB |
Output is correct |
27 |
Correct |
11 ms |
3676 KB |
Output is correct |
28 |
Correct |
17 ms |
4444 KB |
Output is correct |
29 |
Correct |
12 ms |
3676 KB |
Output is correct |
30 |
Correct |
12 ms |
4184 KB |
Output is correct |
31 |
Correct |
12 ms |
3676 KB |
Output is correct |
32 |
Correct |
11 ms |
3676 KB |
Output is correct |
33 |
Correct |
11 ms |
3676 KB |
Output is correct |
34 |
Correct |
14 ms |
4444 KB |
Output is correct |
35 |
Correct |
15 ms |
4444 KB |
Output is correct |
36 |
Correct |
631 ms |
4368 KB |
Output is correct |
37 |
Correct |
940 ms |
3924 KB |
Output is correct |
38 |
Correct |
1076 ms |
4164 KB |
Output is correct |
39 |
Correct |
260 ms |
4440 KB |
Output is correct |
40 |
Correct |
1184 ms |
4176 KB |
Output is correct |
41 |
Correct |
1690 ms |
4556 KB |
Output is correct |
42 |
Correct |
2199 ms |
4808 KB |
Output is correct |
43 |
Correct |
1180 ms |
3788 KB |
Output is correct |
44 |
Correct |
1416 ms |
3788 KB |
Output is correct |
45 |
Correct |
686 ms |
4188 KB |
Output is correct |
46 |
Correct |
942 ms |
4160 KB |
Output is correct |
47 |
Correct |
1320 ms |
3868 KB |
Output is correct |
48 |
Correct |
438 ms |
3932 KB |
Output is correct |
49 |
Correct |
1476 ms |
3936 KB |
Output is correct |
50 |
Correct |
959 ms |
4600 KB |
Output is correct |
51 |
Execution timed out |
4021 ms |
4600 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |