Submission #963904

# Submission time Handle Problem Language Result Execution time Memory
963904 2024-04-16T02:37:20 Z Pring Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 3928 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
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:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 39
      |                    ^~
fish2.cpp:92:5: note: in expansion of macro 'debug'
   92 |     debug(id);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 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 2392 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 3 ms 2392 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 4 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 3 ms 2528 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 5 ms 2396 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 8 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 10 ms 3592 KB Output is correct
3 Correct 9 ms 3420 KB Output is correct
4 Correct 11 ms 3420 KB Output is correct
5 Correct 9 ms 3416 KB Output is correct
6 Correct 14 ms 3420 KB Output is correct
7 Correct 10 ms 3420 KB Output is correct
8 Correct 14 ms 3420 KB Output is correct
9 Correct 9 ms 3416 KB Output is correct
10 Correct 13 ms 3416 KB Output is correct
11 Correct 9 ms 3420 KB Output is correct
12 Correct 10 ms 3420 KB Output is correct
13 Correct 10 ms 3408 KB Output is correct
14 Correct 11 ms 3676 KB Output is correct
15 Correct 12 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 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 2392 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 3 ms 2392 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 4 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 3 ms 2528 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 5 ms 2396 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 8 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 10 ms 3592 KB Output is correct
23 Correct 9 ms 3420 KB Output is correct
24 Correct 11 ms 3420 KB Output is correct
25 Correct 9 ms 3416 KB Output is correct
26 Correct 14 ms 3420 KB Output is correct
27 Correct 10 ms 3420 KB Output is correct
28 Correct 14 ms 3420 KB Output is correct
29 Correct 9 ms 3416 KB Output is correct
30 Correct 13 ms 3416 KB Output is correct
31 Correct 9 ms 3420 KB Output is correct
32 Correct 10 ms 3420 KB Output is correct
33 Correct 10 ms 3408 KB Output is correct
34 Correct 11 ms 3676 KB Output is correct
35 Correct 12 ms 3676 KB Output is correct
36 Correct 592 ms 3648 KB Output is correct
37 Correct 881 ms 3928 KB Output is correct
38 Correct 1024 ms 3572 KB Output is correct
39 Correct 258 ms 3612 KB Output is correct
40 Correct 1107 ms 3572 KB Output is correct
41 Correct 1275 ms 3828 KB Output is correct
42 Correct 1645 ms 3664 KB Output is correct
43 Correct 1146 ms 3576 KB Output is correct
44 Correct 1346 ms 3568 KB Output is correct
45 Correct 643 ms 3580 KB Output is correct
46 Correct 842 ms 3572 KB Output is correct
47 Correct 1234 ms 3568 KB Output is correct
48 Correct 450 ms 3668 KB Output is correct
49 Correct 1433 ms 3604 KB Output is correct
50 Correct 747 ms 3736 KB Output is correct
51 Correct 3254 ms 3732 KB Output is correct
52 Correct 3526 ms 3736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 10 ms 3592 KB Output is correct
3 Correct 9 ms 3420 KB Output is correct
4 Correct 11 ms 3420 KB Output is correct
5 Correct 9 ms 3416 KB Output is correct
6 Correct 14 ms 3420 KB Output is correct
7 Correct 10 ms 3420 KB Output is correct
8 Correct 14 ms 3420 KB Output is correct
9 Correct 9 ms 3416 KB Output is correct
10 Correct 13 ms 3416 KB Output is correct
11 Correct 9 ms 3420 KB Output is correct
12 Correct 10 ms 3420 KB Output is correct
13 Correct 10 ms 3408 KB Output is correct
14 Correct 11 ms 3676 KB Output is correct
15 Correct 12 ms 3676 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Execution timed out 4065 ms 3572 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 10 ms 3592 KB Output is correct
3 Correct 9 ms 3420 KB Output is correct
4 Correct 11 ms 3420 KB Output is correct
5 Correct 9 ms 3416 KB Output is correct
6 Correct 14 ms 3420 KB Output is correct
7 Correct 10 ms 3420 KB Output is correct
8 Correct 14 ms 3420 KB Output is correct
9 Correct 9 ms 3416 KB Output is correct
10 Correct 13 ms 3416 KB Output is correct
11 Correct 9 ms 3420 KB Output is correct
12 Correct 10 ms 3420 KB Output is correct
13 Correct 10 ms 3408 KB Output is correct
14 Correct 11 ms 3676 KB Output is correct
15 Correct 12 ms 3676 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Execution timed out 4077 ms 3576 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 2392 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 2392 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 3 ms 2392 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 4 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 3 ms 2528 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 5 ms 2396 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 8 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 10 ms 3592 KB Output is correct
23 Correct 9 ms 3420 KB Output is correct
24 Correct 11 ms 3420 KB Output is correct
25 Correct 9 ms 3416 KB Output is correct
26 Correct 14 ms 3420 KB Output is correct
27 Correct 10 ms 3420 KB Output is correct
28 Correct 14 ms 3420 KB Output is correct
29 Correct 9 ms 3416 KB Output is correct
30 Correct 13 ms 3416 KB Output is correct
31 Correct 9 ms 3420 KB Output is correct
32 Correct 10 ms 3420 KB Output is correct
33 Correct 10 ms 3408 KB Output is correct
34 Correct 11 ms 3676 KB Output is correct
35 Correct 12 ms 3676 KB Output is correct
36 Correct 592 ms 3648 KB Output is correct
37 Correct 881 ms 3928 KB Output is correct
38 Correct 1024 ms 3572 KB Output is correct
39 Correct 258 ms 3612 KB Output is correct
40 Correct 1107 ms 3572 KB Output is correct
41 Correct 1275 ms 3828 KB Output is correct
42 Correct 1645 ms 3664 KB Output is correct
43 Correct 1146 ms 3576 KB Output is correct
44 Correct 1346 ms 3568 KB Output is correct
45 Correct 643 ms 3580 KB Output is correct
46 Correct 842 ms 3572 KB Output is correct
47 Correct 1234 ms 3568 KB Output is correct
48 Correct 450 ms 3668 KB Output is correct
49 Correct 1433 ms 3604 KB Output is correct
50 Correct 747 ms 3736 KB Output is correct
51 Correct 3254 ms 3732 KB Output is correct
52 Correct 3526 ms 3736 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Execution timed out 4065 ms 3572 KB Time limit exceeded
55 Halted 0 ms 0 KB -