#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a struct fenwick_tree{ vector v; int n; fenwick_tree(int x){ n=x+1; v.assign(n+1,0); } fenwick_tree(vector &a){ n=(int)a.size()+1; v.assign(n+1,0); if((int)a.size()==0) return; v[1]=a[0]; for(int i=0;i>=1){ if(x+k<=n&&v[x+k] a,ll n,ll k){ //O(n) if(k==0) return 0; vector vr(n,0); ll r=0,sz=0; rep(l,n){ auto g=[&](ll idx){ ll p=0; if(cnt[a[idx]]==0) p=1; return (sz+p)<=k; }; while(r dp(n+1,0),sum(n+2,0); dp[0]=1; rep(i,n+1){ dp[i]+=sum[i]; if(INF a,ll s,auto &f){ //O(N) ll n=(ll)a.size(); ll ok=0; rep(i,n+1){ if(f(a,n,i)<=s) chmax(ok,i); else break; } cout << ok << '\n'; } void solve_b(vector a,ll s){ //O(M^2) return solve_linear(a,s,f_linear); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; assert(1<=n&&n<=1000000); vector x(n); rep(i,n){ cin >> x[i]; assert(0<=x[i]&&x[i]<=n); } ll q; cin >> q; assert(1<=q&&q<=10000); rep(t,q){ if(t==60) break; ll l,r,s; cin >> l >> r >> s; assert(1<=l&&l<=r&&r<=n); assert(1<=s&&s<=(1ll<<60)); } }