結果

問題 No.1703 Much Matching
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,048 KB
testcase_01 AC 28 ms
17,920 KB
testcase_02 AC 28 ms
18,176 KB
testcase_03 AC 29 ms
18,304 KB
testcase_04 AC 30 ms
18,432 KB
testcase_05 AC 29 ms
18,304 KB
testcase_06 AC 359 ms
25,344 KB
testcase_07 AC 46 ms
22,144 KB
testcase_08 AC 371 ms
24,704 KB
testcase_09 AC 418 ms
25,216 KB
testcase_10 AC 83 ms
22,396 KB
testcase_11 AC 112 ms
22,388 KB
testcase_12 AC 45 ms
22,144 KB
testcase_13 AC 176 ms
23,040 KB
testcase_14 AC 35 ms
19,328 KB
testcase_15 AC 100 ms
22,260 KB
testcase_16 AC 244 ms
23,552 KB
testcase_17 AC 270 ms
23,424 KB
testcase_18 AC 33 ms
18,944 KB
testcase_19 AC 555 ms
28,288 KB
testcase_20 AC 92 ms
22,532 KB
testcase_21 AC 649 ms
30,720 KB
testcase_22 AC 265 ms
24,192 KB
testcase_23 AC 202 ms
23,552 KB
testcase_24 AC 33 ms
19,328 KB
testcase_25 AC 53 ms
22,272 KB
testcase_26 AC 140 ms
22,912 KB
testcase_27 AC 288 ms
23,808 KB
testcase_28 AC 525 ms
25,856 KB
testcase_29 AC 119 ms
22,508 KB
testcase_30 AC 167 ms
22,784 KB
testcase_31 AC 40 ms
21,376 KB
testcase_32 AC 295 ms
23,680 KB
testcase_33 AC 199 ms
23,040 KB
testcase_34 AC 45 ms
22,272 KB
testcase_35 AC 72 ms
22,268 KB
testcase_36 AC 1,278 ms
31,616 KB
testcase_37 AC 29 ms
18,432 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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));}
}
0