結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-05 22:45:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 974 ms / 2,000 ms |
| コード長 | 3,248 bytes |
| コンパイル時間 | 2,025 ms |
| コンパイル使用メモリ | 77,852 KB |
| 実行使用メモリ | 96,964 KB |
| 最終ジャッジ日時 | 2024-10-02 09:28:22 |
| 合計ジャッジ時間 | 16,417 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
static SegmentTree seg;
static void update(int x,long d){
seg.update(x,new long[]{Math.max(d,0),d});
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=sc.nextInt();
int[]t=sc.nextIntArray(n-1);
long[]ct=new long[n],dt=new long[n-1];
for(int i=0;i<n-1;++i)ct[i+1]=t[i]+3*(n-i-1);
for(int i=0;i<n-1;++i)dt[i]=ct[i+1]-ct[i];
int m=sc.nextInt();
seg=new SegmentTree();
for(int i=0;i<n-1;++i)update(i,dt[i]);
for(int i=0;i<m;++i){
int l=sc.nextInt();
int r=sc.nextInt();
long d=sc.nextInt();
dt[l-1]+=d;
update(l-1,dt[l-1]);
if(r<n-1){
dt[r]-=d;
update(r,dt[r]);
}
long[]res=seg.query(0,n-1);
out.println(res[0]);
}
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n){
int[]r=new int[n];
for(int i=0;i<n;++i)r[i]=nextInt();
return r;
}
}
}
class SegmentTree {
static final int SIZE = 1 << 18;
long[][] seg;
SegmentTree() {
this.seg = new long[2 * SIZE][2];
}
static long[]comb(long[] a,long[] b){
long dif=a[1]+b[1];
long max=Math.max(a[0],a[1]+b[0]);
return new long[]{max,dif};
}
void update(int x, long[] value) {
x += SIZE - 1;
for(int i=0;i<2;++i)
seg[x][i]=value[i];
while (x > 0) {
x = (x - 1) / 2;
this.seg[x] = comb(this.seg[2 * x + 1], this.seg[2 * x + 2]);
}
}
long[] query(int a,int b,int l,int r,int k){
if(a<=l&&r<=b)return seg[k];
if(b<=l||r<=a)
return new long[]{0,0};
return comb(query(a,b,l,(l+r)/2,2*k+1),query(a,b,(l+r)/2,r,2*k+2));
}
long[] query(int l, int r) {
return query(l,r,0,SIZE,0);
}
}
夕叢霧香(ゆうむらきりか)