結果
問題 |
No.631 Noelちゃんと電車旅行
|
ユーザー |
|
提出日時 | 2020-10-16 17:26:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 1,217 bytes |
コンパイル時間 | 2,107 ms |
コンパイル使用メモリ | 201,588 KB |
最終ジャッジ日時 | 2025-01-15 07:50:45 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:44:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:46:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | rep(i,n-1) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:51:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | int q; scanf("%d",&q); | ~~~~~^~~~~~~~~ main.cpp:54:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | lint d; scanf("%d%d%lld",&l,&r,&d); l--; | ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; class starry_sky_tree{ int n; vector<lint> dat1,dat2; void add(int l,int r,int a,int b,int u,lint val){ if(b<=l || r<=a) return; if(l<=a && b<=r){ dat1[u]+=val; return; } add(l,r,a,(a+b)/2,2*u+1,val); add(l,r,(a+b)/2,b,2*u+2,val); dat2[u]=max(dat2[2*u+1]+dat1[2*u+1],dat2[2*u+2]+dat1[2*u+2]); } lint query_max(int l,int r,int a,int b,int u){ if(b<=l || r<=a) return 0; if(l<=a && b<=r) return dat1[u]+dat2[u]; lint res1=query_max(l,r,a,(a+b)/2,2*u+1); lint res2=query_max(l,r,(a+b)/2,b,2*u+2); return max(res1,res2)+dat1[u]; } public: starry_sky_tree(int N){ for(n=1;n<N;n*=2); dat1.assign(2*n,0); dat2.assign(2*n,0); } void add(int l,int r,lint val){ add(l,r,0,n,0,val); } lint query_max(int l,int r){ return query_max(l,r,0,n,0); } }; int main(){ int n; scanf("%d",&n); vector<lint> a(n-1); rep(i,n-1) scanf("%lld",&a[i]); starry_sky_tree SS(n-1); rep(i,n-1) SS.add(i,i+1,a[i]+3*(n-i-1)); int q; scanf("%d",&q); rep(_,q){ int l,r; lint d; scanf("%d%d%lld",&l,&r,&d); l--; SS.add(l,r,d); printf("%lld\n",SS.query_max(0,n-1)); } return 0; }