제출 #1131781

#제출 시각아이디문제언어결과실행 시간메모리
1131781antonnFire (JOI20_ho_t5)C++20
0 / 100
1094 ms2788 KiB
#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

template<class T> bool ckmin(T& a, T b) { return b < a ? a = b, true : false; }
template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, true : false; }

const int N = 2e5+7;
const int L = 20;

int a[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    
    vector<int> lft(n + 1), rgh(n + 1);
    vector<int> stk;
    for (int i = 1; i <= n; ++i) {
        while (!stk.empty() && a[i] >= a[stk.back()]) stk.pop_back();
        if (stk.empty()) lft[i] = -1e9;
        if (!stk.empty()) lft[i] = stk.back() + 1;
        stk.push_back(i);
    }
    stk.clear();
    for (int i = n; i >= 1; --i) {
        while (!stk.empty() && a[i] >= a[stk.back()]) stk.pop_back();
        if (stk.empty()) rgh[i] = +1e9;
        if (!stk.empty()) rgh[i] = stk.back() - 1;
        stk.push_back(i);
    }
    
    for (int i = 1; i <= q; ++i) {
        int t, l, r; cin >> t >> l >> r;
        ll ans = 0;
        for (int j = 1; j <= n; ++j) {
            int L = max({lft[j] + t, l, j}); 
            int R = min({j + t, r, rgh[j]});
            if (L <= R) ans += (R - L + 1) * a[j];
        }
        cout << ans << "\n";
    }
}
#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...