Submission #601974

# Submission time Handle Problem Language Result Execution time Memory
601974 2022-07-22T13:05:14 Z verngutz Progression (NOI20_progression) C++17
15 / 100
3000 ms 45008 KB
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
struct segtree {
    vector<ll>& a;
    segtree* l;
    segtree* r;
    int L, R;
    int longest_eq_suff, longest_eq_pref, longest, longest_start_index;
    segtree(vector<ll>& a, int L, int R): a(a), L(L), R(R) {
        if(R - L > 1) {
            int M = (L + R) / 2;
            l = new segtree(a, L, M);
            r = new segtree(a, M, R);
            longest_eq_suff = r->longest_eq_suff;
            if(r->longest_eq_suff == r->len() && l->back() == r->front()) {
                longest_eq_suff += l->longest_eq_suff;
            }
            longest_eq_pref = l->longest_eq_pref;
            if(l->longest_eq_pref == l->len() && l->back() == r->front()) {
                longest_eq_pref += r->longest_eq_pref;
            }
            int crossing = l->back() == r->front() ? l->longest_eq_suff + r->longest_eq_pref : 0;
            longest = max({l->longest, r->longest, crossing});
            if(longest == r->longest) {
                longest_start_index = r->longest_start_index;
            } else if(longest == crossing) {
                longest_start_index = M - l->longest_eq_suff;
            } else {
                longest_start_index = l->longest_start_index;
            }
        } else {
            longest_eq_suff = 1;
            longest_eq_pref = 1;
            longest = 1;
            longest_start_index = L;
            l = nullptr;
            r = nullptr;
        }
    }
    int front() {
        return a[L];
    }
    int back() {
        return a[R - 1];
    }
    int len() {
        return R - L;
    }
    pair<int, int> query(int s, int e) {
        if(s <= L and R <= e) {
            return {longest, longest_start_index};
        } else if(R <= s or e <= L) {
            return {0, -1};
        } else {
            int M = (L + R) / 2;
            auto [L_longest, L_start_index] = l->query(s, e);
            auto [R_longest, R_start_index] = r->query(s, e);
            int crossing = l->back() == r->front() 
                ? min(l->longest_eq_suff, M - s) + min(r->longest_eq_pref, e - M)
                : 0;
            int crossing_start_index = l->back() == r->front() 
                ? max(M - l->longest_eq_suff, s)
                : -1;
            int ans = max({L_longest, R_longest, crossing});
            int index;
            if(ans == R_longest) {
                index = R_start_index;
            } else if(ans == crossing) {
                index = crossing_start_index;
            } else {
                index = max(L_start_index, s);
            }
            return {ans, index};
        }
    }
    ~segtree() {
        delete l;
        delete r;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<ll> d(n), diff(n);
    cin >> d;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int L, R, S, C;
            cin >> L >> R >> S >> C;
            L--, R--;
            for(int i = L; i <= R; i++) {
                d[i] += S + (i - L) * C;
            }
        } else if(t == 2) {
            int L, R, S, C;
            cin >> L >> R >> S >> C;
            L--, R--;
            for(int i = L; i <= R; i++) {
                d[i] = S + (i - L) * C;
            }
        } else {
            int L, R;
            cin >> L >> R;
            L--, R--;
            adjacent_difference(d.begin(), d.end(), diff.begin());
            segtree st(diff, 0, n);
            auto [longest, longest_start_index] = st.query(L, R + 1);
            cout << longest + (longest_start_index != L) << endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 45004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 468 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 22 ms 468 KB Output is correct
9 Correct 25 ms 468 KB Output is correct
10 Correct 26 ms 468 KB Output is correct
11 Correct 64 ms 468 KB Output is correct
12 Correct 25 ms 468 KB Output is correct
13 Correct 68 ms 468 KB Output is correct
14 Correct 51 ms 468 KB Output is correct
15 Correct 22 ms 468 KB Output is correct
16 Correct 23 ms 468 KB Output is correct
17 Correct 23 ms 468 KB Output is correct
18 Correct 25 ms 464 KB Output is correct
19 Correct 2 ms 328 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3060 ms 44948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3048 ms 45008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3060 ms 44948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 45004 KB Time limit exceeded
2 Halted 0 ms 0 KB -