結果
問題 |
No.3214 small square
|
ユーザー |
|
提出日時 | 2025-07-25 21:57:38 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 2,501 ms / 3,000 ms |
コード長 | 15,295 bytes |
コンパイル時間 | 7,776 ms |
コンパイル使用メモリ | 171,176 KB |
実行使用メモリ | 197,384 KB |
最終ジャッジ日時 | 2025-07-25 21:59:04 |
合計ジャッジ時間 | 76,109 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (93 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using Lib; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static Lib.Functions; using static Lib.OutputLib; public class Solver { const bool MultiTestCase = false; void Solve() { int n = ri, a = ri; ReadArray(out (int x, int y, long v)[] ps, n, () => (ri, ri, rl)); Array.Sort(ps); long Calc(int ax, int ay) { var comp = new Compress<int>(); foreach (var (x, y, v) in ps) { comp.Add(y); comp.Add(y + ay); } comp.Build(); var xs = new List<int>(); foreach (var (x, y, v) in ps) { xs.Add(x); xs.Add(x + ax); } xs.Sort(); long ans = 0; var seg = new LazySegTree<long, long, Op>(new long[comp.Count]); for (int i = 0, i1 = 0, i2 = 0; i < xs.Count; i++) { int x = xs[i]; while (i1 < n && ps[i1].x <= x) { var (_, y, v) = ps[i1++]; seg.Apply(comp.GetIndex(y), comp.GetIndex(y + ay), v); } while (i2 < n && ps[i2].x + ax <= x) { var (_, y, v) = ps[i2++]; seg.Apply(comp.GetIndex(y), comp.GetIndex(y + ay), -v); } Chmax(ref ans, seg.Prod(0, comp.Count)); } return ans; } long ans = 0; for (int f = 0; f < 4; f++) Chmax(ref ans, Calc(a + (f & 1), a + (f >> 1))); Write(ans); } struct Op : ILazySegTreeOperator<long, long> { public long Identity => 0; public long Operate(long x, long y) => Math.Max(x, y); public long FIdentity => 0; public long Mapping(long f, long x) => f + x; public long Composition(long f, long g) => f + g; } #pragma warning disable CS0162, CS8618 public Solver() { if (!MultiTestCase) Solve(); else for (int t = ri; t > 0; t--) Solve(); } #pragma warning restore CS0162, CS8618 const int IINF = 1 << 30; const long INF = 1L << 60; int ri { [MethodImpl(256)] get => (int)sc.Integer(); } long rl { [MethodImpl(256)] get => sc.Integer(); } uint rui { [MethodImpl(256)] get => (uint)sc.UInteger(); } ulong rul { [MethodImpl(256)] get => sc.UInteger(); } double rd { [MethodImpl(256)] get => sc.Double(); } string rs { [MethodImpl(256)] get => sc.Scan(); } string rline { [MethodImpl(256)] get => sc.Line(); } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); void ReadArray(out int[] a, int n) { a = new int[n]; for (int i = 0; i < a.Length; i++) a[i] = ri; } void ReadArray(out long[] a, int n) { a = new long[n]; for (int i = 0; i < a.Length; i++) a[i] = rl; } void ReadArray<T>(out T[] a, int n, Func<T> read) { a = new T[n]; for (int i = 0; i < a.Length; i++) a[i] = read(); } void ReadArray<T>(out T[] a, int n, Func<int, T> read) { a = new T[n]; for (int i = 0; i < a.Length; i++) a[i] = read(i); } } static class Program { static public void Main(string[] args) { SourceExpander.Expander.Expand(); Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(); Console.Out.Flush(); } } #region Expanded by https://github.com/kzrnm/SourceExpander public class Compress<T>where T:notnull,IComparable<T>{public int Count{get;private set;}=0;private readonly HashSet<T>_set;private readonly Dictionary<T,int>_dic;private T[]_data;public Compress(){_set=new HashSet<T>();_dic=new Dictionary<T,int>();}public Compress(ReadOnlySpan<T>a){_set=new HashSet<T>();_dic=new Dictionary<T,int>();foreach(var v in a)Add(v);Build();}public void Add(T x)=>_set.Add(x);public void Build(){Count=_set.Count;_dic.Clear();_data=_set.ToArray();Array.Sort(_data);for(int i=0;i<_data.Length;i++)_dic.Add(_data[i],i);}public int GetIndex(T x)=>_dic[x];public T this[int i]{get=>_data[i];}public bool Contains(T x)=>_set.Contains(x);public int LowerBound(T v){int n=_data.Length;if(n==0)return-1;int l=0,r=n;while(l<r){int x=(l+r)/2;if(_data[x].CompareTo(v)<0)l=x+1;else r=x;}return l;}public int UpperBound(T v){int n=_data.Length;if(n==0)return-1;int l=0,r=n;while(l<r){int x=(l+r)/2;if(_data[x].CompareTo(v)<=0)l=x+1;else r=x;}return l;}} public interface ILazySegTreeOperator<T,F>{T Identity{get;}F FIdentity{get;}T Operate(T x,T y);T Mapping(F f,T x);F Composition(F f,F g);} public class LazySegTree<T,F,Op>where Op:struct,ILazySegTreeOperator<T,F>{protected static readonly Op op=default;public int Length{get;}protected readonly int size,log;protected readonly T[]d;protected readonly F[]lz;public LazySegTree(int n){Length=n;log=0;while((1<<log)<Length)log++;size=1<<log;d=new T[2*size];lz=new F[size];Array.Fill(d,op.Identity);Array.Fill(lz,op.FIdentity);}public LazySegTree(T[]v):this(v.Length){for(int i=0;i<v.Length;i++)d[size+i]=v[i];for(int i=size-1;i>=1;i--)Update(i);}[MethodImpl(256)]public void Clear(){Array.Fill(d,op.Identity);Array.Fill(lz,op.FIdentity);}[MethodImpl(256)]public void Set(int p,T x){p+=size;for(int i=log;i>=1;i--)Push(p>>i);d[p]=x;for(int i=1;i<=log;i++)Update(p>>i);}[MethodImpl(256)]public T Get(int p){p+=size;for(int i=log;i>=1;i--)Push(p>>i);return d[p];}[MethodImpl(256)]public T Prod(int l,int r){if(l==r)return op.Identity;l+=size;r+=size;for(int i=log;i>=1;i--){if(((l>>i)<<i)!=l)Push(l>>i);if(((r>>i)<<i)!=r)Push((r-1)>>i);}T sml=op.Identity,smr=op.Identity;while(l<r){if((l&1)!=0)sml=op.Operate(sml,d[l++]);if((r&1)!=0)smr=op.Operate(d[ --r],smr);l>>=1;r>>=1;}return op.Operate(sml,smr);}public T AllProd()=>d[1];[MethodImpl(256)]public void Apply(int p,F f){p+=size;for(int i=log;i>=1;i--)Push(p>>i);d[p]=op.Mapping(f,d[p]);for(int i=1;i<=log;i++)Update(p>>i);}[MethodImpl(256)]public void Apply(int l,int r,F f){if(l>=r)return;l+=size;r+=size;for(int i=log;i>=1;i--){if(((l>>i)<<i)!=l)Push(l>>i);if(((r>>i)<<i)!=r)Push((r-1)>>i);}{int l2=l,r2=r;while(l<r){if((l&1)!=0)AllApply(l++,f);if((r&1)!=0)AllApply( --r,f);l>>=1;r>>=1;}l=l2;r=r2;}for(int i=1;i<=log;i++){if(((l>>i)<<i)!=l)Update(l>>i);if(((r>>i)<<i)!=r)Update((r-1)>>i);}}[MethodImpl(256)]protected void Update(int k)=>d[k]=op.Operate(d[2*k],d[2*k+1]);[MethodImpl(256)]protected virtual void AllApply(int k,F f){d[k]=op.Mapping(f,d[k]);if(k<size)lz[k]=op.Composition(f,lz[k]);}[MethodImpl(256)]protected void Push(int k){AllApply(2*k,lz[k]);AllApply(2*k+1,lz[k]);lz[k]=op.FIdentity;}[MethodImpl(256)]public int MaxRight(int l,Predicate<T>f){if(l==Length)return Length;l+=size;for(int i=log;i>=1;i--)Push(l>>i);var s=op.Identity;do{while(l%2==0)l>>=1;if(!f(op.Operate(s,d[l]))){while(l<size){Push(l);l<<=1;if(f(op.Operate(s,d[l]))){s=op.Operate(s,d[l]);l++;}}return l-size;}s=op.Operate(s,d[l]);l++;}while((l&-l)!=l);return Length;}[MethodImpl(256)]public int MinLeft(int r,Predicate<T>f){if(r==0)return 0;r+=size;for(int i=log;i>=1;i--)Push((r-1)>>i);var s=op.Identity;do{r--;while(r>1&&(r%2)!=0)r>>=1;if(!f(op.Operate(d[r],s))){while(r<size){Push(r);r=(r<<1)|1;if(f(op.Operate(d[r],s))){s=op.Operate(d[r],s);r--;}}return r+1-size;}s=op.Operate(d[r],s);}while((r&-r)!=r);return 0;}} namespace Lib{public static class Functions{[MethodImpl(256)]public static int Popcount(ulong x){x=(x&0x5555555555555555UL)+((x>>1)&0x5555555555555555UL);x=(x&0x3333333333333333UL)+((x>>2)&0x3333333333333333UL);x=(x&0x0f0f0f0f0f0f0f0fUL)+((x>>4)&0x0f0f0f0f0f0f0f0fUL);x=(x&0x00ff00ff00ff00ffUL)+((x>>8)&0x00ff00ff00ff00ffUL);x=(x&0x0000ffff0000ffffUL)+((x>>16)&0x0000ffff0000ffffUL);x=(x&0x00000000ffffffffUL)+((x>>32)&0x00000000ffffffffUL);return(int)x;}[MethodImpl(256)]public static int Popcount(long x){x=(x&0x5555555555555555L)+((x>>1)&0x5555555555555555L);x=(x&0x3333333333333333L)+((x>>2)&0x3333333333333333L);x=(x&0x0f0f0f0f0f0f0f0fL)+((x>>4)&0x0f0f0f0f0f0f0f0fL);x=(x&0x00ff00ff00ff00ffL)+((x>>8)&0x00ff00ff00ff00ffL);x=(x&0x0000ffff0000ffffL)+((x>>16)&0x0000ffff0000ffffL);x=(x&0x00000000ffffffffL)+((x>>32)&0x00000000ffffffffL);return(int)x;}[MethodImpl(256)]public static int Popcount(int x){x=(x&0x55555555)+((x>>1)&0x55555555);x=(x&0x33333333)+((x>>2)&0x33333333);x=(x&0x0f0f0f0f)+((x>>4)&0x0f0f0f0f);x=(x&0x00ff00ff)+((x>>8)&0x00ff00ff);x=(x&0x0000ffff)+((x>>16)&0x0000ffff);return x;}[MethodImpl(256)]public static int Ctz(long x){if(x==0)return-1;return Popcount((ulong)((x&-x)-1));}[MethodImpl(256)]public static int CeilPow2(int n){int x=0;while((1<<x)<n)x++;return x;}[MethodImpl(256)]public static int SafeMod(int x,int m){int r=x%m;return r<0?r+Math.Abs(m):r;}[MethodImpl(256)]public static long SafeMod(long x,long m){long r=x%m;return r<0?r+Math.Abs(m):r;}[MethodImpl(256)]public static bool IsIncreasing(long a,long b,long c)=>a<=b&&b<=c;[MethodImpl(256)]public static int Sign(long x)=>x==0?0:(x<0?-1:1);[MethodImpl(256)]public static int Sign(double x)=>x==0?0:(x<0?-1:1);[MethodImpl(256)]public static int DigitSum(long n,int d=10){long s=0;while(n>0){s+=n%d;n/=d;}return(int)s;}[MethodImpl(256)]public static long Floor(long a,long b)=>a>=0?a/b:(a+1)/b-1;[MethodImpl(256)]public static long Ceil(long a,long b)=>a>0?(a-1)/b+1:a/b;[MethodImpl(256)]public static long Gcd(long a,long b){if(a==0)return Math.Abs(b);if(b==0)return Math.Abs(a);if(a<0)a=-a;if(b<0)b=-b;int u=Ctz(a);int v=Ctz(b);a>>=u;b>>=v;while(a!=b){if(a<b)(a,b)=(b,a);a-=b;a>>=Ctz(a);}return a<<Math.Min(u,v);}[MethodImpl(256)]public static(long x,long y,long g)ExtGcd(long a,long b){if(b==0)return(Sign(a),0,Math.Abs(a));long c=SafeMod(a,b);var(x2,y2,g)=ExtGcd(b,c);long x=SafeMod(y2,b);long y=(g-a*x)/b;return(x,y,g);}[MethodImpl(256)]public static void Swap(ref int x,ref int y){x^=y;y^=x;x^=y;}[MethodImpl(256)]public static void Swap(ref long x,ref long y){x^=y;y^=x;x^=y;}[MethodImpl(256)]public static void Swap<T>(ref T x,ref T y){T t=y;y=x;x=t;}[MethodImpl(256)]public static T Clamp<T>(T x,T l,T r)where T:IComparable<T> =>x.CompareTo(l)<=0?l:(x.CompareTo(r)<=0?x:r);[MethodImpl(256)]public static T Clamp<T>(ref T x,T l,T r)where T:IComparable<T> =>x=x.CompareTo(l)<=0?l:(x.CompareTo(r)<=0?x:r);[MethodImpl(256)]public static void Chmin<T>(ref T x,T y)where T:IComparable<T>{if(x.CompareTo(y)>0)x=y;}[MethodImpl(256)]public static void Chmax<T>(ref T x,T y)where T:IComparable<T>{if(x.CompareTo(y)<0)x=y;}[MethodImpl(256)]public static int LowerBound(long[]arr,long val,int l=-1,int r=-1)=>LowerBound(arr.AsSpan(),t=>Sign(t-val),l,r);[MethodImpl(256)]public static int LowerBound(int[]arr,int val,int l=-1,int r=-1)=>LowerBound(arr.AsSpan(),t=>t-val,l,r);[MethodImpl(256)]public static int LowerBound<T>(T[]arr,T val,int l=-1,int r=-1)where T:IComparable<T> =>LowerBound(arr.AsSpan(),t=>t.CompareTo(val),l,r);[MethodImpl(256)]public static int LowerBound<T>(T[]arr,Func<T,int>comp,int l=-1,int r=-1)=>LowerBound(arr.AsSpan(),comp,l,r);[MethodImpl(256)]public static int LowerBound<T>(Span<T>data,Func<T,int>comp,int l=-1,int r=-1){if(data.Length==0)return-1;if(l==-1)l=0;if(r==-1)r=data.Length;while(l<r){int x=(l+r)/2;if(comp(data[x])<0)l=x+1;else r=x;}return l;}[MethodImpl(256)]public static int RangeCount<T>(T[]arr,T geq,T lt,int l=-1,int r=-1)where T:IComparable<T> =>Math.Max(0,LowerBound(arr.AsSpan(),t=>t.CompareTo(lt),l,r)-LowerBound(arr.AsSpan(),t=>t.CompareTo(geq),l,r));[MethodImpl(256)]public static string ToBase2(long v,int digit=-1){if(digit==-1){digit=0;while((v>>digit)>0)digit++;}var c=new string[digit];for(int i=0;i<digit;i++)c[digit-1-i]=((v>>i)&1)==0?"0":"1";return string.Join("",c);}[MethodImpl(256)]public static string ToBaseN(long v,int n,int digit=-1){if(digit==-1){digit=0;long pow=1;while(v>=pow){digit++;pow*=n;}}var c=new int[digit];for(int i=0;i<digit;i++,v/=n)c[digit-1-i]=(int)(v%n);return string.Join("",c);}}} namespace Lib{public partial class StreamScanner{public StreamScanner(Stream stream){str=stream;}private readonly Stream str;private readonly byte[]buf=new byte[1024];private int len,ptr;public bool isEof=false;public bool IsEndOfStream{get{return isEof;}}[MethodImpl(256)]private byte Read(){if(isEof)throw new EndOfStreamException();if(ptr>=len){ptr=0;if((len=str.Read(buf,0,1024))<=0){isEof=true;return 0;}}return buf[ptr++];}[MethodImpl(256)]public char Char(){byte b;do b=Read();while(b<33||126<b);return(char)b;}[MethodImpl(256)]public string Line(){var sb=new StringBuilder();for(var b=Char();b!=10&&!isEof;b=(char)Read())sb.Append(b);return sb.ToString();}[MethodImpl(256)]public string Scan(){var sb=new StringBuilder();for(var b=Char();b>=33&&b<=126;b=(char)Read())sb.Append(b);return sb.ToString();}[MethodImpl(256)]public long Integer(){long ret=0;var ng=false;byte b;do b=Read();while(b!='-'&&(b<'0'||'9'<b));if(b=='-'){ng=true;b=Read();}for(;'0'<=b&&b<='9';b=Read())ret=ret*10+(b^'0');return ng?-ret:ret;}[MethodImpl(256)]public ulong UInteger(){ulong ret=0;byte b;do b=Read();while(b<'0'||'9'<b);for(;'0'<=b&&b<='9';b=Read())ret=ret*10+(ulong)(b^'0');return ret;}[MethodImpl(256)]public double Double()=>double.Parse(Scan());}} namespace Lib{public static class OutputLib{[MethodImpl(256)]public static void WriteJoin<T>(string s,IEnumerable<T>t)=>Console.WriteLine(string.Join(s,t));[MethodImpl(256)]public static void WriteMat<T>(T[,]a,string sep=" "){int sz1=a.GetLength(0),sz2=a.GetLength(1);var b=new T[sz2];for(int i=0;i<sz1;i++){for(int j=0;j<sz2;j++)b[j]=a[i,j];WriteJoin(sep,b);}}[MethodImpl(256)]public static void WriteMat<T>(T[][]a,string sep=" "){foreach(var ar in a)WriteJoin(sep,ar);}[MethodImpl(256)]public static void WriteMat<T>(T[][]a,Func<T,string>map,string sep=" "){foreach(var ar in a)WriteJoin(sep,ar.Select(x=>map(x)));}[MethodImpl(256)]public static void Write(object t)=>Console.WriteLine(t.ToString());[MethodImpl(256)]public static void Write(params object[]arg)=>Console.WriteLine(string.Join(" ",arg.Select(x=>x.ToString())));[MethodImpl(256)]public static void Write(string str)=>Console.WriteLine(str);[MethodImpl(256)]public static void WriteFlush(object t){Console.WriteLine(t.ToString());Console.Out.Flush();}[MethodImpl(256)]public static void WriteError(object t)=>Console.Error.WriteLine(t.ToString());[MethodImpl(256)]public static void Flush()=>Console.Out.Flush();[MethodImpl(256)]public static void YN(bool t)=>Console.WriteLine(t?"YES":"NO");[MethodImpl(256)]public static void Yn(bool t)=>Console.WriteLine(t?"Yes":"No");[MethodImpl(256)]public static void yn(bool t)=>Console.WriteLine(t?"yes":"no");[MethodImpl(256)]public static void DeleteLine()=>Console.Write("\x1b[1A\x1b[2K");[MethodImpl(256)]public static void ProgressBar(long now,long total,int blocks=50){int x=(int)((2*now*blocks+1)/(2*total));Console.Write($"\x1b[G[\x1b[42m{string.Concat(Enumerable.Repeat("_",x))}\x1b[0m{string.Concat(Enumerable.Repeat("_",blocks-x))}] : {now} / {total}");}}} namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}} #endregion Expanded by https://github.com/kzrnm/SourceExpander