結果

問題 No.999 てん vs. ほむ
ユーザー outlineoutline
提出日時 2020-02-28 21:45:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,637 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 112,992 KB
実行使用メモリ 11,456 KB
最終ジャッジ日時 2024-04-21 18:14:35
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 4 ms
5,376 KB
testcase_09 AC 80 ms
11,452 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 37 ms
7,296 KB
testcase_13 AC 86 ms
11,412 KB
testcase_14 AC 86 ms
11,392 KB
testcase_15 AC 84 ms
11,392 KB
testcase_16 AC 85 ms
11,360 KB
testcase_17 AC 74 ms
11,432 KB
testcase_18 AC 73 ms
11,300 KB
testcase_19 AC 74 ms
11,440 KB
testcase_20 AC 76 ms
11,456 KB
testcase_21 AC 89 ms
11,364 KB
testcase_22 AC 86 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    int sz = n * 2;
    SegmentTree<ll> evenseg(sz, [](ll a, ll b){return a + b;}, 0);
    SegmentTree<ll> oddseg(sz, [](ll a, ll b){return a + b;}, 0);
    for(int i = 0; i < sz; ++i){
        ll input;
        if(i % 2 == 0){
            cin >> input;
            evenseg.update(i, input);
        }
        else{
            cin >> input;
            oddseg.update(i, input);
        }
    }

    ll res = -1e+16;
    for(int i = 0; i <= sz; i += 2){
        ll foo = evenseg.query(0, i) + oddseg.query(i, sz);
        ll bar = evenseg.query(i, sz) + oddseg.query(0, i);
        chmax(res, foo - bar);
    }
    cout << res << endl;
}
0