結果

問題 No.999 てん vs. ほむ
ユーザー monkukui2monkukui2
提出日時 2020-02-28 21:33:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 3,233 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 100,236 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-21 17:59:38
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 104 ms
8,704 KB
testcase_10 AC 32 ms
5,376 KB
testcase_11 AC 22 ms
5,376 KB
testcase_12 AC 48 ms
6,016 KB
testcase_13 AC 115 ms
8,832 KB
testcase_14 AC 113 ms
8,832 KB
testcase_15 AC 115 ms
8,832 KB
testcase_16 AC 114 ms
8,960 KB
testcase_17 AC 83 ms
8,704 KB
testcase_18 AC 80 ms
8,704 KB
testcase_19 AC 81 ms
8,960 KB
testcase_20 AC 81 ms
8,832 KB
testcase_21 AC 112 ms
8,832 KB
testcase_22 AC 108 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

// quoted from beet-aizu
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    // using F = function<T(T, T)>
    // using G = function<T(T, E)>
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

    /* TODO わからない 聞く 
    template<typename C>
    int find(int a,int b,C &check,int k,int l,int r){
        if(!check(dat[k])||r<=a||b<=l) return -1;
        if(k>=n) return k-n;
        int m=(l+r)>>1;
        int vl=find(a,b,check,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(a,b,check,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int a,int b,C &check){
        return find(a,b,check,1,0,n);
    }*/
    
};


int main(){
  using T = lint;  // type T
  using E = lint;  // type E
  auto f = [](T a, T b){ // return type T value
    return a + b;
  };
  auto g = [](T a, E b){ // return type T value
    return b;  // return b;
  };
  T ti = 0;  // identify element
  int n; cin >> n;
  vector<lint> a(n);
  vector<lint> b(n);
  for(int i = 0; i < n; i++) {
    int aa, bb; cin >> aa >> bb;
    a[i] = aa;
    b[i] = bb;
  }
  SegmentTree<T, E, decltype(f), decltype(g)> sg1(f, g, ti);  // don't change
  sg1.build(a);   // 初期配列を代入
  SegmentTree<T, E, decltype(f), decltype(g)> sg2(f, g, ti);  // don't change
  sg2.build(b);   // 初期配列を代入
  
  lint ans = -INF;
  for(int i = 0; i <= n; i++) {
    lint homu = sg1.query(0, i) + sg2.query(i, n);
    lint pura = sg2.query(0, i) + sg1.query(i, n);
    ans = max(ans, homu - pura);
  }

  cout << ans << endl;
  return 0;
}
0