結果
| 問題 | No.631 Noelちゃんと電車旅行 |
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-01-08 15:24:37 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 642 ms / 2,000 ms |
| コード長 | 1,660 bytes |
| 記録 | |
| コンパイル時間 | 1,093 ms |
| コンパイル使用メモリ | 103,808 KB |
| 実行使用メモリ | 8,552 KB |
| 最終ジャッジ日時 | 2024-06-12 23:22:49 |
| 合計ジャッジ時間 | 10,040 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto t=readln.split.to!(long[]);
assert(t.length==(n-1));
auto sqd=new SqD(t);
int q; rd(q);
while(q--){
int l, r; long d; rd(l, r, d);
sqd.radd(l-1, r, d);
writeln(sqd.rmax(0, n-1));
}
}
class SqD{
int sz=1, k=1;
long[] buc, bucmax, laz;
import std.algorithm;
this(long[] a){
auto n=a.length;
while(sz*sz<n) sz++;
bucmax.length=laz.length=sz;
buc.length=(sz*sz);
foreach(i; 0..n) buc[i]=a[i]+(n-i)*3;
foreach(i; 0..sz) bucmax[i]=reduce!(max)(buc[(i*sz)..((i+1)*sz)]);
}
void push(int i){
if(laz[i]>0){
buc[(i*sz)..((i+1)*sz)]+=laz[i];
laz[i]=0;
}
}
void radd(int l, int r, long x){
for(auto i=l/sz; i<=r/sz && i*sz<sz*sz; i++){
if(l<=i*sz && (i+1)*sz<=r){
bucmax[i]+=x; laz[i]+=x;
}else{
push(i);
auto s=max(l, i*sz), t=min(r, (i+1)*sz);
buc[s..t]+=x;
if(s<t) bucmax[i]=reduce!(max)(buc[(i*sz)..((i+1)*sz)]);
}
}
}
long rmax(int l, int r){
long ret=0;
for(auto i=l/sz; i<=r/sz && i*sz<sz*sz; i++){
if(l<=i*sz && (i+1)*sz<=r){
ret=max(ret, bucmax[i]);
}else{
push(i);
auto s=max(l, i*sz), t=min(r, (i+1)*sz);
if(s<t) ret=max(ret, reduce!(max)(buc[s..t]));
}
}
return ret;
}
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
}
ikd