結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
fgwiebfaoish
|
| 提出日時 | 2019-12-16 01:33:16 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,115 bytes |
| コンパイル時間 | 2,485 ms |
| コンパイル使用メモリ | 109,312 KB |
| 実行使用メモリ | 45,428 KB |
| 最終ジャッジ日時 | 2024-07-02 18:48:57 |
| 合計ジャッジ時間 | 11,865 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 WA * 9 |
コンパイルメッセージ
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.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;}
}
fgwiebfaoish