#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){ 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 st(n+1,0); st[0]=1; fenwick_tree BIT(st); rep(i,n) BIT.add(i+1,1+vr[i],BIT.get(i)); return BIT.get(n); } void solve(vector a,ll s){ ll n=(ll)a.size(); ll ok=0,ng=n+1; while(1> n; vector x(n); rep(i,n) cin >> x[i]; ll q; cin >> q; while(q--){ ll l,r,s; cin >> l >> r >> s; l--; if((1ll< a; for(ll i=l;i