Submission #993656
Source Code Expand
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }
template<class N>
struct SegTree {
int lg, sz;
vector<N> n;
SegTree(int sz) {
lg = bsr(2*sz-1);
sz = 1<<lg;
this->sz = sz;
n = vector<N>(2*sz);
for (int i = 2*sz-1; i >= sz; i--) {
n[i] = N();
}
for (int i = sz-1; i >= 1; i--) {
n[i] = N(n[2*i], n[2*i+1]);
}
}
template<class Q>
Q single(int idx, Q q) {
if (idx < 0 || sz <= idx) return q;
idx += sz;
for (int i = lg; i >= 1; i--) {
int k = idx>>i;
n[k].push(n[2*k], n[2*k+1]);
}
q += n[idx];
if (q.update()) {
for (int i = 1; i <= lg; i++) {
int k = idx>>i;
n[k].update(n[2*k], n[2*k+1]);
}
}
return q;
}
template<class Q>
void query(int a, int b, Q &q, int k, int sz) {
if (a <= 0 && sz <= b) {
q += n[k];
return;
}
n[k].push(n[2*k], n[2*k+1]);
if (a < sz/2) query(a, b, q, 2*k, sz/2);
if (sz/2 < b) query(a-sz/2, b-sz/2, q, 2*k+1, sz/2);
if (q.update()) n[k].update(n[2*k], n[2*k+1]);
}
template<class Q>
Q query(int a, int b, Q q) {
if (a < sz && 0 < b) query(a, b, q, 1, sz);
return q;
}
};
struct Node {
ll ma, lz;
void init() {
ma = lz = 0;
}
Node() { init(); } // leaf
Node(Node &l, Node &r) { init(); update(l, r); }
void update(const Node &l, const Node &r) {
ma = max(l.ma, r.ma);
}
void push(Node &l, Node &r) {
if (lz) {
l.lzdata(lz);
r.lzdata(lz);
lz = 0;
}
}
void lzdata(ll x) {
ma += x; lz += x;
}
// query
struct MaxQuery {
ll ma = -TEN(18);
static constexpr bool update() { return false; }
void operator+=(Node &r) { ma = max(ma, r.ma); }
};
struct AddQuery {
ll x;
static constexpr bool update() { return true; }
void operator+=(Node &n) { n.lzdata(x); }
};
};
const int MN = 200100;
ll a[MN], as[MN];
int main() {
cout << setprecision(20);
int n;
cin >> n;
for (int i = 0; i < n-1; i++) {
cin >> a[i];
}
as[0] = 0;
for (int i = 0; i < n; i++) {
as[i+1] = as[i]+a[i];
}
int m;
cin >> m;
assert(m == 1);
cin >> a[n-1];
SegTree<Node> s(n);
for (int i = 0; i < n; i++) {
s.single(i, Node::AddQuery{a[i]-as[i+1]});
}
for (int i = n-2; i >= 0; i--) {
ll f = a[i];
if (i < n-2) {
f += s.query(i+2, n, Node::MaxQuery{}).ma;
f += as[i+1];
}
// cout << i << " " << f << endl;
s.single(i, Node::AddQuery{-f});
}
cout << s.single(0, Node::MaxQuery{}).ma << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
H - Tokaido |
User |
yosupo |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3454 Byte |
Status |
WA |
Exec Time |
146 ms |
Memory |
11520 KB |
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
0 / 700 |
0 / 900 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
dataset1 |
sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
dataset2 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
WA |
111 ms |
11520 KB |
01-02.txt |
WA |
3 ms |
256 KB |
01-03.txt |
WA |
3 ms |
384 KB |
01-04.txt |
WA |
55 ms |
5760 KB |
01-05.txt |
WA |
117 ms |
11520 KB |
01-06.txt |
WA |
110 ms |
11520 KB |
01-07.txt |
WA |
34 ms |
3200 KB |
01-08.txt |
WA |
118 ms |
11520 KB |
01-09.txt |
WA |
111 ms |
11520 KB |
01-10.txt |
WA |
3 ms |
256 KB |
01-11.txt |
WA |
23 ms |
2944 KB |
01-12.txt |
WA |
113 ms |
11392 KB |
01-13.txt |
WA |
112 ms |
11520 KB |
01-14.txt |
WA |
117 ms |
11520 KB |
01-15.txt |
WA |
111 ms |
11520 KB |
01-16.txt |
WA |
112 ms |
11520 KB |
01-17.txt |
WA |
112 ms |
11520 KB |
01-18.txt |
WA |
112 ms |
11520 KB |
01-19.txt |
WA |
112 ms |
11520 KB |
02-01.txt |
RE |
119 ms |
768 KB |
02-02.txt |
RE |
145 ms |
3328 KB |
02-03.txt |
RE |
143 ms |
3328 KB |
02-04.txt |
RE |
145 ms |
3328 KB |
02-05.txt |
RE |
110 ms |
256 KB |
02-06.txt |
RE |
145 ms |
3328 KB |
02-07.txt |
RE |
146 ms |
3328 KB |
02-08.txt |
RE |
111 ms |
256 KB |
02-09.txt |
RE |
112 ms |
256 KB |
02-10.txt |
RE |
128 ms |
1792 KB |
02-11.txt |
RE |
145 ms |
3328 KB |
02-12.txt |
RE |
145 ms |
3328 KB |
02-13.txt |
RE |
146 ms |
3328 KB |
02-14.txt |
RE |
146 ms |
3328 KB |
02-15.txt |
RE |
145 ms |
3328 KB |
02-16.txt |
RE |
145 ms |
3328 KB |
sample-01.txt |
AC |
2 ms |
256 KB |
sample-02.txt |
RE |
111 ms |
256 KB |