using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program{ const int mod=(int)1e9+7; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; var a=sc.Ia; int p=0,n=s[0],q=s[1]; var g=new int[n][]; int[] la=new int[n],ua=new int[n]; var z=new int[q][]; var liq=new List[n]; var qe=new int[q][]; for(int i = 0;i(); } Array.Sort(g,(u,v)=>v[1]-u[1]); int mid=(n-1)>>1; la[mid]=-1; ua[mid]=n; for(int i = 0;i>1; liq[mid].Add(i); } while(p=qe[liq[i][j]][2]){ mid=(la[i]+i)>>1; lb=la[i]; } else{ mid=(ua[i]+i)>>1; ub=ua[i]; } if(ub-lb>1){ liq[mid].Add(liq[i][j]); la[mid]=lb; ua[mid]=ub; } else{ z[liq[i][j]]=new int[]{g[ub][1],liq[i][j]}; p++; } } } liq[i].Clear(); } } Bit bit2=new Bit(n); Bit bit3=new Bit(n); var ans=new long[q]; var x=new long[q]; var y=new long[q]; Array.Sort(z,(u,v)=>u[0]-v[0]); for(int i = n-1,j=0;i>=0;i--) { bit2.Ud(g[i][0],g[i][1]); bit3.Ud(g[i][0],1); while(j0){a+=bit[n];n-=n&-n;} return a; } public long Get2(int m,int n){ long a=0,b=0; m--; while(n>m){a+=bit[n];n-=n&-n;} if(n==m){return a;} while(n!=m){b+=bit[m];m-=m&-m;} return a-b; } public void Clear(){bit=new long[n+1];} } public class Sc{ public int I{get{return int.Parse(Console.ReadLine());}} public long L{get{return long.Parse(Console.ReadLine());}} public double D{get{return double.Parse(Console.ReadLine());}} public string S{get{return Console.ReadLine();}} public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}} public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}} public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}} public string[] Sa{get{return Console.ReadLine().Split();}} public object[] Oa{get{return Console.ReadLine().Split();}} public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}} public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);} public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);} public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);} public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}} public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);} public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);} public T[] Arr(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i