結果
問題 |
No.631 Noelちゃんと電車旅行
|
ユーザー |
|
提出日時 | 2020-10-16 17:07:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 828 bytes |
コンパイル時間 | 1,980 ms |
コンパイル使用メモリ | 195,260 KB |
最終ジャッジ日時 | 2025-01-15 07:50:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:31:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | rep(i,n-1) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:41:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | int q; scanf("%d",&q); | ~~~~~^~~~~~~~~ main.cpp:44:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | 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; template<class G> class Fenwick_tree_dual{ vector<G> a; public: Fenwick_tree_dual(int n):a(n){} void add(int l,int r,const G& val){ if(l==0){ for(;r>0;r-=r&-r) a[r-1]+=val; return; } add(0,r,val); add(0,l,-val); } G sum(int i)const{ G res{}; for(i++;i<=a.size();i+=i&-i) res+=a[i-1]; return res; } }; int main(){ int n; scanf("%d",&n); vector<lint> a(n-1); rep(i,n-1) scanf("%lld",&a[i]); lint t=0; for(int i=1;i<n;i++){ t=max(a[i],t)+3; } Fenwick_tree_dual<lint> F(n-1); rep(i,n-1) F.add(i,i+1,a[i]); int q; scanf("%d",&q); rep(_,q){ int l,r; lint d; scanf("%d%d%lld",&l,&r,&d); l--; F.add(l,r,d); t=max(t,F.sum(l)+3*(n-l-1)); printf("%lld\n",t); } return 0; }