結果

問題 No.953 席
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2019-12-16 01:33:16
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 6,115 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 107,888 KB
実行使用メモリ 51,128 KB
最終ジャッジ日時 2023-09-15 16:20:01
合計ジャッジ時間 13,885 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
20,896 KB
testcase_01 AC 61 ms
20,884 KB
testcase_02 AC 333 ms
40,792 KB
testcase_03 AC 319 ms
40,532 KB
testcase_04 AC 331 ms
42,636 KB
testcase_05 AC 291 ms
37,580 KB
testcase_06 AC 334 ms
40,908 KB
testcase_07 AC 361 ms
46,864 KB
testcase_08 AC 503 ms
44,808 KB
testcase_09 AC 319 ms
47,172 KB
testcase_10 AC 154 ms
30,232 KB
testcase_11 AC 390 ms
42,396 KB
testcase_12 AC 429 ms
46,840 KB
testcase_13 WA -
testcase_14 AC 403 ms
43,768 KB
testcase_15 AC 392 ms
45,468 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 364 ms
45,084 KB
testcase_24 WA -
testcase_25 AC 524 ms
47,316 KB
testcase_26 AC 261 ms
36,456 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.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;
		int p=s[1];
		var o=new int[]{s[1]-s[2],s[2]-s[1]};
		var b=true;
		St st=new St(s[0]+2,false,true,0);
		for(int i = 1,j=0;;i++) {
			p+=i*o[i&1];
			if(p>0&&p<=s[0]){
				j++;
				st.Ud(p,j);
				b=true;
			}
			else if(b){b=false;}
			else{break;}
		}
		var pq=new Rheap<Tuple<int,int>>(32);
		var n=sc.I;
		for(int i = 0;i<n;i++) {
			var e=sc.Ia;
			pq.Push(new Rheap<Tuple<int,int>>.Dt(e[0],Tuple.Create(i,e[1])));
		}
		var d=new int[n];
		var r=new int[s[0]+2];
		var g=new Rheap<Tuple<int,int>>.Dt[n+1];
		int k=0,l=0;
		while(pq.cnt>0){
			var e=pq.Dequeue;
			if(e.d.Item2!=-1){
				if(st.Get(1,s[0]).d>=1e9){
					g[k]=e;
					k++;
					continue;
				}
				int z=st.Get(1,s[0]).n;
				st.Ud(z,(long)1e9);
				if(r[z+1]==0){st.Ud(z+1,200000);}
				if(r[z-1]==0){st.Ud(z-1,200000);}
				r[z+1]++;
				r[z-1]++;
				pq.Push(new Rheap<Tuple<int,int>>.Dt(e.n+e.d.Item2,Tuple.Create(e.d.Item1,-1)));
				d[e.d.Item1]=z;
			}
			else if(g[l]!=null){
				pq.Push(new Rheap<Tuple<int,int>>.Dt(e.n+g[l].d.Item2,Tuple.Create(g[l].d.Item1,-1)));
				d[g[l].d.Item1]=d[e.d.Item1];
				l++;
			}
			else{
				int z=d[e.d.Item1];
				st.Ud(z,(long)-1e9);
				r[z+1]--;
				r[z-1]--;
				if(r[z+1]==0){st.Ud(z+1,-200000);}
				if(r[z-1]==0){st.Ud(z-1,-200000);}
			}
		}
		Console.WriteLine(String.Join("\n",d));
	}
}
public class Rheap<T>{
	public class Dt{
		public long n;
		public T d;
		public Dt(long n,T d){this.n=n;this.d=d;}
	}
	private const int m=65;
	private long la=0;
	private Dt[][] bf;
	private int[] h;
	public int cnt=0;
	public Rheap(int max){
		bf=new Dt[m][];
		h=new int[m];
		for(int i = 0;i<m;i++) {bf[i]=new Dt[max];}
	}
	public void Push(Dt x){
		int a=x.n!=la?Bsr(la^x.n)+1:0;
		if(h[a]==bf[a].Length){Extend(a);}
		bf[a][h[a]]=x;
		cnt++;
		h[a]++;
	}
	public Dt Peek{get{
		if(h[0]==0){
			for(int i = 1;i<m;i++) {
				if(h[i]>0){
					int p=0;
					for(int j = 1;j<h[i];j++) {
						if(bf[i][p].n>bf[i][j].n){p=j;}
					}
					la=bf[i][p].n;
					for(int j = 0;j<h[i];j++) {
						Push(bf[i][j]);
						cnt--;
					}
					h[i]=0;
					break;
				}
			}
		}
		return bf[0][h[0]-1];
	}}
	public Dt Dequeue{get{
		var e=Peek;
		h[0]--;
		cnt--;
		return e;
	}}
	private void Extend(int n){
		var nhe=new Dt[bf[n].Length<<1];
		Array.Copy(bf[n],nhe,bf[n].Length);
		bf[n]=nhe;
	}
	private int Bsr(long b){
		int n=0;
		if(b==0){return -1;}
		if((b&-4294967296)!=0){b=b&-4294967296;n+=32;}
		if((b&-281470681808896)!=0){b=b&-281470681808896;n+=16;}
		if((b&-71777214294589696)!=0){b=b&-71777214294589696;n+=8;}
		if((b&-1085102592571150096)!=0){b=b&-1085102592571150096;n+=4;}
		if((b&-3689348814741910324)!=0){b=b&-3689348814741910324;n+=2;}
		if((b&-6148914691236517206)!=0){b=b&-6148914691236517206;n+=1;}
		return n;
	}
}
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 Dt[] dat;
	private int m=1;
	private bool mm,ku;
	private Dt du;
	private Func<Dt,Dt,bool> compare;
	public St(int n,bool mm,bool ku,long df){
		this.mm=mm;this.ku=ku;
		if(mm){du=new Dt(long.MinValue,-1);compare=CoMax;}
		else{du=new Dt(long.MaxValue,-1);compare=CoMin;}
		while(m<n){m<<=1;}
		m--;
		dat=new Dt[m+n+1];
		dat[m+n]=du;
		for(int i=m+n-1;i>=m;i--){dat[i]=new Dt(df,i-m);}
		for(int i=m-1;i>=0;i--){dat[i]=(i<<1)+1<m+n?dat[(i<<1)+1]:du;}
	}
	private bool CoMax(Dt x,Dt y){return x.d>y.d;}
	private bool CoMin(Dt x,Dt y){return x.d<y.d;}
	public void Ud(int q,long b){
		q+=m;
		if(ku){b+=dat[q].d;}
		dat[q].d=du.d;
		dat[q]=new Dt(b,q-m);
		q=(q-1)>>1;
		while(q>=0){
			Dt o=compare(dat[2*q+1],dat[2*q+2])?dat[2*q+1]:dat[2*q+2];
			if(dat[q]==o){break;}
			dat[q]=o;
			q=(q-1)>>1;
		}
	}
	private Dt Fdg(int a,int b,int k,int l,int r){
		if(r<a||b<l){return du;}
		if(a<=l&&r<=b){return dat[k];}
		Dt p=Fdg(a,b,k*2+1,l,(l+r)>>1);
		Dt q=Fdg(a,b,k*2+2,(l+r+1)>>1,r);
		return compare(p,q)?p:q;
	}
	public Dt Get(int a,int b){return Fdg(a,b,0,0,m);}
}

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