#include #include using namespace std; typedef long long ll; typedef pair pll; ll n,mod = 1000000007; pll seg[400010],INF = {0,1}; pll cal(pll p, pll q){ if(p.first>q.first) return p; if(p.first0;i--){ seg[i] = cal(seg[i<<1],seg[i<<1|1]); } } void update(pll val,int p){ for(seg[p += n] = val;p>1;p>>=1){ seg[p>>1] = cal(seg[p],seg[p^1]); } } pll query(int l,int r){ pll res = INF; for(l += n,r += n; l>=1,r>>=1){ if(l&1) res = cal(res,seg[l++]); if(r&1) res = cal(res,seg[--r]); } return res; } pll a[200010]; int main(){ int i; cin >> n; for(i=0;i> b; a[i] = {b,-i}; } sort(a,a + n); for(i=0;i