using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; //using nint=System.Int32; static class Program{ const int mod=(int)1e9+7; static void Main(){ Sc sc=new Sc(); var (n,m,q)=sc.Tp3(); var li=new List[n+1]; for(int i = 1;i<=n;i++) { li[i]=new List(); } for(int i = 0;iv-u); for(int j = 0;j"n:"+n.ToString()+" d:"+d.ToString(); } private Dt[] dat; private int n,cnt; private bool ku; private Dt du; private Func compare; public St(int n,bool mm,bool ku,long df){ this.n=n; this.ku=ku; if(mm){du=new Dt(long.MinValue,-1);compare=CoMax;} else{du=new Dt(long.MaxValue,-1);compare=CoMin;} cnt=n<<1; dat=new Dt[cnt]; for(int i = cnt-1;i>=cnt-n;i--) {dat[i]=new Dt(df,n-cnt+i);} for(int i = cnt-n-1;i>0;i--) {dat[i]=dat[i<<1];} } private Dt CoMax(Dt x,Dt y){return x.d>y.d?x:y;} private Dt CoMin(Dt x,Dt y){return x.d1){dat[q>>=1]=compare(dat[q<<1],dat[(q<<1)+1]);} } public Dt Get(int l,int r){ Dt x=du; l+=n;r+=n; while(l<=r){ if((l&1)==1){x=compare(x,dat[l]);l++;} if((r&1)==0){x=compare(x,dat[r]);r--;} l>>=1;r>>=1; } return x; } public (int r,long d) Bsl(int l,long b){ Dt x=du,bd=new Dt(b,-1); int r=cnt-1; l+=n; var sk=new Stack(); while(l<=r){ if((l&1)==1){ if(compare(bd,compare(x,dat[l]))!=bd){goto lb;} x=compare(x,dat[l]); l++; } if((r&1)==0){sk.Push(r);r--;} l>>=1;r>>=1; } while(sk.Count>0){ l=sk.Pop(); if(compare(bd,compare(x,dat[l]))!=bd){goto lb;} x=compare(x,dat[l]); } return (-1,x.d); lb: while(l<<1(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(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T,T,T) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} public (T,T,T,T) Tp4(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]));} public (T1,T2) Tp2(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T1,T1,T2) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} }