import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class SUM{ int n=1; int[] v; public SUM(int n_) { while(n[] list=new ArrayList[N]; for(int i=0;i(); for(int i=0;i=0;--i) { int v=rmq.query(0, pos[i]); list[v+1].add(pos[i]); rmq.setVal(pos[i], pos[i]); } PrintWriter pw=new PrintWriter(System.out); int[][] query=new int[Q][]; long[] ans=new long[Q]; for(int i=0;iv[0])); int p=0; for(int i=0;i