Submission #650336

#TimeUsernameProblemLanguageResultExecution timeMemory
650336600MihneaFire (JOI20_ho_t5)C++17
1 / 100
1090 ms12032 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Op { int limit; int k; int id; }; int main() { #ifndef ONPC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif int n, q; cin >> n >> q; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } // l, r, t vector<ll> prn(2 * q, 0); vector<Op> ops; for (int i = 0; i < q; i++) { int l, r, t; cin >> t >> l >> r; l--, r--; ops.push_back({l - 1, t, i}); ops.push_back({r, t, i + q}); } // next bigger vector<int> nxt(n, n), ant(n, -1); { vector<int> stk; for (int i = n - 1; i >= 0; i--) { while (!stk.empty() && a[stk.back()] <= a[i]) { stk.pop_back(); } if (!stk.empty()) { nxt[i] = stk.back(); } stk.push_back(i); } } { vector<int> stk; for (int i = 0; i < n; i++) { while (!stk.empty() && a[stk.back()] < a[i]) { stk.pop_back(); } if (!stk.empty()) { ant[i] = stk.back(); } stk.push_back(i); } } for (auto &it : ops) { int limit = it.limit; if (limit < 0) { //cout << "skip\n"; continue; } int k = it.k; int id = it.id; ll sol = 0; for (int i = 0; i <= limit; i++) { for (int rgh = 0; rgh <= limit; rgh++) { int lft = max(0, rgh - k); // is i the maximum in the interval [lft, rgh]? if (ant[i] < lft && lft <= i && i <= rgh && rgh < nxt[i]) { sol += a[i]; } } // whenever this comes I make an assumption and later a correction } prn[id] = sol; } for (int i = 0; i < q; i++) { cout << prn[i + q] - prn[i] << "\n"; } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...