結果
問題 | No.1332 Range Nearest Query |
ユーザー | fgwiebfaoish |
提出日時 | 2021-01-08 22:50:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,486 ms / 2,500 ms |
コード長 | 5,482 bytes |
コンパイル時間 | 5,620 ms |
コンパイル使用メモリ | 108,160 KB |
実行使用メモリ | 99,832 KB |
最終ジャッジ日時 | 2024-11-16 14:25:50 |
合計ジャッジ時間 | 53,752 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
17,792 KB |
testcase_01 | AC | 26 ms
17,920 KB |
testcase_02 | AC | 26 ms
17,920 KB |
testcase_03 | AC | 1,387 ms
90,108 KB |
testcase_04 | AC | 1,407 ms
90,480 KB |
testcase_05 | AC | 1,412 ms
90,612 KB |
testcase_06 | AC | 1,158 ms
97,784 KB |
testcase_07 | AC | 1,147 ms
97,920 KB |
testcase_08 | AC | 1,148 ms
97,656 KB |
testcase_09 | AC | 1,156 ms
97,712 KB |
testcase_10 | AC | 1,147 ms
97,912 KB |
testcase_11 | AC | 1,154 ms
97,800 KB |
testcase_12 | AC | 1,142 ms
97,880 KB |
testcase_13 | AC | 1,153 ms
97,916 KB |
testcase_14 | AC | 1,139 ms
97,856 KB |
testcase_15 | AC | 1,147 ms
97,784 KB |
testcase_16 | AC | 1,476 ms
99,780 KB |
testcase_17 | AC | 1,472 ms
99,644 KB |
testcase_18 | AC | 1,457 ms
99,712 KB |
testcase_19 | AC | 1,452 ms
99,512 KB |
testcase_20 | AC | 1,468 ms
99,508 KB |
testcase_21 | AC | 1,477 ms
99,720 KB |
testcase_22 | AC | 1,486 ms
99,768 KB |
testcase_23 | AC | 1,476 ms
99,636 KB |
testcase_24 | AC | 1,473 ms
99,832 KB |
testcase_25 | AC | 1,470 ms
99,756 KB |
testcase_26 | AC | 643 ms
91,892 KB |
testcase_27 | AC | 619 ms
95,360 KB |
testcase_28 | AC | 224 ms
22,272 KB |
testcase_29 | AC | 227 ms
22,528 KB |
testcase_30 | AC | 231 ms
22,400 KB |
testcase_31 | AC | 216 ms
22,400 KB |
testcase_32 | AC | 235 ms
22,272 KB |
testcase_33 | AC | 230 ms
22,272 KB |
testcase_34 | AC | 220 ms
22,528 KB |
testcase_35 | AC | 223 ms
22,400 KB |
testcase_36 | AC | 219 ms
22,272 KB |
testcase_37 | AC | 230 ms
22,400 KB |
testcase_38 | AC | 1,239 ms
64,736 KB |
testcase_39 | AC | 459 ms
28,416 KB |
testcase_40 | AC | 1,455 ms
97,280 KB |
testcase_41 | AC | 885 ms
39,636 KB |
testcase_42 | AC | 1,190 ms
62,580 KB |
testcase_43 | AC | 1,052 ms
49,844 KB |
testcase_44 | AC | 1,342 ms
83,936 KB |
testcase_45 | AC | 1,289 ms
77,364 KB |
testcase_46 | AC | 1,143 ms
58,684 KB |
testcase_47 | AC | 1,264 ms
71,100 KB |
コンパイルメッセージ
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; 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=sc.I; var a=sc.Ia; var q=sc.I; var wm=new Wm(a); StringBuilder sb=new StringBuilder(); for(int i = 0;i<q;i++) { var e=sc.Ia; int b=wm.Pv(e[0]-1,e[1]-1,e[2]+1); int c=wm.Nv(e[0]-1,e[1]-1,e[2]-1); if(b<0){b=mod;} else{b=e[2]-b;} if(c<0){c=mod;} else{c=c-e[2];} sb.Append(Min(b,c)+"\n"); } Console.Write(sb); } } public class Wm{ private int[][] ra; private int[] za; private const int b=30; private int n; public Wm(int[] a){ n=a.Length; var d=new int[b+1][]; ra=new int[b+1][]; for(int i = 0;i<=b;i++) { d[i]=new int[n]; ra[i]=new int[n+1]; } var d0=new int[2][]{new int[n],new int[n]}; var d1=new int[2][]{new int[n],new int[n]}; var h0=new int[]{0,0}; var h1=new int[]{0,0}; za=new int[b+1]; for(int i = 0;i<n;i++) { if((a[i]&(1<<b))==0){ d0[1][h0[1]]=a[i]; h0[1]++; za[b]++; } else{ d1[1][h1[1]]=a[i]; h1[1]++; d[b][i]=ra[b][i+1]=1; } ra[b][i+1]+=ra[b][i]; } for(int i = 1;i<=b;i++) { int g=(1<<(b-i)),p=i&1; h0[p^1]=h1[p^1]=0; for(int j = 0;j<h0[p];j++) { if((d0[p][j]&g)==0){ d0[p^1][h0[p^1]]=d0[p][j]; h0[p^1]++; za[b-i]++; } else{ d1[p^1][h1[p^1]]=d0[p][j]; h1[p^1]++; d[b-i][j]=ra[b-i][j+1]=1; } ra[b-i][j+1]+=ra[b-i][j]; } for(int j = 0;j<h1[p];j++) { if((d1[p][j]&g)==0){ d0[p^1][h0[p^1]]=d1[p][j]; h0[p^1]++; za[b-i]++; } else{ d1[p^1][h1[p^1]]=d1[p][j]; h1[p^1]++; d[b-i][h0[p]+j]=ra[b-i][h0[p]+j+1]=1; } ra[b-i][h0[p]+j+1]+=ra[b-i][h0[p]+j]; } } } public int Rk(int l,int r,long k){ l--; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return r-l; } public int Rl(int l,int r,long k){ l--; int p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ p+=r-l; r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; p-=r-l; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return p; } public int Rm(int l,int r,long k){ l--; int p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; } else{ p+=r-l; r=r-ra[i][r+1]; l=l-ra[i][l+1]; p-=r-l; } } return p; } public int Qt(int l,int r,int k){ l--; int p=0; for(int i = b;i>=0;i--) { if((r-ra[i][r+1])-(l-ra[i][l+1])<k){ k-=(r-ra[i][r+1])-(l-ra[i][l+1]); r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; p|=1<<i; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return p; } public int Pv(int l,int r,int k){ int p=Rl(l,r,k); return p!=0?Qt(l,r,p):-1; } public int Nv(int l,int r,int k){ int p=Rm(l,r,k); return p!=0?Qt(l,r,r-l+1-p+1):-1; } } 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]));} private T Ct<T>(string s){return (T)Convert.ChangeType(s,typeof(T));} }