結果
| 問題 |
No.2861 Slime Party
|
| コンテスト | |
| ユーザー |
square1001
|
| 提出日時 | 2024-07-15 23:31:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,270 bytes |
| コンパイル時間 | 990 ms |
| コンパイル使用メモリ | 82,424 KB |
| 最終ジャッジ日時 | 2025-02-23 15:49:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 75 |
ソースコード
#include <vector>
#include <iostream>
using namespace std;
class query {
public:
int t, a; long long b;
query() : t(-1), a(-1), b(-1) {}
};
class node {
public:
int p, l, r;
node() : p(-1), l(-1), r(-1) {}
};
class binary_tree {
public:
int root;
vector<node> v;
binary_tree(int n) : root(-1), v(vector<node>(n)) {}
};
binary_tree cartesian_tree(int N, const vector<long long>& A) {
binary_tree T(N);
vector<int> st;
int pos = 0;
for (int i = 0; i < N; i++) {
int u = -1;
while (!st.empty() && A[st.back()] < A[i]) {
u = st.back();
st.pop_back();
}
if (u != -1) {
T.v[i].l = u;
T.v[u].p = i;
}
if (!st.empty()) {
T.v[i].p = st.back();
T.v[st.back()].r = i;
}
st.push_back(i);
}
T.root = st[0];
return T;
}
vector<long long> solve(int N, int Q, long long L, const vector<long long>& A, const vector<long long>& X, const vector<query>& qs) {
binary_tree T = cartesian_tree(N, A);
vector<long long> s = X;
auto build_tree = [&](auto& self, int x) -> void {
if (T.v[x].l != -1) {
self(self, T.v[x].l);
s[x] += s[T.v[x].l];
}
if (T.v[x].r != -1) {
self(self, T.v[x].r);
s[x] += s[T.v[x].r];
}
};
build_tree(build_tree, T.root);
vector<long long> CX = X;
vector<long long> ans;
for (query q : qs) {
if (q.t == 1) {
long long d = q.b - CX[q.a];
CX[q.a] = q.b;
int pos = q.a;
while (pos != -1) {
s[pos] += d;
pos = T.v[pos].p;
}
}
if (q.t == 2) {
int base = (A[q.a] < A[q.a + 1] ? q.a : q.a + 1);
if (A[base] < L) {
int pos = base;
while (pos != T.root) {
if (A[T.v[pos].p] >= s[pos] + L) {
break;
}
pos = T.v[pos].p;
}
ans.push_back(s[pos] + L);
} else {
ans.push_back(L);
}
}
}
return ans;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, Q; long long L;
cin >> N >> Q >> L;
vector<long long> A(N), X(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> X[i];
}
vector<query> qs(Q);
for (int i = 0; i < Q; i++) {
cin >> qs[i].t >> qs[i].a;
if (qs[i].t == 1) {
cin >> qs[i].b;
}
qs[i].a--;
}
vector<long long> ans = solve(N, Q, L, A, X, qs);
for (int i = 0; i < int(ans.size()); i++) {
cout << ans[i] << '\n';
}
return 0;
}
square1001