結果
| 問題 |
No.704 ゴミ拾い Medium
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2018-06-15 23:26:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,925 bytes |
| コンパイル時間 | 824 ms |
| コンパイル使用メモリ | 90,424 KB |
| 実行使用メモリ | 23,552 KB |
| 最終ジャッジ日時 | 2024-06-30 15:31:47 |
| 合計ジャッジ時間 | 8,992 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 RE * 22 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
#define int long long
int MOD = 1000000007;
template<typename T>
struct segtree {
const int inf = (int)1 << 60;
int N;
int dat[700000];
segtree() {}
segtree(int n) {
N = 1;
while (N < n) N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
dat[i] = inf;
}
// update k th element
void update(int k, int a) {
k += N - 1; // leaf
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min [a, b)
int query(int a, int b) { return query(a, b, 0, 0, N); }
int query(int a, int b, int k, int l, int r) {
if (r <= a or b <= l) return inf;
if (a <= l and r <= b) return dat[k];
int m = (l + r) / 2;
return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> A(N);
vector<int> X(N);
vector<int> Y(N);
vector<int> dp(N + 1, 0);
int res = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]++;
}
for (int i = 0; i < N; i++) {
cin >> X[i];
X[i]++;
}
for (int i = 0; i < N; i++) {
cin >> Y[i];
//Y[i]++;
}
segtree<int> sg1(N);
segtree<int> sg2(N);
dp[0] = 0;
sg1.update(0, dp[0] - X[0] + Y[0]);
sg2.update(0, dp[0] + X[0] + Y[0]);
X.push_back(1 << 30);
//sg1.update()
for (int i = 1; i <= N; i++) {
int t = lower_bound(X.begin(), X.end(), A[i - 1]) - X.begin();
int a;
if (i <= t) {
a = sg1.query(0, i) + A[i - 1];
}
else {
a = sg1.query(0, t) + A[i - 1];
a = min(a, sg2.query(t, i) - A[i - 1]);
}
dp[i] = a;
if (i < N) {
sg1.update(i, dp[i] - X[i] + Y[i]);
sg2.update(i, dp[i] + X[i] + Y[i]);
}
}
cout << dp[N] << endl;
}
ats5515