Submission #2474247
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
// use 2^i size by yourself
// otherwise, maybe, it needs exchange law
/// --- SegmentTree Library {{{ ///
/*
struct Monoid {
using T = _underlying_set_;
static T op(const T& a, const T& b) { return _a_op_b_; }
static constexpr T identity() { return _identity_element_; }
};
*/
template<class Monoid>
struct SegTree {
private:
using T = typename Monoid::T;
const int n;
vector<T> data;
void propTo(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }
public:
SegTree(int n, const T& v = Monoid::identity())
: n(n),data(2 * n, v) {}
template <class InputIt>
SegTree(InputIt first, InputIt last)
: n(distance(first, last)), data(2 * n, Monoid::identity()) {
copy(first, last, begin(data) + n);
// たぶん深いところから更新するため
for(int i = n - 1; i > 0; i--) propTo(i);
}
void set(int i, const T& v) {
data[i += n] = v;
while(i >>= 1) propTo(i);
}
T get(int i) { return data[i + n]; }
T query(int l, int r) {
l = max(0, l); r = min(r, n);
T tmpL = Monoid::identity(), tmpR = Monoid::identity();
for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l & 1) tmpL = Monoid::op(tmpL, data[l++]);
if(r & 1) tmpR = Monoid::op(data[--r], tmpR);
}
return Monoid::op(tmpL, tmpR);
}
};
struct RMQMonoid {
using T = long long;
static T op(const T& a, const T& b) { return std::min(a, b); }
static constexpr T identity() { return numeric_limits<T>::max(); }
};
struct RSQMonoid {
using T = long long;
static T op(const T& a, const T& b) { return a + b; }
static constexpr T identity() { return 0; }
};
struct RMaxQMonoid {
using T = long long;
static T op(const T& a, const T& b) { return std::max(a, b); }
static constexpr T identity() { return numeric_limits<T>::min(); }
};
using RMQ = SegTree<RMQMonoid>;
using RSQ = SegTree<RSQMonoid>;
using RMaxQ = SegTree<RMaxQMonoid>;
/// }}}--- ///
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q; cin >> n >> q;
n <<= 1;
int m = 1;
while(m < n) m <<= 1;
vector<ll> a(n), b(n);
RMaxQ treeone(m);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
int use = 0;
ll now = 0;
for(int i = 1; i < n - 1; i++) {
now += max(a[i], b[i]);
if(a[i] < b[i]) use ^= 1;
treeone.set(i, -abs(a[i] - b[i]));
}
while(q--) {
int i, x, y; cin >> i >> x >> y;
i--;
if(i == 0 || i == n - 1) {
} else {
now -= max(a[i], b[i]);
if(a[i] < b[i]) use ^= 1;
now += max(x, y);
if(x < y) use ^= 1;
treeone.set(i, -abs(y - x));
}
a[i] = x; b[i] = y;
ll ans = a[0] + a[n - 1];
ans += now;
if(use) ans += treeone.query(1, n - 1);
cout << ans << endl;
}
}
Submission Info
Submission Time |
|
Task |
C - Paired Parentheses |
User |
luma |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
3012 Byte |
Status |
AC |
Exec Time |
268 ms |
Memory |
8960 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
300 / 300 |
200 / 200 |
Status |
|
|
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
Subtask1 |
00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt |
Subtask2 |
s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s2_24.txt, s2_25.txt, s2_26.txt, s2_27.txt, s2_28.txt |
All |
00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s2_24.txt, s2_25.txt, s2_26.txt, s2_27.txt, s2_28.txt, s3_29.txt, s3_30.txt, s3_31.txt, s3_32.txt, s3_33.txt, s3_34.txt, s3_35.txt, s3_36.txt, s3_37.txt, s3_38.txt, s3_39.txt, s3_40.txt, s3_41.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
AC |
1 ms |
256 KB |
00_example_02.txt |
AC |
1 ms |
256 KB |
s1_01.txt |
AC |
1 ms |
256 KB |
s1_02.txt |
AC |
1 ms |
256 KB |
s1_03.txt |
AC |
1 ms |
256 KB |
s1_04.txt |
AC |
1 ms |
256 KB |
s1_05.txt |
AC |
1 ms |
256 KB |
s1_06.txt |
AC |
1 ms |
256 KB |
s1_07.txt |
AC |
1 ms |
256 KB |
s1_08.txt |
AC |
1 ms |
256 KB |
s1_09.txt |
AC |
1 ms |
256 KB |
s1_10.txt |
AC |
1 ms |
256 KB |
s1_11.txt |
AC |
1 ms |
256 KB |
s1_12.txt |
AC |
1 ms |
256 KB |
s1_13.txt |
AC |
1 ms |
256 KB |
s2_14.txt |
AC |
3 ms |
640 KB |
s2_15.txt |
AC |
4 ms |
640 KB |
s2_16.txt |
AC |
35 ms |
6528 KB |
s2_17.txt |
AC |
29 ms |
4096 KB |
s2_18.txt |
AC |
49 ms |
7552 KB |
s2_19.txt |
AC |
49 ms |
7552 KB |
s2_20.txt |
AC |
49 ms |
7552 KB |
s2_21.txt |
AC |
50 ms |
7552 KB |
s2_22.txt |
AC |
3 ms |
640 KB |
s2_23.txt |
AC |
4 ms |
640 KB |
s2_24.txt |
AC |
3 ms |
640 KB |
s2_25.txt |
AC |
52 ms |
7552 KB |
s2_26.txt |
AC |
53 ms |
7552 KB |
s2_27.txt |
AC |
53 ms |
7552 KB |
s2_28.txt |
AC |
54 ms |
7552 KB |
s3_29.txt |
AC |
81 ms |
4352 KB |
s3_30.txt |
AC |
150 ms |
3072 KB |
s3_31.txt |
AC |
47 ms |
6912 KB |
s3_32.txt |
AC |
224 ms |
8064 KB |
s3_33.txt |
AC |
84 ms |
4352 KB |
s3_34.txt |
AC |
255 ms |
8960 KB |
s3_35.txt |
AC |
268 ms |
8960 KB |
s3_36.txt |
AC |
254 ms |
8960 KB |
s3_37.txt |
AC |
254 ms |
8960 KB |
s3_38.txt |
AC |
246 ms |
8960 KB |
s3_39.txt |
AC |
246 ms |
8960 KB |
s3_40.txt |
AC |
187 ms |
1024 KB |
s3_41.txt |
AC |
184 ms |
1024 KB |