#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r) - 1; i >= (l); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define pb push_back
#define eb emplace_back
#define sz(v) (int)v.size()
#define sum_of(v) accumulate(all(v), 0ll)
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vl = vector<ll>;
using vd = vector<db>;
using vpi = vector<pi>;
using vpl = vector<pl>;
void setIO(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
}
int main(){
setIO();
int N, Q;
cin >> N >> Q;
vi d(N+1);
FOR(i, 1, N+1) cin >> d[i];
const int MAXT = 1e3 + 1;
vector<vi> blocks(MAXT);
vi cur(N+1);
FOR(i, 0, N+1) cur[i] = -i;
blocks[0] = cur;
FOR(t, 1, MAXT){
++cur[0];
FOR(i, 1, N+1){
if(cur[i-1] - cur[i] > d[i]){
cur[i] = cur[i-1] - 1;
}
}
blocks[t] = cur;
// FOR(i, 0, N+1) cout << cur[i] << ' '; cout << '\n';
}
while(Q--){
int T, L, R;
cin >> T >> L >> R;
int l = lower_bound(rall(blocks[T]), L) - blocks[T].rbegin();
int r = upper_bound(rall(blocks[T]), R) - blocks[T].rbegin();
cout << r - l << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |