Submission #806866

# Submission time Handle Problem Language Result Execution time Memory
806866 2023-08-04T10:38:50 Z hugo_pm Triple Jump (JOI19_jumps) C++17
5 / 100
4000 ms 37316 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define sz(v) ((int)((v).size()))

template<typename T>
void chmax(T &x, const T &v) { if (x < v) x = v; }
template<typename T>
void chmin(T &x, const T &v) { if (x > v) x = v; }

using pii = pair<int, int>;
using vi = vector<int>;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
	bool first = true;
	string res = "[";
	for (const auto &x : v) {
		if (!first)
			res += ", ";
		first = false;
		res += to_string(x);
	}
	res += "]";
	return res;
}

template <typename val, typename B>
string to_string(pair<val, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
	cout << ' ' << to_string(H);
	dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct Segtree {
    #define op max
    const int e = -1e18;
    vector<int> tree;
    int N;
    Segtree(vector<int> v) {
        N = v.size();
        tree.resize(2*N);
        for (int i = 2*N-1; i >= 1; --i) {
            tree[i] = (i >= N ? v[i-N] : op(tree[2*i], tree[2*i+1]));
        }
    }
    int query_include(int L, int R) {
        L += N, R += N+1;
        int res = e;
        while (L < R) {
            if (L & 1) res = op(res, tree[L++]);
            if (R & 1) res = op(res, tree[--R]);
            L /= 2, R /= 2;
        }
        return res;
    }
    #undef op
};

struct Req {
    int l, r, i;
};
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    vector<int> val(N);
    for (int &x : val) cin >>x;
    int Q; cin >> Q;
    vector<vector<Req>> req(N);
    vector<int> ansReq(Q);
    rep(i, 0, Q) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        req[l].push_back({l, r, i});
    }
    vector<int> stk;
    vector<vi> cand(N);
    rep(B, 0, N) {
        while (!stk.empty()) {
            int A = stk.back();
            cand[A].push_back(B);
            if (val[A] >= val[B]) break;
            stk.pop_back();
        }
        stk.push_back(B);
    }
    Segtree st(val);
    vector<pii> ptRouge, ptBleu;
    for (int i = N-1; i >= 0; --i) {
        ptBleu.emplace_back(i, val[i]);
        {
            int A = i;
            for (int B : cand[i]) {
                int suffC = B + (B-A);
                ptRouge.emplace_back(suffC, val[A]+val[B]);
            }
        }
        for (Req rq : req[i]) {
            for (auto [xR, yR] : ptRouge) for (auto [xB, yB] : ptBleu) {
                if (xR <= xB && xB <= rq.r) chmax(ansReq[rq.i], yR+yB);
            }
        }
    }
    rep(i, 0, Q) {
        cout << ansReq[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Execution timed out 4037 ms 29036 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 37316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Execution timed out 4037 ms 29036 KB Time limit exceeded
12 Halted 0 ms 0 KB -