結果

問題 No.631 Noelちゃんと電車旅行
ユーザー a_kawashiro
提出日時 2018-01-06 09:43:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 2,268 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 114,388 KB
最終ジャッジ日時 2025-01-05 07:07:09
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 | #define GI(i) (scanf("%d",&i))
      |               ~~~~~~^~~~~~~~~~
main.cpp:69:11: note: in expansion of macro ‘GI’
   69 |     int N;GI(N);
      |           ^~
main.cpp:20:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 | #define GI(i) (scanf("%d",&i))
      |               ~~~~~~^~~~~~~~~~
main.cpp:72:15: note: in expansion of macro ‘GI’
   72 |         int t;GI(t);sg.add(i,i+1,t-3*i);
      |               ^~
main.cpp:20:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 | #define GI(i) (scanf("%d",&i))
      |               ~~~~~~^~~~~~~~~~
main.cpp:74:11: note: in expansion of macro ‘GI’
   74 |     int M;GI(M);
      |           ^~
main.cpp:20:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 | #define GI(i) (scanf("%d",&i))
      |               ~~~~~~^~~~~~~~~~
main.cpp:76:22: note: in expansion of macro ‘GI’
   76 |         int l,r;LL d;GI(l);GI(r);GLL(d);
      |                      ^~
main.cpp:20:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 | #define GI(i) (scanf("%d",&i))
      |               ~~~~~~^~~~~~~~~~
main.cpp:76:28: note: in expansion of macro ‘GI’
   76 |         int l,r;LL d;GI(l);GI(r);GLL(d);
      |                            ^~
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 | #define GLL(i) (scanf("%lld",&i))
      |                

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

class RangeAddRangeMax {
    public:
        int N;
        vector<LL> dat, sum_dat;
        RangeAddRangeMax(int n) {
            N = 1;
            while(N < n) N <<= 1;
            dat.assign(2*N-1, 0);
            sum_dat.assign(2*N-1, 0);
        }

        void add(int a, int b, LL x) { add(a,b,x,0,0,N); }
        LL add(int a, int b, LL x, int k, int l, int r) {
            if(b <= l or r <= a) return dat[k];
            if(a <= l and r <= b) {
                sum_dat[k] += x;
                return dat[k] += x;
            }
            const int m = (l+r)/2;
            return dat[k] = max(add(a,b,x,2*k+1,l,m),add(a,b,x,2*k+2,m,r))+sum_dat[k];
        }

        LL rangeMax(int a, int b) { return rangeMax(a,b,0,0,N); }
        LL rangeMax(int a, int b, int k, int l, int r) {
            if(b <= l or r <= a) return 0;
            if(a <= l and r <= b) return dat[k];
            const int m = (l+r)/2;
            return max(rangeMax(a,b,2*k+1,l,m),rangeMax(a,b,2*k+2,m,r))+sum_dat[k];
        }
};

int main(void){
    int N;GI(N);
    RangeAddRangeMax sg(N);
    REP(i,N-1){
        int t;GI(t);sg.add(i,i+1,t-3*i);
    }
    int M;GI(M);
    REP(i,M){
        int l,r;LL d;GI(l);GI(r);GLL(d);
        sg.add(l-1,r,d);
        printf("%lld\n",sg.rangeMax(0,N-1)+(N-1)*3);
    }
    return 0;
}
0