#include <bits/stdc++.h>
using namespace std;
const int c=100005;
int n, t[c];
set<pair<int, int> > s;
vector<pair<int, pair<int, int> > > sz;
void init(int N, vector<int> sz) {
n=N;
for (int i=0; i<n; i++) {
t[i+1]=sz[i];
}
}
int max_towers(int l, int r, int d) {
l++, r++;
for (int i=l-1; i<=r+1; i++) {
s.insert({i, 1});
}
for (int i=l; i<=r; i++) {
sz.push_back({t[i], {1, i}}), sz.push_back({t[i]+d, {0, i}});
}
sort(sz.begin(), sz.end());
int maxi=0, ert=0;
for (auto x:sz) {
int id=x.second.first, pos=x.second.second;
//cout << "fontos " << pos << " " << id << "\n";
if (!id) {
s.insert({pos, id});
}
auto it=s.upper_bound({pos, -1});
int cnt=0;
it++;
cnt+=(*it).second;
it--, it--;
cnt+=(*it).second;
if (id==0) {
if (cnt==2) {
ert++;
}
}
if (id==1) {
if (!cnt) {
ert--;
}
s.erase({pos, id});
}
maxi=max(maxi, ert);
}
s.clear(), sz.clear();
return maxi;
}
int main()
{
int N;
vector<int> P;
cin >> N;
for (int i=0; i<N; i++) {
int x;
cin >> x;
P.push_back(x);
}
init(N, P);
int q;
cin >> q;
while (q--) {
int l, r, d;
cin >> l >> r >> d;
cout << max_towers(l, r, d) << "\n";
}
return 0;
}
/*
7
10 20 60 40 50 30 70
1
1 5 10
*/
Compilation message
/usr/bin/ld: /tmp/ccDJyQaH.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6qWy8D.o:towers.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status