Submission #802194

# Submission time Handle Problem Language Result Execution time Memory
802194 2023-08-02T10:58:40 Z Johann Mizuyokan 2 (JOI23_mizuyokan2) C++14
28 / 100
4000 ms 24144 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const int INF = 1e9;

int N, Q;
vi L;

struct segtree
{
    vi arr;
    int size;
    void init(int _size)
    {
        size = 1;
        while (size < _size)
            size *= 2;
        arr.assign(2 * size, -INF);
    }
    void set(int i, ll v)
    {
        i += size;
        while (i > 0)
        {
            arr[i] = max(arr[i], v);
            i /= 2;
        }
    }
    ll query(int l, int r) { return query(l, r, 1, 0, size); }
    ll query(int l, int r, int x, int lx, int rx)
    {
        if (l <= lx && rx <= r)
            return arr[x];
        if (r <= lx || rx <= l)
            return -INF;
        int m = (lx + rx) / 2;
        return max(query(l, r, 2 * x, lx, m), query(l, r, 2 * x + 1, m, rx));
    }
};
segtree seg;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    L.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> L[i];
    cin >> Q;

    while (Q--)
    {
        ll x, y, a, b;
        cin >> x >> y >> a >> b;
        --x;
        L[x] = y;

        vi B(L.begin() + a, L.begin() + b);
        vi pref(sz(B));
        partial_sum(all(B), pref.begin());
        // starting with lower piece
        seg.init(sz(B));
        // seg used as dp
        // vi dp(sz(B), -INF); // dp[i] := number of zigzag pieces in prefix i with i as minimum
        vvpii activate(sz(B) + 1);

        ll ans = -INF;

        for (int i = 0; i < sz(B); ++i)
        {
            for (pii tmp : activate[i])
                seg.set(tmp.first, tmp.second);

            ll needed;
            needed = pref[i] - 2 * B[i] - 1;
            pii ac;
            if (needed < 0)
                ac = {i, 1};
            else
            {
                int r = upper_bound(all(pref), needed) - pref.begin();
                ac = {i, max(0LL, seg.query(0, r)) + 2};
            }

            ans = max(ans, ac.second);

            needed = pref[i] + B[i] + 1;
            if (needed <= pref.back())
            {
                int idx = lower_bound(all(pref), needed) - pref.begin();
                idx += 1;
                if (idx < sz(activate))
                    activate[idx].push_back(ac);
            }
        }
        for (pii tmp : activate[sz(B)])
            seg.set(tmp.first, tmp.second);

        ans = max(ans, seg.query(0, seg.size) + 1);

        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 352 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 500 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 352 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 500 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 17 ms 3924 KB Output is correct
42 Correct 19 ms 4428 KB Output is correct
43 Correct 21 ms 4444 KB Output is correct
44 Correct 19 ms 4984 KB Output is correct
45 Correct 75 ms 13960 KB Output is correct
46 Correct 217 ms 23572 KB Output is correct
47 Correct 171 ms 19184 KB Output is correct
48 Correct 265 ms 24144 KB Output is correct
49 Correct 355 ms 23884 KB Output is correct
50 Correct 217 ms 18752 KB Output is correct
51 Correct 204 ms 23872 KB Output is correct
52 Correct 132 ms 18936 KB Output is correct
53 Correct 303 ms 22420 KB Output is correct
54 Correct 265 ms 21180 KB Output is correct
55 Correct 258 ms 23360 KB Output is correct
56 Correct 199 ms 17484 KB Output is correct
57 Correct 130 ms 12968 KB Output is correct
58 Correct 227 ms 22252 KB Output is correct
59 Correct 63 ms 17752 KB Output is correct
60 Correct 91 ms 13136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 383 ms 1852 KB Output is correct
3 Correct 2591 ms 6080 KB Output is correct
4 Execution timed out 4008 ms 5248 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 373 ms 2292 KB Output is correct
4 Correct 2546 ms 5104 KB Output is correct
5 Execution timed out 4030 ms 19580 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 352 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 500 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 17 ms 3924 KB Output is correct
42 Correct 19 ms 4428 KB Output is correct
43 Correct 21 ms 4444 KB Output is correct
44 Correct 19 ms 4984 KB Output is correct
45 Correct 75 ms 13960 KB Output is correct
46 Correct 217 ms 23572 KB Output is correct
47 Correct 171 ms 19184 KB Output is correct
48 Correct 265 ms 24144 KB Output is correct
49 Correct 355 ms 23884 KB Output is correct
50 Correct 217 ms 18752 KB Output is correct
51 Correct 204 ms 23872 KB Output is correct
52 Correct 132 ms 18936 KB Output is correct
53 Correct 303 ms 22420 KB Output is correct
54 Correct 265 ms 21180 KB Output is correct
55 Correct 258 ms 23360 KB Output is correct
56 Correct 199 ms 17484 KB Output is correct
57 Correct 130 ms 12968 KB Output is correct
58 Correct 227 ms 22252 KB Output is correct
59 Correct 63 ms 17752 KB Output is correct
60 Correct 91 ms 13136 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 383 ms 1852 KB Output is correct
63 Correct 2591 ms 6080 KB Output is correct
64 Execution timed out 4008 ms 5248 KB Time limit exceeded
65 Halted 0 ms 0 KB -