Submission #364712

#TimeUsernameProblemLanguageResultExecution timeMemory
364712Mamnoon_SiamFire (JOI20_ho_t5)C++17
1 / 100
1092 ms4884 KiB
#include <bits/stdc++.h> using namespace std; /* sorry, this is the bare minimum :'( */ using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second const int N = 2e5 + 5; int n, q; int a[N]; int prv[N]; int sub[N]; int intersect(int l1, int r1, int l2, int r2) { return max(0, min(r1, r2) - max(l1, l2) + 1); } int main(int argc, char const *argv[]) { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); #ifdef LOCAL freopen("in", "r", stdin); #endif cin >> n >> q; for(int i = 1; i <= n; ++i) { cin >> a[i]; } a[0] = INT_MAX; vector<int> stk = {0}; for(int i = 1; i <= n; ++i) { while(a[stk.back()] <= a[i]) { stk.pop_back(); } prv[i] = stk.back(); stk.push_back(i); } fill(sub+1, sub+1+n, 1); for(int i = n; i >= 1; --i) { sub[prv[i]] += sub[i]; } while(q--) { int T, l, r; cin >> T >> l >> r; ll ans = 0; for(int i = l; i <= r; ++i) ans += a[i]; for(int i = 1; i <= n; ++i) if(prv[i]) { ll f = a[prv[i]] - a[i]; int intersex; if(i+sub[i]-1 <= prv[i]+T) { intersex = intersect(i, i+sub[i]-1, l, r); } else { intersex = intersect(i, prv[i]+T, l, r); } ans += f * intersex; } cout << ans << endl; } 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...