結果
問題 | No.1703 Much Matching |
ユーザー | fgwiebfaoish |
提出日時 | 2021-10-08 23:07:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,278 ms / 2,000 ms |
コード長 | 5,080 bytes |
コンパイル時間 | 1,029 ms |
コンパイル使用メモリ | 118,364 KB |
実行使用メモリ | 31,616 KB |
最終ジャッジ日時 | 2024-07-23 06:38:56 |
合計ジャッジ時間 | 9,929 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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<int>(); var li=new List<int>[n+1]; for(int i = 1;i<=n;i++) { li[i]=new List<int>(); } for(int i = 0;i<q;i++) { var e=sc.Ia; li[e[0]].Add(e[1]); } St st=new St(m+1,true,false,0); for(int i = 1;i<=n;i++) { li[i].Sort((u,v)=>v-u); for(int j = 0;j<li[i].Count;j++) { var p=st.Get(0,li[i][j]-1).d; st.Ud(li[i][j],p+1); } } Console.WriteLine("{0}",st.Get(0,m).d); } } public class St{ public class Dt{ public int n; public long d; public Dt(long d,int n){this.d=d;this.n=n;} public override string ToString()=>"n:"+n.ToString()+" d:"+d.ToString(); } private Dt[] dat; private int n,cnt; private bool ku; private Dt du; private Func<Dt,Dt,Dt> 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.d<y.d?x:y;} public void Ud(int q,long b){ q+=n; if(ku){dat[q].d+=b;} else{dat[q].d=b;} while(q>1){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<int>(); 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<cnt){ l<<=1; if(compare(bd,compare(x,dat[l]))==bd){x=compare(x,dat[l]);l++;} } return (l-n,compare(x,dat[l]).d); } } 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(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);} public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);} public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);} public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}} public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);} public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;} public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;} public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;} public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;} public (T,T) Tp2<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]));} public (T,T,T) Tp3<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]));} public (T,T,T,T) Tp4<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]),Ct<T>(s[3]));} public (T1,T2) Tp2<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T2>(s[1]));} public (T1,T1,T2) Tp3<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T1>(s[1]),Ct<T2>(s[2]));} private T Ct<T>(string s){return (T)Convert.ChangeType(s,typeof(T));} }