problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03176 | C++ | Runtime Error | // Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:
/*
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxval = 200005;
ll tree[2 * maxval + 5];
void make_tree(int i, int low, int high, const vector<int> &A) {
if (low == high) {
tree[i] = 0;
return;
}
int mid = (low + high) / 2;
make_tree(2 * i, low, mid, A);
make_tree(2 * i + 1, mid + 1, high, A);
tree[i] = max(tree[2 * i], tree[2 * i + 1]);
}
void update(int i, int low, int high, ll val, ll h, const vector<int> &A) {
if (low == high) {
tree[i] = val;
return;
}
int mid = (low + high) / 2;
if (h <= mid)
update(2 * i, low, mid, val, h, A);
else
update(2 * i + 1, mid + 1, high, val, h, A);
tree[i] = max(tree[2 * i], tree[2 * i + 1]);
}
ll query(int i, int low, int high, int a, int b) {
if (high < a || low > b)
return 0;
if (low >= a && high <= b) {
return tree[i];
}
int mid = (low + high) / 2;
return max(query(2 * i, low, mid, a, b),
query(2 * i + 1, mid + 1, high, a, b));
}
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
scanf("%d", &n);
vector<int> H(n + 1);
vector<int> A(n + 1);
int maxh = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &H[i]);
maxh = max(maxh, H[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
make_tree(1, 0, maxh, A);
ll res = 0;
for (int i = 0; i < n; i++) {
ll h = H[i];
ll val = query(1, 0, maxh, 0, h - 1);
res = max(res, A[i] + val);
update(1, 0, maxh, val + A[i], h, A);
}
printf("%lld\n", res);
return 0;
}
| // Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:
/*
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxval = 200005;
ll tree[4 * maxval + 5];
void make_tree(int i, int low, int high, const vector<int> &A) {
if (low == high) {
tree[i] = 0;
return;
}
int mid = (low + high) / 2;
make_tree(2 * i, low, mid, A);
make_tree(2 * i + 1, mid + 1, high, A);
tree[i] = max(tree[2 * i], tree[2 * i + 1]);
}
void update(int i, int low, int high, ll val, ll h, const vector<int> &A) {
if (low == high) {
tree[i] = val;
return;
}
int mid = (low + high) / 2;
if (h <= mid)
update(2 * i, low, mid, val, h, A);
else
update(2 * i + 1, mid + 1, high, val, h, A);
tree[i] = max(tree[2 * i], tree[2 * i + 1]);
}
ll query(int i, int low, int high, int a, int b) {
if (high < a || low > b)
return 0;
if (low >= a && high <= b) {
return tree[i];
}
int mid = (low + high) / 2;
return max(query(2 * i, low, mid, a, b),
query(2 * i + 1, mid + 1, high, a, b));
}
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
scanf("%d", &n);
vector<int> H(n + 1);
vector<int> A(n + 1);
int maxh = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &H[i]);
maxh = max(maxh, H[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
make_tree(1, 0, maxh, A);
ll res = 0;
for (int i = 0; i < n; i++) {
ll h = H[i];
ll val = query(1, 0, maxh, 0, h - 1);
res = max(res, A[i] + val);
update(1, 0, maxh, val + A[i], h, A);
}
printf("%lld\n", res);
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include "rubo.h"
// #define mp make_pair
// #define pb push_back
#define in int
#define ll long long
#define vc vector
#define SQ(j) (j) * (j)
// #define x first
// #define y second
// #define ld long double
#define dbl long double
#define pll pair<long long, long long>
#define pii pair<int, int>
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for (int xxx = 0; xxx < yyy; xxx++)
// #define printf(fmt, ...) (0)
// #define HOME
// #define y0 ngacaleiebinvoaeu
// #define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp
#define db(x) cout << #x << " = " << x << endl
#define dbCont(x) \
cout << #x << ": "; \
for (auto shun : x) \
cout << shun << ' '; \
cout << endl;
typedef long double ld;
using namespace std;
const int N = 100 * 1000 + 123;
const int MOD = 1000 * 1000 * 1000 + 7;
int n;
map<int, int> a;
int h[N];
ll t[4 * N];
ll get_mx(int v, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return t[v];
if (ql > r || l > qr)
return 0;
int mid = (l + r) / 2;
return max(get_mx(2 * v + 1, l, mid, ql, qr),
get_mx(2 * v + 2, mid + 1, r, ql, qr));
}
ll upd(int v, int l, int r, int pos, ll val) {
if (l == r) {
t[v] = val;
} else {
int mid = (l + r) / 2;
if (pos <= mid)
upd(2 * v + 1, l, mid, pos, val);
else
upd(2 * v + 2, mid + 1, r, pos, val);
t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}
}
int main() {
cin >> n;
loop(i, n) { cin >> h[i]; }
loop(i, n) { cin >> a[h[i]]; }
vector<pii> v;
loop(i, n) { v.push_back(make_pair(h[i], i)); }
sort(all(v));
for (auto p : v) {
int he = p.first;
int i = p.second;
// db(i);
ll mx = get_mx(0, 0, n - 1, 0, i);
upd(0, 0, n - 1, i, mx + a[he]);
}
ll res = t[0];
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
// #include "rubo.h"
// #define mp make_pair
// #define pb push_back
#define in int
#define ll long long
#define vc vector
#define SQ(j) (j) * (j)
// #define x first
// #define y second
// #define ld long double
#define dbl long double
#define pll pair<long long, long long>
#define pii pair<int, int>
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for (int xxx = 0; xxx < yyy; xxx++)
// #define printf(fmt, ...) (0)
// #define HOME
// #define y0 ngacaleiebinvoaeu
// #define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp
#define db(x) cout << #x << " = " << x << endl
#define dbCont(x) \
cout << #x << ": "; \
for (auto shun : x) \
cout << shun << ' '; \
cout << endl;
typedef long double ld;
using namespace std;
const int N = 200 * 1000 + 123;
const int MOD = 1000 * 1000 * 1000 + 7;
int n;
map<int, int> a;
int h[N];
ll t[4 * N];
ll get_mx(int v, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return t[v];
if (ql > r || l > qr)
return 0;
int mid = (l + r) / 2;
return max(get_mx(2 * v + 1, l, mid, ql, qr),
get_mx(2 * v + 2, mid + 1, r, ql, qr));
}
ll upd(int v, int l, int r, int pos, ll val) {
if (l == r) {
t[v] = val;
} else {
int mid = (l + r) / 2;
if (pos <= mid)
upd(2 * v + 1, l, mid, pos, val);
else
upd(2 * v + 2, mid + 1, r, pos, val);
t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}
}
int main() {
cin >> n;
loop(i, n) { cin >> h[i]; }
loop(i, n) { cin >> a[h[i]]; }
vector<pii> v;
loop(i, n) { v.push_back(make_pair(h[i], i)); }
sort(all(v));
for (auto p : v) {
int he = p.first;
int i = p.second;
// db(i);
ll mx = get_mx(0, 0, n - 1, 0, i);
upd(0, 0, n - 1, i, mx + a[he]);
}
ll res = t[0];
cout << res << endl;
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p03176 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define pr(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define nl printf("\n")
#define fr(i, n) for (i = 0; i < n; i++)
#define rep(i, st, en) for (i = st; i <= en; i++)
#define repv(i, en, st) for (i = en; i >= st; i--)
#define fout cout << fixed << setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
ll mod = 1e9 + 7;
ll fmod(ll b, ll exp) {
ll res = 1;
while (exp) {
if (exp & 1ll)
res = (res * b) % mod;
b = (b * b) % mod;
exp /= 2ll;
}
return res;
}
int n;
ll A[N], h[N], bit[N];
void upd(int idx, ll val) {
for (int i = idx; i <= n; i += (i & -i))
bit[i] = max(bit[i], val);
}
ll query(int idx) {
ll res = 0;
for (int i = idx; i; i--)
res = max(res, bit[i]);
return res;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1, i, j, m;
cin >> n;
rep(i, 1, n) cin >> h[i];
rep(i, 1, n) cin >> A[i];
ll mx = 0;
rep(i, 1, n) {
ll cur = query(h[i]);
ll ans = cur + A[i];
mx = max(mx, ans);
upd(h[i], ans);
}
cout << mx << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define pr(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define nl printf("\n")
#define fr(i, n) for (i = 0; i < n; i++)
#define rep(i, st, en) for (i = st; i <= en; i++)
#define repv(i, en, st) for (i = en; i >= st; i--)
#define fout cout << fixed << setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
ll mod = 1e9 + 7;
ll fmod(ll b, ll exp) {
ll res = 1;
while (exp) {
if (exp & 1ll)
res = (res * b) % mod;
b = (b * b) % mod;
exp /= 2ll;
}
return res;
}
int n;
ll A[N], h[N], bit[N];
void upd(int idx, ll val) {
for (int i = idx; i <= n; i += (i & -i))
bit[i] = max(bit[i], val);
}
ll query(int idx) {
ll res = 0;
for (int i = idx; i; i -= (i & -i))
res = max(res, bit[i]);
return res;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1, i, j, m;
cin >> n;
rep(i, 1, n) cin >> h[i];
rep(i, 1, n) cin >> A[i];
ll mx = 0;
rep(i, 1, n) {
ll cur = query(h[i]);
ll ans = cur + A[i];
mx = max(mx, ans);
upd(h[i], ans);
}
cout << mx << "\n";
return 0;
}
| replace | 40 | 41 | 40 | 41 | TLE | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define vi vector<long long>
#define vvi vector<vector<long long>>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
#define dbg(x, y) cout << (x) << " --> " << (y) << endl
#define dbg2(k) cout << (k) << " * " << endl;
#define F first
#define S second
#define int long long
#define ll long long
const int inf = 1e6 + 2;
const int ninf = -1e9;
const int mod = 1e9 + 7;
int cost[100005], h[100005];
int BIT[10005];
int n;
void update(int idx, int val) {
while (idx < n) {
BIT[idx] = max(BIT[idx], val);
idx += ((idx) & (-idx));
}
}
int fun(int idx) {
int ans = 0;
while (idx > 0) {
ans = max(ans, BIT[idx]);
idx -= (idx & (-idx));
}
return ans;
}
void solve() {
int m, i, j, x, d, bt, y, p, g, k, low, high, res, mid, q;
cin >> n;
for (i = 0; i < n; i++) {
cin >> h[i];
}
for (i = 0; i < n; i++) {
cin >> cost[i];
}
int ans = 0;
for (i = 0; i < n; i++) {
mid = fun(h[i] - 1);
res = mid + cost[i];
// cout<<i<<" "<<mid<<" "<<res<<" "<<h[i]<<endl;
ans = max(ans, res);
update(h[i], res);
}
cout << ans << endl;
}
signed main() {
// FASTIO;
int T;
T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define vi vector<long long>
#define vvi vector<vector<long long>>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
#define dbg(x, y) cout << (x) << " --> " << (y) << endl
#define dbg2(k) cout << (k) << " * " << endl;
#define F first
#define S second
#define int long long
#define ll long long
const int inf = 1e6 + 2;
const int ninf = -1e9;
const int mod = 1e9 + 7;
int cost[200005], h[200005];
int BIT[200005];
int n;
void update(int idx, int val) {
while (idx < n) {
BIT[idx] = max(BIT[idx], val);
idx += ((idx) & (-idx));
}
}
int fun(int idx) {
int ans = 0;
while (idx > 0) {
ans = max(ans, BIT[idx]);
idx -= (idx & (-idx));
}
return ans;
}
void solve() {
int m, i, j, x, d, bt, y, p, g, k, low, high, res, mid, q;
cin >> n;
for (i = 0; i < n; i++) {
cin >> h[i];
}
for (i = 0; i < n; i++) {
cin >> cost[i];
}
int ans = 0;
for (i = 0; i < n; i++) {
mid = fun(h[i] - 1);
res = mid + cost[i];
// cout<<i<<" "<<mid<<" "<<res<<" "<<h[i]<<endl;
ans = max(ans, res);
update(h[i], res);
}
cout << ans << endl;
}
signed main() {
// FASTIO;
int T;
T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| replace | 23 | 25 | 23 | 25 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 123, MAXN = 1e9;
int n;
ll h[N], a[N], dp[N], ans, L[N], R[N], sz = 1, t[N * 40];
void upd(int pos, ll val, int v = 1, int tl = 1, int tr = MAXN) {
if (tl == tr) {
t[v] = max(val, t[v]);
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm) {
if (!L[v])
L[v] = ++sz;
upd(pos, val, L[v], tl, tm);
} else {
if (!R[v])
R[v] = ++sz;
upd(pos, val, R[v], tm + 1, tr);
}
t[v] = max(t[L[v]], t[R[v]]);
}
ll get(int l, int r, int v = 1, int tl = 1, int tr = MAXN) {
if (tl > r || l > tr || !v)
return 0;
if (tl >= l && r >= tr)
return t[v];
int tm = (tl + tr) >> 1;
return max(get(l, r, L[v], tl, tm), get(l, r, R[v], tm + 1, tr));
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
dp[i] = get(1, h[i] - 1) + a[i];
upd(h[i], dp[i]);
ans = max(ans, dp[i]);
}
cout << ans;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 123, MAXN = 1e9;
int n;
ll h[N], a[N], dp[N], ans, L[N * 40], R[N * 40], sz = 1, t[N * 40];
void upd(int pos, ll val, int v = 1, int tl = 1, int tr = MAXN) {
if (tl == tr) {
t[v] = max(val, t[v]);
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm) {
if (!L[v])
L[v] = ++sz;
upd(pos, val, L[v], tl, tm);
} else {
if (!R[v])
R[v] = ++sz;
upd(pos, val, R[v], tm + 1, tr);
}
t[v] = max(t[L[v]], t[R[v]]);
}
ll get(int l, int r, int v = 1, int tl = 1, int tr = MAXN) {
if (tl > r || l > tr || !v)
return 0;
if (tl >= l && r >= tr)
return t[v];
int tm = (tl + tr) >> 1;
return max(get(l, r, L[v], tl, tm), get(l, r, R[v], tm + 1, tr));
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
dp[i] = get(1, h[i] - 1) + a[i];
upd(h[i], dp[i]);
ans = max(ans, dp[i]);
}
cout << ans;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define endl '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pii pair<ll int, ll int>
#define ff first
#define ss second
ll int n;
ll int h[200001], b[200001];
ll int dp[200001];
ll int tree[600001];
void update(ll int i, ll int v, ll int s, ll int e, ll int index) {
if (i < s || i > e) {
return;
}
if (s == e && s == i) {
tree[index] = v;
return;
}
ll int mid = (s + e) / 2;
update(i, v, s, mid, 2 * index);
update(i, v, mid + 1, e, 2 * index + 1);
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
ll int query(ll int l, ll int r, ll int s, ll int e, ll int index) {
if (r < s || l > e) {
return INT_MIN;
}
if (s >= l && e <= r) {
return tree[index];
}
ll int mid = (s + e) / 2;
return max(query(l, r, s, mid, 2 * index),
query(l, r, mid + 1, e, 2 * index + 1));
}
int main() {
fastio
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n;
for (ll int i = 0; i < n; i++)
cin >> h[i];
for (ll int i = 0; i < n; i++)
cin >> b[i];
memset(dp, 0, sizeof(dp));
memset(tree, 0, sizeof(tree));
ll int ans = 0;
for (ll int i = 0; i < n; i++) {
ll int ht = h[i];
ll int q = query(0, ht - 1, 0, n - 1, 1);
dp[ht] = q + b[i];
ans = max(ans, dp[ht]);
update(ht, q + b[i], 0, n - 1, 1);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define endl '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pii pair<ll int, ll int>
#define ff first
#define ss second
ll int n;
ll int h[200001], b[200001];
ll int dp[200001];
ll int tree[600001];
void update(ll int i, ll int v, ll int s, ll int e, ll int index) {
if (i < s || i > e) {
return;
}
if (s == e && s == i) {
tree[index] = v;
return;
}
ll int mid = (s + e) / 2;
update(i, v, s, mid, 2 * index);
update(i, v, mid + 1, e, 2 * index + 1);
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
ll int query(ll int l, ll int r, ll int s, ll int e, ll int index) {
if (r < s || l > e) {
return INT_MIN;
}
if (s >= l && e <= r) {
return tree[index];
}
ll int mid = (s + e) / 2;
return max(query(l, r, s, mid, 2 * index),
query(l, r, mid + 1, e, 2 * index + 1));
}
int main() {
// fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt" , "r" , stdin);
// freopen("output.txt" , "w" , stdout);
// #endif
cin >> n;
for (ll int i = 0; i < n; i++)
cin >> h[i];
for (ll int i = 0; i < n; i++)
cin >> b[i];
memset(dp, 0, sizeof(dp));
memset(tree, 0, sizeof(tree));
ll int ans = 0;
for (ll int i = 0; i < n; i++) {
ll int ht = h[i];
ll int q = query(0, ht - 1, 0, n - 1, 1);
dp[ht] = q + b[i];
ans = max(ans, dp[ht]);
update(ht, q + b[i], 0, n - 1, 1);
}
cout << ans << endl;
return 0;
}
| replace | 54 | 59 | 54 | 59 | 0 | |
p03176 | C++ | Runtime Error | #pragma GCC optimize("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define ifr(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m, n, r) \
m.reserve(n); \
m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd() { return 0ll; }
template <typename T, typename... Args> T gcd(T a, Args... args) {
return __gcd(a, (__typeof(a))gcd(args...));
}
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001
ll h[N], a[N], bit[N];
map<ll, ll> m;
ll upd(ll i, ll val) {
for (; i < N; i += (i & (-i)))
bit[i] = max(bit[i], val);
}
ll get(ll i) {
ll res = 0;
for (; i > 0; i -= (i & (-i)))
res = max(res, bit[i]);
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
ifr(i, 0, n) cin >> h[i], m[h[i]];
ifr(i, 0, n) cin >> a[i];
int j = 1;
for (auto &it : m) {
it.ss = j;
j++;
}
ifr(i, 0, n) h[i] = m[h[i]];
// ifr(i,0,n) cout<<h[i]<<" ";cout<<endl;
ll x, ans = 0;
ifr(i, 0, n) {
x = get(h[i]);
upd(h[i], x + a[i]);
ans = max(ans, x + a[i]);
}
cout << ans << endl;
return 0;
} | #pragma GCC optimize("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define ifr(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m, n, r) \
m.reserve(n); \
m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd() { return 0ll; }
template <typename T, typename... Args> T gcd(T a, Args... args) {
return __gcd(a, (__typeof(a))gcd(args...));
}
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 200020
ll h[N], a[N], bit[N];
map<ll, ll> m;
ll upd(ll i, ll val) {
for (; i < N; i += (i & (-i)))
bit[i] = max(bit[i], val);
}
ll get(ll i) {
ll res = 0;
for (; i > 0; i -= (i & (-i)))
res = max(res, bit[i]);
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
ifr(i, 0, n) cin >> h[i], m[h[i]];
ifr(i, 0, n) cin >> a[i];
int j = 1;
for (auto &it : m) {
it.ss = j;
j++;
}
ifr(i, 0, n) h[i] = m[h[i]];
// ifr(i,0,n) cout<<h[i]<<" ";cout<<endl;
ll x, ans = 0;
ifr(i, 0, n) {
x = get(h[i]);
upd(h[i], x + a[i]);
ans = max(ans, x + a[i]);
}
cout << ans << endl;
return 0;
} | replace | 46 | 47 | 46 | 47 | -11 | |
p03176 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr << x << "\n"
#define debug2(x, y) cerr << x << " " << y << "\n"
#define debug3(x, y, z) cerr << x << " " << y << " " << z << "\n"
#define nl cerr << "\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr << "abcd\n";
#define pi pair<int, int>
#define pii pair<int, pi>
#define pb push_back
#define mxn 100005
#define mxnn 2000005
int hei[mxn], tree[mxn << 2], val[mxn], dp[mxn];
void update(int i, int tl, int tr, int pos, int val) {
if (tl > tr || tl > pos || tr < pos)
return;
if (tl == tr) {
tree[i] = val;
return;
}
int mid = (tl + tr) >> 1;
if (mid >= pos)
update(i + i, tl, mid, pos, val);
else
update(i + i + 1, mid + 1, tr, pos, val);
tree[i] = max(tree[i + i], tree[i + i + 1]);
}
int query(int i, int tl, int tr, int l, int r) {
if (tl > tr || tl > r || tr < l)
return 0;
if (tl >= l && tr <= r)
return tree[i];
int mid = (tl + tr) >> 1;
return max(query(i + i, tl, mid, l, r), query(i + i + 1, mid + 1, tr, l, r));
}
int32_t main() {
sp;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> hei[i];
for (int i = 1; i <= n; i++)
cin >> val[i];
int mx = 0;
for (int i = 1; i <= n; i++)
mx = max(mx, hei[i]);
int ans = 0;
for (int i = 1; i <= n; i++) {
int x = hei[i];
int a = query(1, 0, mx, 1, x);
ans = max(ans, a + val[i]);
update(1, 0, mx, x, a + val[i]);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr << x << "\n"
#define debug2(x, y) cerr << x << " " << y << "\n"
#define debug3(x, y, z) cerr << x << " " << y << " " << z << "\n"
#define nl cerr << "\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr << "abcd\n";
#define pi pair<int, int>
#define pii pair<int, pi>
#define pb push_back
#define mxn 200005
#define mxnn 2000005
int hei[mxn], tree[mxn << 2], val[mxn], dp[mxn];
void update(int i, int tl, int tr, int pos, int val) {
if (tl > tr || tl > pos || tr < pos)
return;
if (tl == tr) {
tree[i] = val;
return;
}
int mid = (tl + tr) >> 1;
if (mid >= pos)
update(i + i, tl, mid, pos, val);
else
update(i + i + 1, mid + 1, tr, pos, val);
tree[i] = max(tree[i + i], tree[i + i + 1]);
}
int query(int i, int tl, int tr, int l, int r) {
if (tl > tr || tl > r || tr < l)
return 0;
if (tl >= l && tr <= r)
return tree[i];
int mid = (tl + tr) >> 1;
return max(query(i + i, tl, mid, l, r), query(i + i + 1, mid + 1, tr, l, r));
}
int32_t main() {
sp;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> hei[i];
for (int i = 1; i <= n; i++)
cin >> val[i];
int mx = 0;
for (int i = 1; i <= n; i++)
mx = max(mx, hei[i]);
int ans = 0;
for (int i = 1; i <= n; i++) {
int x = hei[i];
int a = query(1, 0, mx, 1, x);
ans = max(ans, a + val[i]);
update(1, 0, mx, x, a + val[i]);
}
cout << ans;
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p03176 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define show(x) cerr << #x << " = " << x << endl;
#define input_from_file freopen("input.txt", "r", stdin)
#define output_to_file freopen("output.txt", "w", stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'
const int N = 1e5 + 1;
long long tree[4 * N];
vector<vector<int>> v(N, vector<int>(3));
void update(int l, int r, int pos, int index, long long val) {
if (l > r)
return;
else if (l == r) {
tree[pos] = val;
return;
}
int mid = l + (r - l) / 2;
if (index <= mid)
update(l, mid, 2 * pos + 1, index, val);
else
update(mid + 1, r, 2 * pos + 2, index, val);
tree[pos] = max(tree[2 * pos + 1], tree[2 * pos + 2]);
// cerr <<l << " "<< r << " "<< pos << " "<< tree[pos] << endl;
return;
}
long long query(int ql, int qr, int l, int r, int pos) {
if (l > r || qr < l || ql > r)
return 0;
else if (ql <= l && qr >= r)
return tree[pos];
int mid = l + (r - l) / 2;
return max(query(ql, qr, l, mid, 2 * pos + 1),
query(ql, qr, mid + 1, r, 2 * pos + 2));
}
int main() {
#ifdef LOCAL
input_from_file;
output_to_file;
#endif
fastio;
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> v[i][0];
v[i][1] = i;
}
for (int i = 0; i < n; ++i)
cin >> v[i][2];
sort(v.begin(), v.begin() + n);
long long x;
for (int i = 0; i < n; ++i) {
x = query(0, v[i][1] - 1, 0, n - 1, 0);
update(0, n - 1, 0, v[i][1], x + 1LL * v[i][2]);
}
cout << tree[0];
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define show(x) cerr << #x << " = " << x << endl;
#define input_from_file freopen("input.txt", "r", stdin)
#define output_to_file freopen("output.txt", "w", stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'
const int N = 2e5 + 1;
long long tree[4 * N];
vector<vector<int>> v(N, vector<int>(3));
void update(int l, int r, int pos, int index, long long val) {
if (l > r)
return;
else if (l == r) {
tree[pos] = val;
return;
}
int mid = l + (r - l) / 2;
if (index <= mid)
update(l, mid, 2 * pos + 1, index, val);
else
update(mid + 1, r, 2 * pos + 2, index, val);
tree[pos] = max(tree[2 * pos + 1], tree[2 * pos + 2]);
// cerr <<l << " "<< r << " "<< pos << " "<< tree[pos] << endl;
return;
}
long long query(int ql, int qr, int l, int r, int pos) {
if (l > r || qr < l || ql > r)
return 0;
else if (ql <= l && qr >= r)
return tree[pos];
int mid = l + (r - l) / 2;
return max(query(ql, qr, l, mid, 2 * pos + 1),
query(ql, qr, mid + 1, r, 2 * pos + 2));
}
int main() {
#ifdef LOCAL
input_from_file;
output_to_file;
#endif
fastio;
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> v[i][0];
v[i][1] = i;
}
for (int i = 0; i < n; ++i)
cin >> v[i][2];
sort(v.begin(), v.begin() + n);
long long x;
for (int i = 0; i < n; ++i) {
x = query(0, v[i][1] - 1, 0, n - 1, 0);
update(0, n - 1, 0, v[i][1], x + 1LL * v[i][2]);
}
cout << tree[0];
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> height, dp, b;
vector<ll> tree;
// buildtree(int *arr,start,end,node){
// }
// void treeupdate(int indx,int s,int e,int updi,int upd ){
// if(s==e) {
// tree[indx]=upd;
// }
// else{
// int mid=(s+e)/2;
// int le=2*indx,ri=2*indx+1;
// if(updi<=mid) treeupdate(le,0,mid,updi,upd);
// else treeupdate(ri,mid+1,e,updi,upd);
// tree[indx]=max(tree[le],tree[ri]);
// }
// }
void treeupdate(int idx, int L, int R, int ii, ll upd) {
if (L == R) {
tree[idx] = upd;
return;
}
int le = 2 * idx + 1, ri = le + 1, mid = (L + R) / 2;
if (ii <= mid)
treeupdate(le, L, mid, ii, upd);
else
treeupdate(ri, mid + 1, R, ii, upd);
//
tree[idx] = max(tree[le], tree[ri]);
}
// int treemax(int ind,int l,int r,int ql,int qr){
// if(ql>r||qr<l) return 0;
// if(ql<=l&&qr>=r) return tree[ind];
// else{
// int mid=(l+r)/2;
// return
// max(treemax(2*ind,l,mid,ql,qr),treemax(2*ind+1,mid+1,r,ql,qr));
// }
// }
ll treemax(int idx, int L, int R, int QL, int QR) {
if (L >= QL && R <= QR) {
return tree[idx];
}
if (L > QR || R < QL)
return 0;
int le = 2 * idx + 1, ri = le + 1, mid = (L + R) / 2;
ll a1 = treemax(le, L, mid, QL, QR);
ll a2 = treemax(ri, mid + 1, R, QL, QR);
//
return max(a1, a2);
}
long long findbase(long long k) {
long long ans = 0;
while (k) {
k = k >> 1;
ans++;
}
return ans;
}
int main() {
ll n;
cin >> n;
height.resize(n);
dp.resize(n);
b.resize(n);
// cout<<findbase(n);
tree.resize(1 << (findbase(n) + 1));
// tree.resize(100);
for (int i = 0; i < n; i++) {
cin >> height[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
// dp[i]=b[i];
}
for (int i = 0; i < n; i++) {
dp[i] = treemax(1, 1, n, 1, height[i] - 1) + b[i];
treeupdate(1, 1, n, height[i], dp[i]);
// cout<<dp[i]<<"X";
}
ll ans = 0;
for (int i = 0; i < dp.size(); i++) {
// cout<<tree[i];
ans = max(ans, dp[i]);
}
cout << ans;
// cout<<treemax(0);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> height, dp, b;
vector<ll> tree;
// buildtree(int *arr,start,end,node){
// }
// void treeupdate(int indx,int s,int e,int updi,int upd ){
// if(s==e) {
// tree[indx]=upd;
// }
// else{
// int mid=(s+e)/2;
// int le=2*indx,ri=2*indx+1;
// if(updi<=mid) treeupdate(le,0,mid,updi,upd);
// else treeupdate(ri,mid+1,e,updi,upd);
// tree[indx]=max(tree[le],tree[ri]);
// }
// }
void treeupdate(int idx, int L, int R, int ii, ll upd) {
if (L == R) {
tree[idx] = upd;
return;
}
int le = 2 * idx + 1, ri = le + 1, mid = (L + R) / 2;
if (ii <= mid)
treeupdate(le, L, mid, ii, upd);
else
treeupdate(ri, mid + 1, R, ii, upd);
//
tree[idx] = max(tree[le], tree[ri]);
}
// int treemax(int ind,int l,int r,int ql,int qr){
// if(ql>r||qr<l) return 0;
// if(ql<=l&&qr>=r) return tree[ind];
// else{
// int mid=(l+r)/2;
// return
// max(treemax(2*ind,l,mid,ql,qr),treemax(2*ind+1,mid+1,r,ql,qr));
// }
// }
ll treemax(int idx, int L, int R, int QL, int QR) {
if (L >= QL && R <= QR) {
return tree[idx];
}
if (L > QR || R < QL)
return 0;
int le = 2 * idx + 1, ri = le + 1, mid = (L + R) / 2;
ll a1 = treemax(le, L, mid, QL, QR);
ll a2 = treemax(ri, mid + 1, R, QL, QR);
//
return max(a1, a2);
}
long long findbase(long long k) {
long long ans = 0;
while (k) {
k = k >> 1;
ans++;
}
return ans;
}
int main() {
ll n;
cin >> n;
height.resize(n);
dp.resize(n);
b.resize(n);
// cout<<findbase(n);
tree.resize(int(2e5 + 2) << 2);
// tree.resize(100);
for (int i = 0; i < n; i++) {
cin >> height[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
// dp[i]=b[i];
}
for (int i = 0; i < n; i++) {
dp[i] = treemax(1, 1, n, 1, height[i] - 1) + b[i];
treeupdate(1, 1, n, height[i], dp[i]);
// cout<<dp[i]<<"X";
}
ll ans = 0;
for (int i = 0; i < dp.size(); i++) {
// cout<<tree[i];
ans = max(ans, dp[i]);
}
cout << ans;
// cout<<treemax(0);
return 0;
}
| replace | 72 | 73 | 72 | 73 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (int i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (int i(a), _##i(b); i <= _##i; ++i)
#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...) \
_NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1) \
(MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...) \
cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m"; \
FOR_EACH_MACRO(watch, __VA_ARGS__) \
cerr << endl
#else
#define debug(...)
#endif
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '{' << p.first << ", " << p.second << '}';
}
template <class T, class = decltype(begin(declval<T>())),
class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
os << '[';
for (auto it = begin(c); it != end(c); ++it)
os << (it == begin(c) ? "" : ", ") << *it;
return os << ']';
}
using ll = long long;
const int N = 1e5 + 5;
struct Seg {
int n = 0;
array<ll, N << 1> a{};
Seg(int n) : n(n) {}
void update(int idx, ll value) {
idx += n;
for (a[idx] = max(a[idx], value); idx > 1; idx >>= 1) {
a[idx >> 1] = max(a[idx], a[idx ^ 1]);
}
}
ll get(int l, int r) {
ll res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, a[l++]);
if (r & 1)
res = max(res, a[--r]);
}
return res;
}
};
void solve() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
REP(i, n) cin >> a[i].F;
REP(i, n) cin >> a[i].S;
Seg seg(n + 1);
REP(i, n) {
ll mx = seg.get(0, a[i].F);
seg.update(a[i].F, mx + a[i].S);
}
ll ans = seg.get(0, n + 1);
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
}
| #include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (int i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (int i(a), _##i(b); i <= _##i; ++i)
#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...) \
_NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1) \
(MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...) \
cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m"; \
FOR_EACH_MACRO(watch, __VA_ARGS__) \
cerr << endl
#else
#define debug(...)
#endif
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '{' << p.first << ", " << p.second << '}';
}
template <class T, class = decltype(begin(declval<T>())),
class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
os << '[';
for (auto it = begin(c); it != end(c); ++it)
os << (it == begin(c) ? "" : ", ") << *it;
return os << ']';
}
using ll = long long;
const int N = 2e5 + 5;
struct Seg {
int n = 0;
array<ll, N << 1> a{};
Seg(int n) : n(n) {}
void update(int idx, ll value) {
idx += n;
for (a[idx] = max(a[idx], value); idx > 1; idx >>= 1) {
a[idx >> 1] = max(a[idx], a[idx ^ 1]);
}
}
ll get(int l, int r) {
ll res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, a[l++]);
if (r & 1)
res = max(res, a[--r]);
}
return res;
}
};
void solve() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
REP(i, n) cin >> a[i].F;
REP(i, n) cin >> a[i].S;
Seg seg(n + 1);
REP(i, n) {
ll mx = seg.get(0, a[i].F);
seg.update(a[i].F, mx + a[i].S);
}
ll ans = seg.get(0, n + 1);
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fored(i, l, r) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout << #x << " " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<char, int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll INF = LONG_LONG_MAX;
const double PI = atan(1) * 4;
const int MAXN = 1e5 + 20;
const double EPS = 1e-10;
struct FenwickTree { // index-1
vector<ll> ft;
FenwickTree(int n) { ft.assign(n + 1, 0); } // init n + 1 zeroes
ll rsq(int b) { // returns RSQ(1, b)
ll maxi = 0;
for (; b; b -= (b & (-b)))
maxi = max(maxi, ft[b]);
return maxi;
}
// int rsq(int a, int b) { // returns RSQ(a, b)
// return rsq(b) - (a == 1 ? 0 : rsq(a - 1));
// }
// adjusts value of the k-th element by v (v can be +ve/inc or -ve/dec)
void adjust(int k, ll v) { // note: n = ft.size() - 1
for (; k < (int)ft.size(); k += (k & (-k)))
ft[k] = max(v, ft[k]);
}
};
int h[MAXN];
ll a[MAXN];
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL); cout.tie(NULL);
// cout<< setprecision(2)<< fixed;
int n;
cin >> n;
int m = 0;
forn(i, n) {
cin >> h[i];
m = max(m, h[i]);
}
forn(i, n) cin >> a[i];
FenwickTree f = FenwickTree(m + 10);
forn(i, n) {
ll v = f.rsq(h[i]);
f.adjust(h[i], a[i] + v);
}
cout << f.rsq(m + 9) << el;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fored(i, l, r) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout << #x << " " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<char, int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll INF = LONG_LONG_MAX;
const double PI = atan(1) * 4;
const int MAXN = 2e5 + 20;
const double EPS = 1e-10;
struct FenwickTree { // index-1
vector<ll> ft;
FenwickTree(int n) { ft.assign(n + 1, 0); } // init n + 1 zeroes
ll rsq(int b) { // returns RSQ(1, b)
ll maxi = 0;
for (; b; b -= (b & (-b)))
maxi = max(maxi, ft[b]);
return maxi;
}
// int rsq(int a, int b) { // returns RSQ(a, b)
// return rsq(b) - (a == 1 ? 0 : rsq(a - 1));
// }
// adjusts value of the k-th element by v (v can be +ve/inc or -ve/dec)
void adjust(int k, ll v) { // note: n = ft.size() - 1
for (; k < (int)ft.size(); k += (k & (-k)))
ft[k] = max(v, ft[k]);
}
};
int h[MAXN];
ll a[MAXN];
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL); cout.tie(NULL);
// cout<< setprecision(2)<< fixed;
int n;
cin >> n;
int m = 0;
forn(i, n) {
cin >> h[i];
m = max(m, h[i]);
}
forn(i, n) cin >> a[i];
FenwickTree f = FenwickTree(m + 10);
forn(i, n) {
ll v = f.rsq(h[i]);
f.adjust(h[i], a[i] + v);
}
cout << f.rsq(m + 9) << el;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
int n;
ll A[100005], h[100005], bit[100005];
void upd(int idx, ll val) {
for (int i = idx; i <= n; i += (i & -i)) {
bit[i] = max(bit[i], val);
}
}
ll query(int idx) {
ll res = 0;
for (int i = idx; i; i -= (i & -i)) {
res = max(res, bit[i]);
}
return res;
}
int main() {
int t = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
ll mx = 0;
for (int i = 1; i <= n; i++) {
ll cur = query(h[i]);
ll ans = cur + A[i];
mx = max(mx, ans);
upd(h[i], ans);
}
cout << mx << "\n";
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
int n;
ll A[1000005], h[1000005], bit[1000005];
void upd(int idx, ll val) {
for (int i = idx; i <= n; i += (i & -i)) {
bit[i] = max(bit[i], val);
}
}
ll query(int idx) {
ll res = 0;
for (int i = idx; i; i -= (i & -i)) {
res = max(res, bit[i]);
}
return res;
}
int main() {
int t = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
ll mx = 0;
for (int i = 1; i <= n; i++) {
ll cur = query(h[i]);
ll ans = cur + A[i];
mx = max(mx, ans);
upd(h[i], ans);
}
cout << mx << "\n";
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define ld long double
#define fio() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define MOD 1000000007
#define nl '\n'
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 105;
const int K = 200005;
int t[N << 2];
void build(int a[], int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
int tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
int query(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) / 2;
return max(query(v * 2, tl, tm, l, min(r, tm)),
query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int32_t main() {
fio();
int n;
cin >> n;
vector<pair<pair<int, int>, int>> v;
int h[n], a[n];
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
v.push_back({{h[i], a[i]}, i});
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
int u = 0;
if (v[i].second != 0)
u = query(1, 0, n - 1, 0, v[i].second - 1);
// cout<<u<<endl;
update(1, 0, n - 1, v[i].second, u + v[i].first.second);
// cout<<query(1,0,n-1,1,1)<<endl;
}
cout << query(1, 0, n - 1, 0, n - 1);
}
| #include <bits/stdc++.h>
#define int long long
#define ld long double
#define fio() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define MOD 1000000007
#define nl '\n'
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 105;
const int K = 200005;
int t[K << 2];
void build(int a[], int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
int tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
int query(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) / 2;
return max(query(v * 2, tl, tm, l, min(r, tm)),
query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int32_t main() {
fio();
int n;
cin >> n;
vector<pair<pair<int, int>, int>> v;
int h[n], a[n];
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
v.push_back({{h[i], a[i]}, i});
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
int u = 0;
if (v[i].second != 0)
u = query(1, 0, n - 1, 0, v[i].second - 1);
// cout<<u<<endl;
update(1, 0, n - 1, v[i].second, u + v[i].first.second);
// cout<<query(1,0,n-1,1,1)<<endl;
}
cout << query(1, 0, n - 1, 0, n - 1);
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03176 | C++ | Time Limit Exceeded | #ifndef bhartiya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;
#define pb push_back
#define bitc __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second
#define swap(a, b) \
{ \
a = a ^ b; \
b = a ^ b; \
a = a ^ b; \
}
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cout << "\n\nTime elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif
#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll maxn = 200005;
ll n;
ll a[maxn];
ll height[maxn];
ll b[maxn];
set<ll> curr;
int main() {
start_routine();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--) {
cin >> n;
rep(i, n) { cin >> height[i]; }
rep(i, n) { cin >> a[i]; }
rep(i, n) {
auto x = lower_bound(curr.begin(), curr.end(), height[i]);
if (x == curr.begin()) {
b[height[i]] = a[i];
curr.insert(height[i]);
x = curr.begin();
ll val = a[i];
x++;
while (x != curr.end() && b[*x] <= val) {
// trace(i, *x);
auto temp = x;
b[*x] = 0;
x++;
curr.erase(*temp);
}
} else {
x--;
ll val = a[i] + b[(*x)];
b[height[i]] = val;
// trace(height[i], val);
curr.insert(height[i]);
x++;
x++;
while (x != curr.end() && b[*x] <= val) {
// trace(i, *x);
auto temp = x;
b[*x] = 0;
x++;
curr.erase(*temp);
}
}
// trace(i,curr.size());
// for(auto lo: curr){
// trace(lo, b[lo]);
// }
}
auto ans = curr.end();
ans--;
// trace(*ans, curr.size(), *(curr.end()));
// for(auto lo: curr){
// trace(lo, b[lo]);
// }
cout << b[(*ans)];
}
end_routine();
} | #ifndef bhartiya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;
#define pb push_back
#define bitc __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second
#define swap(a, b) \
{ \
a = a ^ b; \
b = a ^ b; \
a = a ^ b; \
}
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cout << "\n\nTime elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif
#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll maxn = 200005;
ll n;
ll a[maxn];
ll height[maxn];
ll b[maxn];
set<ll> curr;
int main() {
start_routine();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--) {
cin >> n;
rep(i, n) { cin >> height[i]; }
rep(i, n) { cin >> a[i]; }
rep(i, n) {
auto x = curr.lower_bound(height[i]);
if (x == curr.begin()) {
b[height[i]] = a[i];
curr.insert(height[i]);
x = curr.begin();
ll val = a[i];
x++;
while (x != curr.end() && b[*x] <= val) {
// trace(i, *x);
auto temp = x;
b[*x] = 0;
x++;
curr.erase(*temp);
}
} else {
x--;
ll val = a[i] + b[(*x)];
b[height[i]] = val;
// trace(height[i], val);
curr.insert(height[i]);
x++;
x++;
while (x != curr.end() && b[*x] <= val) {
// trace(i, *x);
auto temp = x;
b[*x] = 0;
x++;
curr.erase(*temp);
}
}
// trace(i,curr.size());
// for(auto lo: curr){
// trace(lo, b[lo]);
// }
}
auto ans = curr.end();
ans--;
// trace(*ans, curr.size(), *(curr.end()));
// for(auto lo: curr){
// trace(lo, b[lo]);
// }
cout << b[(*ans)];
}
end_routine();
} | replace | 85 | 86 | 85 | 86 | TLE | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod = 1e9 + 7;
const int N = 1e5 + 1;
vector<ll> a(N), h(N);
ll n;
vector<ll> dp(N);
struct dat {
ll minm = 2e18;
ll maxm = -minm;
dat() {} // default constructor
dat(ll val) { // declare constructor
minm = maxm = val;
}
};
struct SegmentTree {
vector<ll> arr;
ll n;
dat combine(const dat &l, const dat &r) { // combine Left and Right child
dat ret;
ret.minm = min(l.minm, r.minm);
ret.maxm = max(l.maxm, r.maxm);
return ret;
}
vector<dat> tree;
SegmentTree(vector<ll> &a) {
arr = a;
n = a.size();
tree.resize(4 * n);
build(1, 0, n - 1);
}
SegmentTree(ll cap) {
n = cap;
arr.resize(n, 0);
tree.resize(4 * n);
}
void build(ll v, ll tl, ll tr) {
if (tl == tr) {
tree[v] = dat(arr[tl]); // see base conditions
} else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
tree[v] = combine(tree[v * 2], tree[v * 2 + 1]);
}
}
void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
if (tl == tr) {
arr[pos] = new_val; // See update operations
tree[v] = dat(arr[pos]);
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
tree[v] = combine(tree[v * 2], tree[v * 2 + 1]);
}
}
dat query(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r)
return dat(); // See what to return
if (l == tl && r == tr) {
return tree[v];
}
ll tm = (tl + tr) / 2;
return combine(query(v * 2, tl, tm, l, min(r, tm)),
query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(ll pos, ll val) { update(1, 0, n - 1, pos, val); }
dat query(ll l, ll r) { return query(1, 0, n - 1, l, r); }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = clock();
cin >> n;
for (ll i = 0; i < n; i++)
cin >> h[i];
for (ll i = 0; i < n; i++)
cin >> a[i];
SegmentTree st(dp);
for (int i = 0; i < n; i++) {
// for(int j=0;j<h[i];j++)
// dp[h[i]]=max(dp[h[i]],a[i]+dp[j]);
dat r = st.query(0, h[i] - 1);
st.update(h[i], a[i] + r.maxm);
}
cout << st.query(0, n).maxm;
cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
T = clock();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod = 1e9 + 7;
const int N = 2e5 + 1;
vector<ll> a(N), h(N);
ll n;
vector<ll> dp(N);
struct dat {
ll minm = 2e18;
ll maxm = -minm;
dat() {} // default constructor
dat(ll val) { // declare constructor
minm = maxm = val;
}
};
struct SegmentTree {
vector<ll> arr;
ll n;
dat combine(const dat &l, const dat &r) { // combine Left and Right child
dat ret;
ret.minm = min(l.minm, r.minm);
ret.maxm = max(l.maxm, r.maxm);
return ret;
}
vector<dat> tree;
SegmentTree(vector<ll> &a) {
arr = a;
n = a.size();
tree.resize(4 * n);
build(1, 0, n - 1);
}
SegmentTree(ll cap) {
n = cap;
arr.resize(n, 0);
tree.resize(4 * n);
}
void build(ll v, ll tl, ll tr) {
if (tl == tr) {
tree[v] = dat(arr[tl]); // see base conditions
} else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
tree[v] = combine(tree[v * 2], tree[v * 2 + 1]);
}
}
void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
if (tl == tr) {
arr[pos] = new_val; // See update operations
tree[v] = dat(arr[pos]);
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
tree[v] = combine(tree[v * 2], tree[v * 2 + 1]);
}
}
dat query(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r)
return dat(); // See what to return
if (l == tl && r == tr) {
return tree[v];
}
ll tm = (tl + tr) / 2;
return combine(query(v * 2, tl, tm, l, min(r, tm)),
query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(ll pos, ll val) { update(1, 0, n - 1, pos, val); }
dat query(ll l, ll r) { return query(1, 0, n - 1, l, r); }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = clock();
cin >> n;
for (ll i = 0; i < n; i++)
cin >> h[i];
for (ll i = 0; i < n; i++)
cin >> a[i];
SegmentTree st(dp);
for (int i = 0; i < n; i++) {
// for(int j=0;j<h[i];j++)
// dp[h[i]]=max(dp[h[i]],a[i]+dp[j]);
dat r = st.query(0, h[i] - 1);
st.update(h[i], a[i] + r.maxm);
}
cout << st.query(0, n).maxm;
cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
T = clock();
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 |
TIME: 0.019961 sec
|
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
const int N = 100010;
int n;
long long tree[2 * N];
long long max(long long a, long long b) {
if (a > b)
return a;
return b;
}
void updateTreeNode(int p, long long value) {
tree[p + n] = value;
p = p + n;
for (int i = p; i > 1; i >>= 1)
tree[i >> 1] = max(tree[i], tree[i ^ 1]);
}
long long query(int l, int r) {
long long res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, tree[l++]);
if (r & 1)
res = max(res, tree[--r]);
}
return res;
}
int main() {
cin >> n;
vector<int> h;
vector<long long> p;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
h.push_back(a);
}
for (int i = 0; i < n; i++) {
int a;
cin >> a;
p.push_back(a);
}
for (int i = 0; i < n; i++) {
long long sf = query(1, h[i]);
// cout<<"sf: "<<sf<<endl;
updateTreeNode(h[i], sf + p[i]);
}
cout << query(1, n + 1);
return 0;
} | #include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
const int N = 262144;
int n;
long long tree[2 * N];
long long max(long long a, long long b) {
if (a > b)
return a;
return b;
}
void updateTreeNode(int p, long long value) {
tree[p + n] = value;
p = p + n;
for (int i = p; i > 1; i >>= 1)
tree[i >> 1] = max(tree[i], tree[i ^ 1]);
}
long long query(int l, int r) {
long long res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, tree[l++]);
if (r & 1)
res = max(res, tree[--r]);
}
return res;
}
int main() {
cin >> n;
vector<int> h;
vector<long long> p;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
h.push_back(a);
}
for (int i = 0; i < n; i++) {
int a;
cin >> a;
p.push_back(a);
}
for (int i = 0; i < n; i++) {
long long sf = query(1, h[i]);
// cout<<"sf: "<<sf<<endl;
updateTreeNode(h[i], sf + p[i]);
}
cout << query(1, n + 1);
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define f first
#define s second
const int N = 1e5 + 100;
long long int tree[4 * N];
long long int temp = -1e16;
long long int power(long long int x, long long int y, long long int mod) {
long long int res = 1LL;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return res;
}
bool compare(pair<long long int, long int> a, pair<long long int, long int> b) {
return a.s < b.s;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void update(long int node, long int l, long int r, long int ind, long int val) {
if (l == r) {
tree[node] = val;
} else {
long int mid = (l + r) / 2;
if (ind <= mid)
update(2 * node + 1, l, mid, ind, val);
else
update(2 * node + 2, mid + 1, r, ind, val);
tree[node] = max(tree[2 * node + 1], tree[2 * node + 2]);
}
}
long long int query(long int node, long int l, long int r, long int L,
long int R) {
if (r < L || R < l)
return temp;
else if (L <= l && R >= r)
return tree[node];
else {
long int mid = (l + r) / 2;
return max(query(2 * node + 1, l, mid, L, R),
query(2 * node + 2, mid + 1, r, L, R));
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int n;
cin >> n;
pair<long long int, long long int> a[n];
for (long int i = 0; i < n; i++) {
cin >> a[i].f;
}
for (long int i = 0; i < n; i++)
cin >> a[i].s;
long long int ans = 0;
for (long int i = 0; i < n; i++) {
long long int ans1 = query(0, 0, n, 1, a[i].f);
ans1 += a[i].s;
ans = max(ans1, ans);
update(0, 0, n, a[i].f, ans1);
}
cout << ans;
// your code goes here
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define f first
#define s second
const int N = 2e5 + 100;
long long int tree[4 * N];
long long int temp = -1e16;
long long int power(long long int x, long long int y, long long int mod) {
long long int res = 1LL;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return res;
}
bool compare(pair<long long int, long int> a, pair<long long int, long int> b) {
return a.s < b.s;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void update(long int node, long int l, long int r, long int ind, long int val) {
if (l == r) {
tree[node] = val;
} else {
long int mid = (l + r) / 2;
if (ind <= mid)
update(2 * node + 1, l, mid, ind, val);
else
update(2 * node + 2, mid + 1, r, ind, val);
tree[node] = max(tree[2 * node + 1], tree[2 * node + 2]);
}
}
long long int query(long int node, long int l, long int r, long int L,
long int R) {
if (r < L || R < l)
return temp;
else if (L <= l && R >= r)
return tree[node];
else {
long int mid = (l + r) / 2;
return max(query(2 * node + 1, l, mid, L, R),
query(2 * node + 2, mid + 1, r, L, R));
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int n;
cin >> n;
pair<long long int, long long int> a[n];
for (long int i = 0; i < n; i++) {
cin >> a[i].f;
}
for (long int i = 0; i < n; i++)
cin >> a[i].s;
long long int ans = 0;
for (long int i = 0; i < n; i++) {
long long int ans1 = query(0, 0, n, 1, a[i].f);
ans1 += a[i].s;
ans = max(ans1, ans);
update(0, 0, n, a[i].f, ans1);
}
cout << ans;
// your code goes here
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const long long MAXN = 100100;
const long long MOD = 1e9 + 7;
vector<long long> v1[MAXN];
long long fenwick[MAXN + 2];
long long arr[MAXN];
long long h[MAXN];
long long n;
void update(long long pos, long long val) {
for (; pos <= n; pos += (pos & (-pos))) {
fenwick[pos] = max(val, fenwick[pos]);
}
}
long long query(long long pos) {
long long ans = 0;
for (; pos; pos -= (pos & (-pos))) {
ans = max(ans, fenwick[pos]);
}
return ans;
}
long long ans;
int main() {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
for (long long i = 0; i < n; i++) {
cin >> h[i];
}
for (long long i = 0; i < n; i++) {
long long temp = query(arr[i]) + h[i];
ans = max(ans, temp);
update(arr[i], temp);
}
cout << ans << endl;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const long long MAXN = 200100;
const long long MOD = 1e9 + 7;
vector<long long> v1[MAXN];
long long fenwick[MAXN + 2];
long long arr[MAXN];
long long h[MAXN];
long long n;
void update(long long pos, long long val) {
for (; pos <= n; pos += (pos & (-pos))) {
fenwick[pos] = max(val, fenwick[pos]);
}
}
long long query(long long pos) {
long long ans = 0;
for (; pos; pos -= (pos & (-pos))) {
ans = max(ans, fenwick[pos]);
}
return ans;
}
long long ans;
int main() {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
for (long long i = 0; i < n; i++) {
cin >> h[i];
}
for (long long i = 0; i < n; i++) {
long long temp = query(arr[i]) + h[i];
ans = max(ans, temp);
update(arr[i], temp);
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long c[100001];
int h[100001], n;
int lowbit(int x) { return x & (-x); }
void updatemax(int index, long long value) {
while (index <= n && value > c[index]) {
c[index] = value;
index += lowbit(index);
}
}
long long maxrange(int index) {
long long maxv = 0;
while (index) {
maxv = max(maxv, c[index]);
index -= lowbit(index);
}
return maxv;
}
int main() {
int a, i;
long long t, maxv = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
t = maxrange(h[i] - 1) + a;
maxv = max(maxv, t);
updatemax(h[i], t);
}
printf("%lld", maxv);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long c[200001];
int h[200001], n;
int lowbit(int x) { return x & (-x); }
void updatemax(int index, long long value) {
while (index <= n && value > c[index]) {
c[index] = value;
index += lowbit(index);
}
}
long long maxrange(int index) {
long long maxv = 0;
while (index) {
maxv = max(maxv, c[index]);
index -= lowbit(index);
}
return maxv;
}
int main() {
int a, i;
long long t, maxv = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
t = maxrange(h[i] - 1) + a;
maxv = max(maxv, t);
updatemax(h[i], t);
}
printf("%lld", maxv);
return 0;
} | replace | 2 | 4 | 2 | 4 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define l long
#define ll long long
#define ld long double
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 100006
#define f first
#define s second
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULLL);
using namespace std;
vector<ll> tree(MAX_N);
vector<ll> dp(MAX_N);
void build(l v, l tl, l tr) {
if (tl == tr) {
tree[v] = dp[tl];
return;
}
l tm = (tl + tr) >> 1;
build(2L * v, tl, tm);
build(2L * v + 1, tm + 1, tr);
tree[v] = max(tree[2L * v], tree[2L * v + 1]);
return;
}
void update(ll val, l pos, l v, l tl, l tr) {
if (tl == tr) {
tree[v] = val;
dp[pos] = val;
return;
}
l tm = (tl + tr) >> 1;
if (pos <= tm)
update(val, pos, 2L * v, tl, tm);
else
update(val, pos, 2L * v + 1, tm + 1, tr);
tree[v] = max(tree[2L * v], tree[2L * v + 1]);
return;
}
ll rng_max(l lo, l hi, l v, l tl, l tr) {
if (lo > hi)
return -1;
if (lo == tl && hi == tr)
return tree[v];
l tm = (tl + tr) >> 1;
return max(rng_max(lo, min(hi, tm), 2L * v, tl, tm),
rng_max(max(lo, tm + 1), hi, 2L * v + 1, tm + 1, tr));
}
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
l n, x;
cin >> n;
vector<l> h;
vector<ll> a;
ll val;
for (l i = 0; i < n; i++) {
cin >> x;
h.push_back(x);
}
for (l i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
build(1L, 0L, n);
ll ans = 0;
for (l i = 0; i < n; i++) {
if (i == 0) {
update(a[i], h[i], 1L, 0L, n);
} else {
val = rng_max(0L, h[i] - 1, 1L, 0L, n);
update(val + a[i], h[i], 1L, 0L, n);
}
ans = max(ans, dp[h[i]]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define l long
#define ll long long
#define ld long double
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define f first
#define s second
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULLL);
using namespace std;
vector<ll> tree(MAX_N);
vector<ll> dp(MAX_N);
void build(l v, l tl, l tr) {
if (tl == tr) {
tree[v] = dp[tl];
return;
}
l tm = (tl + tr) >> 1;
build(2L * v, tl, tm);
build(2L * v + 1, tm + 1, tr);
tree[v] = max(tree[2L * v], tree[2L * v + 1]);
return;
}
void update(ll val, l pos, l v, l tl, l tr) {
if (tl == tr) {
tree[v] = val;
dp[pos] = val;
return;
}
l tm = (tl + tr) >> 1;
if (pos <= tm)
update(val, pos, 2L * v, tl, tm);
else
update(val, pos, 2L * v + 1, tm + 1, tr);
tree[v] = max(tree[2L * v], tree[2L * v + 1]);
return;
}
ll rng_max(l lo, l hi, l v, l tl, l tr) {
if (lo > hi)
return -1;
if (lo == tl && hi == tr)
return tree[v];
l tm = (tl + tr) >> 1;
return max(rng_max(lo, min(hi, tm), 2L * v, tl, tm),
rng_max(max(lo, tm + 1), hi, 2L * v + 1, tm + 1, tr));
}
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
l n, x;
cin >> n;
vector<l> h;
vector<ll> a;
ll val;
for (l i = 0; i < n; i++) {
cin >> x;
h.push_back(x);
}
for (l i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
build(1L, 0L, n);
ll ans = 0;
for (l i = 0; i < n; i++) {
if (i == 0) {
update(a[i], h[i], 1L, 0L, n);
} else {
val = rng_max(0L, h[i] - 1, 1L, 0L, n);
update(val + a[i], h[i], 1L, 0L, n);
}
ans = max(ans, dp[h[i]]);
}
cout << ans << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
vector<pair<long long, int>> item;
vector<long long> t;
void update(int v, int tl, int tr, int pos, long long val) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) >> 1;
int lc = (v << 1), rc = (v << 1) + 1;
if (pos <= tm) {
update(lc, tl, tm, pos, val);
} else {
update(rc, tm + 1, tr, pos, val);
}
t[v] = max(t[lc], t[rc]);
}
long long get(int v, int tl, int tr, int l, int r) {
if (l > r) {
return 0;
}
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) >> 1, lc = (v << 1), rc = (v << 1) + 1;
return max(get(lc, tl, tm, l, min(tm, r)),
get(rc, tm + 1, tr, max(tm + 1, l), r));
}
void solve() {
int n;
cin >> n;
item.resize(n);
for (int i = 0; i < n; i++) {
cin >> item[i].second;
}
for (int i = 0; i < n; i++) {
cin >> item[i].first;
}
int mx = 1e+5 + 1;
t.assign(4 * mx, 0);
long long ans = 0;
for (int i = 0; i < n; i++) {
long long getmax = get(1, 0, mx - 1, 0, item[i].second - 1);
long long dp = getmax + item[i].first;
update(1, 0, mx - 1, item[i].second, dp);
ans = max(ans, dp);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
vector<pair<long long, int>> item;
vector<long long> t;
void update(int v, int tl, int tr, int pos, long long val) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) >> 1;
int lc = (v << 1), rc = (v << 1) + 1;
if (pos <= tm) {
update(lc, tl, tm, pos, val);
} else {
update(rc, tm + 1, tr, pos, val);
}
t[v] = max(t[lc], t[rc]);
}
long long get(int v, int tl, int tr, int l, int r) {
if (l > r) {
return 0;
}
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) >> 1, lc = (v << 1), rc = (v << 1) + 1;
return max(get(lc, tl, tm, l, min(tm, r)),
get(rc, tm + 1, tr, max(tm + 1, l), r));
}
void solve() {
int n;
cin >> n;
item.resize(n);
for (int i = 0; i < n; i++) {
cin >> item[i].second;
}
for (int i = 0; i < n; i++) {
cin >> item[i].first;
}
int mx = 2 * 1e+5 + 1;
t.assign(4 * mx, 0);
long long ans = 0;
for (int i = 0; i < n; i++) {
long long getmax = get(1, 0, mx - 1, 0, item[i].second - 1);
long long dp = getmax + item[i].first;
update(1, 0, mx - 1, item[i].second, dp);
ans = max(ans, dp);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | replace | 63 | 64 | 63 | 64 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5 + 5;
LL a[MAX], b[MAX], dp[MAX];
LL ST[4 * MAX + 5];
LL query(LL start, LL end, LL node, LL s, LL e) {
if (e < start || s > end || start > end)
return 0;
if (s <= start && e >= end) {
return ST[node];
}
LL mid = (start + end) / 2;
return max(query(start, mid, 2 * node, s, e),
query(mid + 1, end, 2 * node + 1, s, e));
}
void update(LL start, LL end, LL node, LL pos, LL val) {
if (pos < start || pos > end || start > end)
return;
if (start == end) {
ST[node] = val;
return;
}
LL mid = (start + end) / 2;
if (pos >= start && pos <= mid)
update(start, mid, 2 * node, pos, val);
else
update(mid + 1, end, 2 * node + 1, pos, val);
ST[node] = max(ST[2 * node], ST[2 * node + 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(ST, 0, sizeof(ST));
LL n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
LL x = query(1, n, 1, 1, a[i]);
dp[i] = x + b[i];
update(1, n, 1, a[i], dp[i]);
}
LL ans = 0;
for (int i = 1; i <= n; i++) {
// cout << dp[i] << " ";
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 2e5 + 5;
LL a[MAX], b[MAX], dp[MAX];
LL ST[4 * MAX + 5];
LL query(LL start, LL end, LL node, LL s, LL e) {
if (e < start || s > end || start > end)
return 0;
if (s <= start && e >= end) {
return ST[node];
}
LL mid = (start + end) / 2;
return max(query(start, mid, 2 * node, s, e),
query(mid + 1, end, 2 * node + 1, s, e));
}
void update(LL start, LL end, LL node, LL pos, LL val) {
if (pos < start || pos > end || start > end)
return;
if (start == end) {
ST[node] = val;
return;
}
LL mid = (start + end) / 2;
if (pos >= start && pos <= mid)
update(start, mid, 2 * node, pos, val);
else
update(mid + 1, end, 2 * node + 1, pos, val);
ST[node] = max(ST[2 * node], ST[2 * node + 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(ST, 0, sizeof(ST));
LL n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
LL x = query(1, n, 1, 1, a[i]);
dp[i] = x + b[i];
update(1, n, 1, a[i], dp[i]);
}
LL ans = 0;
for (int i = 1; i <= n; i++) {
// cout << dp[i] << " ";
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef unsigned long long ULL;
typedef pair<double, double> PD;
#define FOR(x, b, e) for (int x = b; x <= (e); x++)
#define FORD(x, b, e) for (int x = b; x >= (e); x--)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007
#define MAXSIZE 200010
#define MAX_T 524300
int n;
int szer = 1;
LL tree[MAXSIZE];
int h[MAXSIZE];
LL query(int v, int l, int r, int a, int b) { //[l,r] szukany,[a,b] ogolny
if (l == a && b == r)
return tree[v];
int mid = (a + b - 1) / 2;
if (r <= mid)
return query(v * 2, l, r, a, mid);
else if (l > mid)
return query(v * 2 + 1, l, r, mid + 1, b);
else
return max(query(v * 2, l, mid, a, mid),
query(v * 2 + 1, mid + 1, r, mid + 1, b));
}
void ins(int p, LL val) {
p += szer;
tree[p] = val;
p /= 2;
while (p) {
tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
p /= 2;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while (szer <= n)
szer *= 2;
REP(i, n)
cin >> h[i];
REP(i, n) {
LL a1;
cin >> a1;
LL dp = query(1, 1, h[i], 0, szer - 1);
ins(h[i], a1 + dp);
}
cout << query(1, 1, n, 0, szer - 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef unsigned long long ULL;
typedef pair<double, double> PD;
#define FOR(x, b, e) for (int x = b; x <= (e); x++)
#define FORD(x, b, e) for (int x = b; x >= (e); x--)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007
#define MAXSIZE 200010
#define MAX_T 524300
int n;
int szer = 1;
LL tree[MAX_T];
int h[MAXSIZE];
LL query(int v, int l, int r, int a, int b) { //[l,r] szukany,[a,b] ogolny
if (l == a && b == r)
return tree[v];
int mid = (a + b - 1) / 2;
if (r <= mid)
return query(v * 2, l, r, a, mid);
else if (l > mid)
return query(v * 2 + 1, l, r, mid + 1, b);
else
return max(query(v * 2, l, mid, a, mid),
query(v * 2 + 1, mid + 1, r, mid + 1, b));
}
void ins(int p, LL val) {
p += szer;
tree[p] = val;
p /= 2;
while (p) {
tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
p /= 2;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while (szer <= n)
szer *= 2;
REP(i, n)
cin >> h[i];
REP(i, n) {
LL a1;
cin >> a1;
LL dp = query(1, 1, h[i], 0, szer - 1);
ins(h[i], a1 + dp);
}
cout << query(1, 1, n, 0, szer - 1);
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define int ll
const int N = 100000;
int n, a[N], h[N], dp[N];
#define all(x) x.begin(), x.end()
struct segment {
int seg[200001 * 4] = {0};
int pull(int x, int y) { return max(seg[x], seg[y]); }
void update(int id, int l, int r, int i, int v) {
if (l == r) {
seg[id] = max(seg[id], v);
return;
}
int m = (l + r) / 2;
if (i <= m)
update(id * 2 + 1, l, m, i, v);
else
update(id * 2 + 2, m + 1, r, i, v);
seg[id] = pull(id * 2 + 1, id * 2 + 2);
}
int query(int id, int l, int r, int ql, int qr) {
if (qr < l || r < ql)
return 0;
if (ql <= r && r <= qr)
return seg[id];
int m = (l + r) / 2;
return max(query(id * 2 + 1, l, m, ql, qr),
query(id * 2 + 2, m + 1, r, ql, qr));
}
} seg;
void bi() {
vector<int> tmp(h, h + n);
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
for (int i = 0; i < n; i++) {
h[i] = upper_bound(all(tmp), h[i]) - tmp.begin() - 1;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
bi();
dp[0] = a[0];
seg.update(0, 0, n - 1, h[0], a[0]);
int ans = a[0];
for (int i = 1; i < n; i++) {
dp[i] = seg.query(0, 0, n - 1, 0, h[i] - 1) + a[i];
seg.update(0, 0, n - 1, h[i], dp[i]);
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define int ll
const int N = 200001;
int n, a[N], h[N], dp[N];
#define all(x) x.begin(), x.end()
struct segment {
int seg[200001 * 4] = {0};
int pull(int x, int y) { return max(seg[x], seg[y]); }
void update(int id, int l, int r, int i, int v) {
if (l == r) {
seg[id] = max(seg[id], v);
return;
}
int m = (l + r) / 2;
if (i <= m)
update(id * 2 + 1, l, m, i, v);
else
update(id * 2 + 2, m + 1, r, i, v);
seg[id] = pull(id * 2 + 1, id * 2 + 2);
}
int query(int id, int l, int r, int ql, int qr) {
if (qr < l || r < ql)
return 0;
if (ql <= r && r <= qr)
return seg[id];
int m = (l + r) / 2;
return max(query(id * 2 + 1, l, m, ql, qr),
query(id * 2 + 2, m + 1, r, ql, qr));
}
} seg;
void bi() {
vector<int> tmp(h, h + n);
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
for (int i = 0; i < n; i++) {
h[i] = upper_bound(all(tmp), h[i]) - tmp.begin() - 1;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
bi();
dp[0] = a[0];
seg.update(0, 0, n - 1, h[0], a[0]);
int ans = a[0];
for (int i = 1; i < n; i++) {
dp[i] = seg.query(0, 0, n - 1, 0, h[i] - 1) + a[i];
seg.update(0, 0, n - 1, h[i], dp[i]);
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03176 | C++ | Time Limit Exceeded | #include <iostream>
#include <stdio.h>
#define Re register int
#define LL long long
int N, H[200005], A[200005];
LL f[200005], T[800005], ans;
template <typename T> inline void read(T &var) {
T x = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch))
w |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
var = w ? -x : x;
}
void Add(int id, int l, int r, int pos, LL v) {
if (l == r && l == pos) {
T[id] = std::max(T[id], v);
return;
}
int mid = (l + r) >> 1;
if (pos <= mid)
Add(id << 1, l, mid, pos, v);
else
Add(id << 1 | 1, mid + 1, r, pos, v);
T[id] = std::max(T[id << 1], T[id << 1 | 1]);
}
LL Query(int id, int l, int r, int pos) {
if (r <= pos)
return T[id];
int mid = (l + r) >> 1;
LL ret = Query(id << 1, l, mid, pos);
if (mid < pos)
ret = std::max(ret, Query(id << 1 | 1, mid + 1, r, pos));
return ret;
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
// freopen("1.ans","w",stdout);
#endif
read(N);
for (Re i = 1; i <= N; ++i)
read(H[i]);
for (Re i = 1; i <= N; ++i)
read(A[i]), f[i] = A[i];
ans = A[1], Add(1, 1, N, H[1], f[1]);
for (Re i = 2; i <= N; ++i) {
f[i] = Query(1, 1, N, H[i]) + A[i];
Add(1, 1, N, H[i], f[i]);
ans = std::max(ans, f[i]);
}
printf("%lld\n", ans);
return 0;
} | #include <iostream>
#include <stdio.h>
#define Re register int
#define LL long long
int N, H[200005], A[200005];
LL f[200005], T[800005], ans;
template <typename T> inline void read(T &var) {
T x = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch))
w |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
var = w ? -x : x;
}
void Add(int id, int l, int r, int pos, LL v) {
if (l == r && l == pos) {
T[id] = std::max(T[id], v);
return;
}
int mid = (l + r) >> 1;
if (pos <= mid)
Add(id << 1, l, mid, pos, v);
else
Add(id << 1 | 1, mid + 1, r, pos, v);
T[id] = std::max(T[id << 1], T[id << 1 | 1]);
}
LL Query(int id, int l, int r, int pos) {
if (r <= pos)
return T[id];
int mid = (l + r) >> 1;
LL ret = Query(id << 1, l, mid, pos);
if (mid < pos)
ret = std::max(ret, Query(id << 1 | 1, mid + 1, r, pos));
return ret;
}
int main(int argc, char const *argv[]) {
read(N);
for (Re i = 1; i <= N; ++i)
read(H[i]);
for (Re i = 1; i <= N; ++i)
read(A[i]), f[i] = A[i];
ans = A[1], Add(1, 1, N, H[1], f[1]);
for (Re i = 2; i <= N; ++i) {
f[i] = Query(1, 1, N, H[i]) + A[i];
Add(1, 1, N, H[i], f[i]);
ans = std::max(ans, f[i]);
}
printf("%lld\n", ans);
return 0;
} | delete | 40 | 44 | 40 | 40 | TLE | |
p03176 | C++ | Runtime Error | /*
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair<int, int>
#define vi vector<int>
// #define =1e9 =(int)1e9
const ll mod = 1000000007;
const ll nmax = 3000001;
#define int ll
int n, h[100005], a[100005], seg[400005];
void upd(int nod, int l, int r, int pos, int v) {
if (l == r)
seg[nod] = v;
else {
int mid = (l + r) >> 1;
if (pos <= mid)
upd(2 * nod, l, mid, pos, v);
else
upd(2 * nod + 1, mid + 1, r, pos, v);
seg[nod] = max(seg[2 * nod], seg[2 * nod + 1]);
}
}
int qry(int nod, int l, int r, int lq, int rq) {
if (rq < l || r < lq)
return 0LL;
else if (lq <= l && r <= rq)
return seg[nod];
else {
int mid = (l + r) >> 1;
return max(qry(2 * nod, l, mid, lq, rq),
qry(2 * nod + 1, mid + 1, r, lq, rq));
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
int x = qry(1, 1, n, 1, h[i]);
upd(1, 1, n, h[i], x + a[i]);
// cout<<"i: "; for(int j=1; j<=n; j++) cout<<qry(1, 1, n, j, j)<<" ";
// cout<<endl;
}
cout << qry(1, 1, n, 1, n);
}
| /*
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair<int, int>
#define vi vector<int>
// #define =1e9 =(int)1e9
const ll mod = 1000000007;
const ll nmax = 3000001;
#define int ll
int n, h[200005], a[200005], seg[800005];
void upd(int nod, int l, int r, int pos, int v) {
if (l == r)
seg[nod] = v;
else {
int mid = (l + r) >> 1;
if (pos <= mid)
upd(2 * nod, l, mid, pos, v);
else
upd(2 * nod + 1, mid + 1, r, pos, v);
seg[nod] = max(seg[2 * nod], seg[2 * nod + 1]);
}
}
int qry(int nod, int l, int r, int lq, int rq) {
if (rq < l || r < lq)
return 0LL;
else if (lq <= l && r <= rq)
return seg[nod];
else {
int mid = (l + r) >> 1;
return max(qry(2 * nod, l, mid, lq, rq),
qry(2 * nod + 1, mid + 1, r, lq, rq));
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
int x = qry(1, 1, n, 1, h[i]);
upd(1, 1, n, h[i], x + a[i]);
// cout<<"i: "; for(int j=1; j<=n; j++) cout<<qry(1, 1, n, j, j)<<" ";
// cout<<endl;
}
cout << qry(1, 1, n, 1, n);
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 100010
using namespace std;
ll tree[4 * N], A[N], h[N];
void update(int low, int high, int ind, ll val, int node) {
if (low == high) {
tree[node] = val;
return;
}
int mid = (low + high) / 2;
if (ind <= mid)
update(low, mid, ind, val, 2 * node);
else
update(mid + 1, high, ind, val, 2 * node + 1);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
ll query(int low, int high, int begin, int end, int node) {
if (low > end || high < begin || begin > end)
return -1e18;
if (low >= begin && high <= end)
return tree[node];
int mid = (low + high) / 2;
return max(query(low, mid, begin, end, 2 * node),
query(mid + 1, high, begin, end, 2 * node + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> A[i];
ll maxi = 0;
for (int i = 0; i < n; i++) {
ll ans = A[i] + query(0, n - 1, 0, h[i] - 1, 1);
// cerr << ans << '\n';
update(0, n - 1, h[i], ans, 1);
maxi = max(maxi, ans);
}
cout << maxi << '\n';
} | #include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 200010
using namespace std;
ll tree[4 * N], A[N], h[N];
void update(int low, int high, int ind, ll val, int node) {
if (low == high) {
tree[node] = val;
return;
}
int mid = (low + high) / 2;
if (ind <= mid)
update(low, mid, ind, val, 2 * node);
else
update(mid + 1, high, ind, val, 2 * node + 1);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
ll query(int low, int high, int begin, int end, int node) {
if (low > end || high < begin || begin > end)
return -1e18;
if (low >= begin && high <= end)
return tree[node];
int mid = (low + high) / 2;
return max(query(low, mid, begin, end, 2 * node),
query(mid + 1, high, begin, end, 2 * node + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> A[i];
ll maxi = 0;
for (int i = 0; i < n; i++) {
ll ans = A[i] + query(0, n - 1, 0, h[i] - 1, 1);
// cerr << ans << '\n';
update(0, n - 1, h[i], ans, 1);
maxi = max(maxi, ans);
}
cout << maxi << '\n';
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03176 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) (x & -x)
const int maxn = 100001;
int n;
ll h[maxn];
ll a[maxn];
ll dp[maxn];
ll bit[maxn];
ll query(ll x) {
ll res = 0;
for (; x; x -= lowbit(x)) {
res = max(bit[x], res);
}
return res;
}
void update(ll x, ll y) {
for (; x <= n; x += lowbit(x)) {
bit[x] = max(bit[x], y);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
dp[i] = query(h[i]) + a[i];
update(h[i], dp[i]);
}
cout << query(n) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) (x & -x)
const int maxn = 200001;
int n;
ll h[maxn];
ll a[maxn];
ll dp[maxn];
ll bit[maxn];
ll query(ll x) {
ll res = 0;
for (; x; x -= lowbit(x)) {
res = max(bit[x], res);
}
return res;
}
void update(ll x, ll y) {
for (; x <= n; x += lowbit(x)) {
bit[x] = max(bit[x], y);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
dp[i] = query(h[i]) + a[i];
update(h[i], dp[i]);
}
cout << query(n) << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1ll << 60)
int n;
vector<vector<int>> G;
class BIT {
public:
vector<long long> bit;
int M;
BIT(int M) : bit(vector<long long>(M + 1, -(1ll << 60))), M(M) {}
long long sum(int i) {
if (i <= 0)
return 0;
return max(bit[i], sum(i - (i & -i)));
}
void add(int i, long long x) {
if (i > M)
return;
bit[i] = max(bit[i], x);
add(i + (i & -i), x);
}
};
int main(int argc, char const *argv[]) {
cin >> n;
vector<long long> h(n + 1, -1);
vector<long long> a(n + 1, 0), b(n + 1, 0);
vector<long long> dp(n + 1, 0);
for (int i = 0; i < n; ++i)
cin >> h[i + 1];
for (int i = 0; i < n; ++i)
cin >> a[i + 1];
for (int i = 0; i <= n; ++i)
b[h[i]] = i;
long long res = 0;
int m = (1 << 20);
BIT bit(m);
bit.add(1, 0);
for (int i = 1; i <= n; ++i) {
int k = b[i];
long long tmp = bit.sum(1 + k) + a[k];
res = max(res, tmp);
bit.add(1 + k, tmp);
}
cout << res << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1ll << 60)
int n;
vector<vector<int>> G;
class BIT {
public:
vector<long long> bit;
int M;
BIT(int M) : bit(vector<long long>(M + 1, -(1ll << 60))), M(M) {}
long long sum(int i) {
if (i <= 0)
return 0;
return max(bit[i], sum(i - (i & -i)));
}
void add(int i, long long x) {
if (i > M)
return;
bit[i] = max(bit[i], x);
add(i + (i & -i), x);
}
};
int main(int argc, char const *argv[]) {
cin >> n;
vector<long long> h(n + 1, 0);
vector<long long> a(n + 1, 0), b(n + 1, 0);
vector<long long> dp(n + 1, 0);
for (int i = 0; i < n; ++i)
cin >> h[i + 1];
for (int i = 0; i < n; ++i)
cin >> a[i + 1];
for (int i = 0; i <= n; ++i)
b[h[i]] = i;
long long res = 0;
int m = (1 << 20);
BIT bit(m);
bit.add(1, 0);
for (int i = 1; i <= n; ++i) {
int k = b[i];
long long tmp = bit.sum(1 + k) + a[k];
res = max(res, tmp);
bit.add(1 + k, tmp);
}
cout << res << endl;
return 0;
} | replace | 41 | 42 | 41 | 42 | -6 | free(): invalid pointer
|
p03176 | C++ | Runtime Error | //****** @mdazmat9 **********
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(), (a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define trace1(x) cout << #x << ": " << x << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define trace(v) \
for (auto it = v.begin(); it != v.end(); it++) \
cout << *it << " "; \
cout << endl;
const int inf = 1e17;
int fast_pow(int x, int y, int p);
const int sz = 300001;
int st[4 * sz];
int n;
void update(int ss, int se, int i, int val, int si) {
if (i < ss || i > se) {
return;
}
if (ss == se) {
st[si] = val;
return;
}
int mid = (ss + se) / 2;
if (i >= ss && i <= mid)
update(ss, mid, i, val, 2 * si + 1);
else
update(mid + 1, se, i, val, 2 * si + 2);
st[si] = max(st[2 * si + 1], st[2 * si + 2]);
}
int get_max(int ss, int se, int qs, int qe, int si) {
if (qs <= ss && qe >= se)
return st[si];
if (se < qs || ss > qe)
return 0;
int mid = (ss + se) / 2;
return max(get_max(ss, mid, qs, qe, 2 * si + 1),
get_max(mid + 1, se, qs, qe, 2 * si + 2));
}
void solve() {
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
int left = get_max(0, n - 1, 0, a[i] - 1, 0);
ans = max(ans, left + b[i]);
update(0, n - 1, a[i], left + b[i], 0);
}
cout << ans << endl;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int test = 1;
// cin>>test;
for (int i = 1; i <= test; i++) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
int fast_pow(int x, int y, int p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
} | //****** @mdazmat9 **********
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(), (a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define trace1(x) cout << #x << ": " << x << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define trace(v) \
for (auto it = v.begin(); it != v.end(); it++) \
cout << *it << " "; \
cout << endl;
const int inf = 1e17;
int fast_pow(int x, int y, int p);
const int sz = 300001;
int st[4 * sz];
int n;
void update(int ss, int se, int i, int val, int si) {
if (i < ss || i > se) {
return;
}
if (ss == se) {
st[si] = val;
return;
}
int mid = (ss + se) / 2;
if (i >= ss && i <= mid)
update(ss, mid, i, val, 2 * si + 1);
else
update(mid + 1, se, i, val, 2 * si + 2);
st[si] = max(st[2 * si + 1], st[2 * si + 2]);
}
int get_max(int ss, int se, int qs, int qe, int si) {
if (qs <= ss && qe >= se)
return st[si];
if (se < qs || ss > qe)
return 0;
int mid = (ss + se) / 2;
return max(get_max(ss, mid, qs, qe, 2 * si + 1),
get_max(mid + 1, se, qs, qe, 2 * si + 2));
}
void solve() {
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
int left = get_max(0, n - 1, 0, a[i] - 1, 0);
ans = max(ans, left + b[i]);
update(0, n - 1, a[i], left + b[i], 0);
}
cout << ans << endl;
}
int32_t main() {
IOS;
int test = 1;
// cin>>test;
for (int i = 1; i <= test; i++) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
int fast_pow(int x, int y, int p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
} | replace | 95 | 99 | 95 | 96 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
ll abi[maxn];
int N;
int h[maxn], b[maxn];
void update(int pos, ll v) {
for (; pos <= N; pos += pos & -pos)
abi[pos] = max(abi[pos], v);
}
ll query(int pos) {
ll sum = 0;
for (; pos; pos -= pos & -pos)
sum = max(abi[pos], sum);
return sum;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(".in","r",stdin);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
for (int i = 1; i <= N; i++) {
cin >> b[i];
}
for (int i = 1; i <= N; i++) {
ll x = query(h[i] - 1) + b[i];
update(h[i], x);
}
cout << query(N);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
typedef long long ll;
ll abi[maxn];
int N;
int h[maxn], b[maxn];
void update(int pos, ll v) {
for (; pos <= N; pos += pos & -pos)
abi[pos] = max(abi[pos], v);
}
ll query(int pos) {
ll sum = 0;
for (; pos; pos -= pos & -pos)
sum = max(abi[pos], sum);
return sum;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(".in","r",stdin);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
for (int i = 1; i <= N; i++) {
cin >> b[i];
}
for (int i = 1; i <= N; i++) {
ll x = query(h[i] - 1) + b[i];
update(h[i], x);
}
cout << query(N);
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | // template {{{
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
using ld = long double;
using ll = long long;
inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}
const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9 + 7;
const int N = 100500;
int a[N], v[N];
struct BIT {
ll f[N];
BIT() {
for (int i = 0; i < N; i++)
f[i] = 0;
}
void update(int x, ll c) {
for (; x < N; x += x & (-x))
f[x] = max(f[x], c);
}
ll query(int x) {
ll ret = 0;
for (; x; x -= x & (-x))
ret = max(ret, f[x]);
return ret;
}
};
void solve() {
int n;
cin >> n;
ll ans = 0;
BIT bit;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> v[i];
for (int i = 0; i < n; i++) {
ll q = bit.query(a[i]) + v[i];
ans = max(ans, q);
bit.update(a[i], q);
}
cout << ans << endl;
}
// main {{{
int main() {
cin.sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); }
inline ll subm(ll __a, ll __b, ll __m = MOD) {
return (((__a - __b) % __m + __m) % __m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); }
ll powm(ll __a, ll __b, ll __m = MOD) {
ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m);
return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); }
// }}}
| // template {{{
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
using ld = long double;
using ll = long long;
inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}
const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9 + 7;
const int N = 200500;
int a[N], v[N];
struct BIT {
ll f[N];
BIT() {
for (int i = 0; i < N; i++)
f[i] = 0;
}
void update(int x, ll c) {
for (; x < N; x += x & (-x))
f[x] = max(f[x], c);
}
ll query(int x) {
ll ret = 0;
for (; x; x -= x & (-x))
ret = max(ret, f[x]);
return ret;
}
};
void solve() {
int n;
cin >> n;
ll ans = 0;
BIT bit;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> v[i];
for (int i = 0; i < n; i++) {
ll q = bit.query(a[i]) + v[i];
ans = max(ans, q);
bit.update(a[i], q);
}
cout << ans << endl;
}
// main {{{
int main() {
cin.sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); }
inline ll subm(ll __a, ll __b, ll __m = MOD) {
return (((__a - __b) % __m + __m) % __m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); }
ll powm(ll __a, ll __b, ll __m = MOD) {
ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m);
return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); }
// }}}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100010;
const int MOD = 1000000007;
const int LOG = 20;
ll fen[N];
int n, h[N], a[N];
void add(int id, ll x) {
id++;
for (; id < N; id += id & (-id))
fen[id] = max(fen[id], x);
}
ll get(int id) {
id++;
ll res = 0;
for (; id; id -= id & (-id))
res = max(res, fen[id]);
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
ll x = get(h[i] - 1) + a[i];
add(h[i], x);
}
cout << get(n);
return 0;
} | #include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
const int MOD = 1000000007;
const int LOG = 20;
ll fen[N];
int n, h[N], a[N];
void add(int id, ll x) {
id++;
for (; id < N; id += id & (-id))
fen[id] = max(fen[id], x);
}
ll get(int id) {
id++;
ll res = 0;
for (; id; id -= id & (-id))
res = max(res, fen[id]);
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
ll x = get(h[i] - 1) + a[i];
add(h[i], x);
}
cout << get(n);
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p03176 | C++ | Runtime Error | // csjosh
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required
// using namespace __gnu_pbds; //required
using namespace std;
#define ll long long
#define loop(x) for (int i = 0; i < x; i++)
#define llu unsigned long long
#define pb push_back
#define sc(x) scanf("%lld", &x)
#define pr(x) printf("%lld\n", x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mt make_tuple // use tie
#define eb emplace_back
typedef tuple<int, int, int> State; // use in dijkstra
// ll mod=1e9+7;
// ll power(ll x,ll y,ll mod){
// ll ans=1;
// while(y>0){
// if(y&1){
// ans=ans*x;
// }
// x=x*x;
// y=y/2;
// }
// return ans;
// }
// typedef tree<
// pair<int, int>,
// null_type,
// less<pair<int, int>>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
int n;
ll a[100006];
ll h[100006];
ll tree[4 * 1000005];
ll update(int root, int x, int start, int end, ll val) {
if ((x < start) || (x > end))
return 0;
if (start == end) {
tree[root] = max(tree[root], val);
return tree[root];
}
ll p1 = 0, p2 = 0;
int mid = (start + end) / 2;
p1 = update(2 * root, x, start, mid, val);
p2 = update(2 * root + 1, x, mid + 1, end, val);
return tree[root] = max(tree[root], max(p1, p2));
}
ll query(int root, int l, int r, int start, int end) {
if (start > end)
return 0;
if (r < start || l > end)
return 0;
if (l <= start && r >= end)
return tree[root];
int mid = (start + end) / 2;
ll p1 = query(2 * root, l, r, start, mid);
ll p2 = query(2 * root + 1, l, r, mid + 1, end);
return max(p1, p2);
}
int main() {
IOS;
cin >> n;
// memset(bit,0,sizeof bit);
loop(n) cin >> h[i + 1];
loop(n) cin >> a[i + 1];
// first use of segment trees
ll maxsum = 0;
for (int i = 1; i <= n; i++) {
maxsum = query(1, 1, h[i], 1, n) + a[i];
update(1, h[i], 1, n, maxsum);
}
cout << query(1, 1, n, 1, n) << endl;
}
| // csjosh
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required
// using namespace __gnu_pbds; //required
using namespace std;
#define ll long long
#define loop(x) for (int i = 0; i < x; i++)
#define llu unsigned long long
#define pb push_back
#define sc(x) scanf("%lld", &x)
#define pr(x) printf("%lld\n", x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mt make_tuple // use tie
#define eb emplace_back
typedef tuple<int, int, int> State; // use in dijkstra
// ll mod=1e9+7;
// ll power(ll x,ll y,ll mod){
// ll ans=1;
// while(y>0){
// if(y&1){
// ans=ans*x;
// }
// x=x*x;
// y=y/2;
// }
// return ans;
// }
// typedef tree<
// pair<int, int>,
// null_type,
// less<pair<int, int>>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
int n;
ll a[400006];
ll h[400006];
ll tree[4 * 1000005];
ll update(int root, int x, int start, int end, ll val) {
if ((x < start) || (x > end))
return 0;
if (start == end) {
tree[root] = max(tree[root], val);
return tree[root];
}
ll p1 = 0, p2 = 0;
int mid = (start + end) / 2;
p1 = update(2 * root, x, start, mid, val);
p2 = update(2 * root + 1, x, mid + 1, end, val);
return tree[root] = max(tree[root], max(p1, p2));
}
ll query(int root, int l, int r, int start, int end) {
if (start > end)
return 0;
if (r < start || l > end)
return 0;
if (l <= start && r >= end)
return tree[root];
int mid = (start + end) / 2;
ll p1 = query(2 * root, l, r, start, mid);
ll p2 = query(2 * root + 1, l, r, mid + 1, end);
return max(p1, p2);
}
int main() {
IOS;
cin >> n;
// memset(bit,0,sizeof bit);
loop(n) cin >> h[i + 1];
loop(n) cin >> a[i + 1];
// first use of segment trees
ll maxsum = 0;
for (int i = 1; i <= n; i++) {
maxsum = query(1, 1, h[i], 1, n) + a[i];
update(1, h[i], 1, n, maxsum);
}
cout << query(1, 1, n, 1, n) << endl;
}
| replace | 45 | 47 | 45 | 47 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1> class Binary_Index_Tree {
private:
CLASS1 n;
// [1, n]
vector<CLASS1> bit;
public:
Binary_Index_Tree(CLASS1 n_) {
bit.resize(n_ + 1, 0);
n = n_ + 1;
return;
};
~Binary_Index_Tree(void) { return; };
CLASS1 submax(CLASS1 i) {
if (i < -1 || n <= i) {
fprintf(stderr, "Binary_Index_Tree Sum Position Error\n");
exit(0);
}
CLASS1 s = 0;
i += 1;
while (i > 0) {
s = max(s, bit[i]);
i -= i & (-i);
}
return s;
};
void update(CLASS1 i, CLASS1 x) {
if (i < 0 || n <= i) {
fprintf(stderr, "Binary_Index_Tree Update Position Error\n");
exit(0);
}
i += 1;
while (i <= n) {
bit[i] = max(bit[i], x);
i += i & (-i);
}
return;
};
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
ll N;
cin >> N;
Binary_Index_Tree<ll> que(N);
vll dp(N + 1, 0), h(N), a(N);
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
REP(i, N) {
dp[i] = que.submax(h[i] - 1) + a[i];
que.update(h[i], dp[i]);
}
ll ans = 0;
REP(i, N + 1) { ans = max(ans, dp[i]); }
cout << ans << "\n";
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1> class Binary_Index_Tree {
private:
CLASS1 n;
// [1, n]
vector<CLASS1> bit;
public:
Binary_Index_Tree(CLASS1 n_) {
bit.resize(n_ + 1, 0);
n = n_ + 1;
return;
};
~Binary_Index_Tree(void) { return; };
CLASS1 submax(CLASS1 i) {
if (i < -1 || n <= i) {
fprintf(stderr, "Binary_Index_Tree Sum Position Error\n");
exit(0);
}
CLASS1 s = 0;
i += 1;
while (i > 0) {
s = max(s, bit[i]);
i -= i & (-i);
}
return s;
};
void update(CLASS1 i, CLASS1 x) {
if (i < 0 || n <= i) {
fprintf(stderr, "Binary_Index_Tree Update Position Error\n");
exit(0);
}
i += 1;
while (i <= n) {
bit[i] = max(bit[i], x);
i += i & (-i);
}
return;
};
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
ll N;
cin >> N;
Binary_Index_Tree<ll> que(N + 1);
vll dp(N + 1, 0), h(N), a(N);
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
REP(i, N) {
dp[i] = que.submax(h[i] - 1) + a[i];
que.update(h[i], dp[i]);
}
ll ans = 0;
REP(i, N + 1) { ans = max(ans, dp[i]); }
cout << ans << "\n";
return 0;
}
| replace | 123 | 125 | 123 | 124 | -6 | munmap_chunk(): invalid pointer
|
p03176 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define MAXN 100500
using namespace std;
int a[MAXN];
int h[MAXN];
long long ans[MAXN];
int n;
long long answer;
struct tree {
int l;
int r;
long long maks;
int left_child;
int right_child;
};
tree g[4 * MAXN];
void create_tree(int v) {
if (g[v].l == g[v].r) {
return;
}
g[v].left_child = v * 2 + 1;
g[v * 2 + 1].l = g[v].l;
g[v * 2 + 1].r = (g[v].r + g[v].l) / 2;
create_tree(2 * v + 1);
g[v].right_child = v * 2 + 2;
g[v * 2 + 2].l = (g[v].r + g[v].l) / 2 + 1;
g[v * 2 + 2].r = g[v].r;
create_tree(2 * v + 2);
}
void add_tree(int v, long long k) {
int now = 0;
while (g[now].l != g[now].r) {
g[now].maks = max(g[now].maks, k);
if (v >= g[g[now].left_child].l && v <= g[g[now].left_child].r) {
now = g[now].left_child;
} else {
now = g[now].right_child;
}
}
g[now].maks = max(g[now].maks, k);
}
long long find_tree(int l, int r, int v) {
// printf("find_tree: l=%i r=%i v=%i\n", l, r, v);
if (g[v].r < l || r < g[v].l) {
// printf(" find_tree: v=%i returns 0\n", v);
return 0;
}
// if (g[v].l > l && g[v].r < r){
if (l <= g[v].l && g[v].r <= r) {
// printf(" find_tree: v=%i returns %i\n", v, g[v].maks);
return g[v].maks;
}
long long tmp =
max(find_tree(l, r, g[v].left_child), find_tree(l, r, g[v].right_child));
// printf(" find_tree: v=%i returns %i\n", v, tmp);
return tmp;
}
void dbg(int v, long long k) {
if (g[v].l != g[v].r) {
dbg(g[v].right_child, k + 1);
}
for (int i = 1; i <= k; i++) {
cout << " ";
}
cout << g[v].maks << endl;
if (g[v].l != g[v].r) {
dbg(g[v].left_child, k + 1);
}
}
int main() {
cin >> n;
g[0].l = 1;
g[0].r = n;
create_tree(0);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
ans[1] = a[1];
add_tree(h[1], ans[1]);
for (int i = 2; i <= n; i++) {
// dbg(0, 0);
// cout << endl;
// cout << endl;
/*answer = 0;
for (int j = 1; j < i; j++){
if (h[i] > h[j] && answer < ans[j]){
answer = ans[j];
}
}*/
// printf("find_tree(1, %i - 1) = %i\n", h[i], find_tree(1, h[i] - 1, 0));
ans[i] = a[i] + find_tree(1, h[i] - 1, 0);
add_tree(h[i], ans[i]);
}
long long answer = 0;
for (int i = 1; i <= n; i++) {
// cout << ans[i] << ' ';
if (answer < ans[i])
answer = ans[i];
}
// cout << endl;
cout << answer;
} | #include <cstdio>
#include <iostream>
#define MAXN 200500
using namespace std;
int a[MAXN];
int h[MAXN];
long long ans[MAXN];
int n;
long long answer;
struct tree {
int l;
int r;
long long maks;
int left_child;
int right_child;
};
tree g[4 * MAXN];
void create_tree(int v) {
if (g[v].l == g[v].r) {
return;
}
g[v].left_child = v * 2 + 1;
g[v * 2 + 1].l = g[v].l;
g[v * 2 + 1].r = (g[v].r + g[v].l) / 2;
create_tree(2 * v + 1);
g[v].right_child = v * 2 + 2;
g[v * 2 + 2].l = (g[v].r + g[v].l) / 2 + 1;
g[v * 2 + 2].r = g[v].r;
create_tree(2 * v + 2);
}
void add_tree(int v, long long k) {
int now = 0;
while (g[now].l != g[now].r) {
g[now].maks = max(g[now].maks, k);
if (v >= g[g[now].left_child].l && v <= g[g[now].left_child].r) {
now = g[now].left_child;
} else {
now = g[now].right_child;
}
}
g[now].maks = max(g[now].maks, k);
}
long long find_tree(int l, int r, int v) {
// printf("find_tree: l=%i r=%i v=%i\n", l, r, v);
if (g[v].r < l || r < g[v].l) {
// printf(" find_tree: v=%i returns 0\n", v);
return 0;
}
// if (g[v].l > l && g[v].r < r){
if (l <= g[v].l && g[v].r <= r) {
// printf(" find_tree: v=%i returns %i\n", v, g[v].maks);
return g[v].maks;
}
long long tmp =
max(find_tree(l, r, g[v].left_child), find_tree(l, r, g[v].right_child));
// printf(" find_tree: v=%i returns %i\n", v, tmp);
return tmp;
}
void dbg(int v, long long k) {
if (g[v].l != g[v].r) {
dbg(g[v].right_child, k + 1);
}
for (int i = 1; i <= k; i++) {
cout << " ";
}
cout << g[v].maks << endl;
if (g[v].l != g[v].r) {
dbg(g[v].left_child, k + 1);
}
}
int main() {
cin >> n;
g[0].l = 1;
g[0].r = n;
create_tree(0);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
ans[1] = a[1];
add_tree(h[1], ans[1]);
for (int i = 2; i <= n; i++) {
// dbg(0, 0);
// cout << endl;
// cout << endl;
/*answer = 0;
for (int j = 1; j < i; j++){
if (h[i] > h[j] && answer < ans[j]){
answer = ans[j];
}
}*/
// printf("find_tree(1, %i - 1) = %i\n", h[i], find_tree(1, h[i] - 1, 0));
ans[i] = a[i] + find_tree(1, h[i] - 1, 0);
add_tree(h[i], ans[i]);
}
long long answer = 0;
for (int i = 1; i <= n; i++) {
// cout << ans[i] << ' ';
if (answer < ans[i])
answer = ans[i];
}
// cout << endl;
cout << answer;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
using lint = long long;
struct RMQ {
static const lint MAX_N = 1 << 17;
lint n, dat[2 * MAX_N - 1];
RMQ() {}
RMQ(lint n_) { init(n_); }
void init(lint n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 0;
}
void update(lint k, lint a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
lint query(lint a, lint b, lint k, lint l, lint r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return dat[k];
else {
lint vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
lint vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
lint query(lint a, lint b) { return query(a, b, 0, 0, n); }
};
signed main() {
int N;
cin >> N;
vector<lint> h(N), a(N);
RMQ rmq(N + 10);
for (int i = 0; i < N; i++)
cin >> h[i], h[i]--;
for (int i = 0; i < N; i++)
cin >> a[i];
lint ans = 0;
for (int i = 0; i < N; i++) {
lint ans1 = a[i] + rmq.query(0, h[i]);
ans = max(ans, ans1);
rmq.update(h[i], ans1);
}
cout << ans << endl;
}
| #include "bits/stdc++.h"
using namespace std;
using lint = long long;
struct RMQ {
static const lint MAX_N = 3e5;
lint n, dat[2 * MAX_N - 1];
RMQ() {}
RMQ(lint n_) { init(n_); }
void init(lint n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 0;
}
void update(lint k, lint a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
lint query(lint a, lint b, lint k, lint l, lint r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return dat[k];
else {
lint vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
lint vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
lint query(lint a, lint b) { return query(a, b, 0, 0, n); }
};
signed main() {
int N;
cin >> N;
vector<lint> h(N), a(N);
RMQ rmq(N + 10);
for (int i = 0; i < N; i++)
cin >> h[i], h[i]--;
for (int i = 0; i < N; i++)
cin >> a[i];
lint ans = 0;
for (int i = 0; i < N; i++) {
lint ans1 = a[i] + rmq.query(0, h[i]);
ans = max(ans, ans1);
rmq.update(h[i], ans1);
}
cout << ans << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long
#define N 200
Int dp[N];
Int tree[2 * N + 1];
Int a[N], f[N];
void update(Int x, Int v, Int node, Int l, Int r) {
if (l == r) {
tree[node] = v;
return;
}
Int mid = (l + r) / 2;
if (x <= mid) {
update(x, v, (2 * node), l, mid);
} else {
update(x, v, (2 * node + 1), mid + 1, r);
}
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
Int Q(Int s, Int e, Int node, Int l, Int r) {
if (l >= s && r <= e)
return tree[node];
else if (l > e || r < s)
return 0;
int mid = (l + r) / 2;
Int x = Q(s, e, 2 * node, l, mid);
Int y = Q(s, e, 2 * node + 1, mid + 1, r);
return max(x, y);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Int n, m;
cin >> n;
for (Int i = 1; i <= n; i++)
cin >> a[i];
for (Int i = 1; i <= n; i++)
cin >> f[i];
for (Int i = 1; i <= n; i++) {
dp[a[i]] = Q(1, (a[i] - 1), 1, 1, n) + f[i];
update(a[i], dp[a[i]], 1, 1, n);
// cout<<a[i]<< " "<<Q(1,(a[i]),1,1,n)<<" "<<dp[a[i]]<<endl;
}
Int ans = 0;
for (Int i = 1; i <= n; i++)
ans = max(ans, dp[a[i]]);
// for(Int i = 1;i<=(2*n-1);i++)cout<<i<<" "<<tree[i]<<endl;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long
#define N 200200
Int dp[N];
Int tree[2 * N + 1];
Int a[N], f[N];
void update(Int x, Int v, Int node, Int l, Int r) {
if (l == r) {
tree[node] = v;
return;
}
Int mid = (l + r) / 2;
if (x <= mid) {
update(x, v, (2 * node), l, mid);
} else {
update(x, v, (2 * node + 1), mid + 1, r);
}
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
Int Q(Int s, Int e, Int node, Int l, Int r) {
if (l >= s && r <= e)
return tree[node];
else if (l > e || r < s)
return 0;
int mid = (l + r) / 2;
Int x = Q(s, e, 2 * node, l, mid);
Int y = Q(s, e, 2 * node + 1, mid + 1, r);
return max(x, y);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Int n, m;
cin >> n;
for (Int i = 1; i <= n; i++)
cin >> a[i];
for (Int i = 1; i <= n; i++)
cin >> f[i];
for (Int i = 1; i <= n; i++) {
dp[a[i]] = Q(1, (a[i] - 1), 1, 1, n) + f[i];
update(a[i], dp[a[i]], 1, 1, n);
// cout<<a[i]<< " "<<Q(1,(a[i]),1,1,n)<<" "<<dp[a[i]]<<endl;
}
Int ans = 0;
for (Int i = 1; i <= n; i++)
ans = max(ans, dp[a[i]]);
// for(Int i = 1;i<=(2*n-1);i++)cout<<i<<" "<<tree[i]<<endl;
cout << ans << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03176 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
long long t[512000];
int h[200001];
int n;
long long query(int index, int lb, int rb, int lq, int rq) {
if (lb == rb)
return t[index];
if (rb == rq && lb == lq)
return t[index];
int mid = (lb + rb) / 2;
if (rq <= mid)
return query(index * 2, lb, mid, lq, rq);
else if (lq > mid)
return query(index * 2 + 1, mid + 1, rb, lq, rq);
else
return max(query(index * 2, lb, mid, lq, mid),
query(index * 2 + 1, mid + 1, rb, mid + 1, rq));
}
long long update(int index, int lb, int rb, int leaf_id, long long value) {
if (lb == rb && lb == leaf_id)
return t[index] = value;
int mid = (lb + rb) / 2;
if (leaf_id <= mid)
return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value));
else
return t[index] = max(t[index],
update(index * 2 + 1, mid + 1, rb, leaf_id, value));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++) {
long long a;
scanf("%lld", &a);
update(1, 1, n, h[i], (long long)query(1, 1, n, 1, h[i] - 1) + a);
}
printf("%lld", t[1]);
} | #include "bits/stdc++.h"
using namespace std;
long long t[600000];
int h[200001];
int n;
long long query(int index, int lb, int rb, int lq, int rq) {
if (lb == rb)
return t[index];
if (rb == rq && lb == lq)
return t[index];
int mid = (lb + rb) / 2;
if (rq <= mid)
return query(index * 2, lb, mid, lq, rq);
else if (lq > mid)
return query(index * 2 + 1, mid + 1, rb, lq, rq);
else
return max(query(index * 2, lb, mid, lq, mid),
query(index * 2 + 1, mid + 1, rb, mid + 1, rq));
}
long long update(int index, int lb, int rb, int leaf_id, long long value) {
if (lb == rb && lb == leaf_id)
return t[index] = value;
int mid = (lb + rb) / 2;
if (leaf_id <= mid)
return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value));
else
return t[index] = max(t[index],
update(index * 2 + 1, mid + 1, rb, leaf_id, value));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++) {
long long a;
scanf("%lld", &a);
update(1, 1, n, h[i], (long long)query(1, 1, n, 1, h[i] - 1) + a);
}
printf("%lld", t[1]);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define pb push_back
// #all(x) (x).begin(),(x).end()
// int const N = 1;
int const MOD = 1e9 + 7;
ll bigmod(ll a, ll b) {
if (b == 0)
return 1 % MOD;
ll x = bigmod(a, b / 2);
x = (x * x) % MOD;
if (b % 2)
x = (x * a) % MOD;
return x;
}
int const N = 1e5 + 10; //;
ll h[N], seg[4 * N];
ll dp[N];
ll Q(int pos, int l, int r, int ql, int qr) {
if (l > qr or r < ql)
return 0;
if (ql <= l and r <= qr)
return seg[pos];
int mid = (l + r) / 2;
return max(Q(pos * 2, l, mid, ql, qr), Q(pos * 2 + 1, mid + 1, r, ql, qr));
}
void update(int pos, int l, int r, int ind, ll val) {
if (l == r and r == ind) {
seg[pos] = val;
return;
}
if (l > ind or r < ind)
return;
int mid = (l + r) / 2;
update(pos * 2, l, mid, ind, val);
update(pos * 2 + 1, mid + 1, r, ind, val);
seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
}
int n;
ll val[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> val[i];
dp[0] = 0;
for (int i = 1; i <= n; i++) {
if (h[i] == 1) {
dp[i] = val[i];
update(1, 1, n, h[i], val[i]);
continue;
}
ll here = Q(1, 1, n, 1, h[i] - 1);
dp[i] = val[i] + here;
update(1, 1, n, h[i], dp[i]);
}
cout << *max_element(dp + 1, dp + n + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define pb push_back
// #all(x) (x).begin(),(x).end()
// int const N = 1;
int const MOD = 1e9 + 7;
ll bigmod(ll a, ll b) {
if (b == 0)
return 1 % MOD;
ll x = bigmod(a, b / 2);
x = (x * x) % MOD;
if (b % 2)
x = (x * a) % MOD;
return x;
}
int const N = 2e5 + 10; //;
ll h[N], seg[4 * N];
ll dp[N];
ll Q(int pos, int l, int r, int ql, int qr) {
if (l > qr or r < ql)
return 0;
if (ql <= l and r <= qr)
return seg[pos];
int mid = (l + r) / 2;
return max(Q(pos * 2, l, mid, ql, qr), Q(pos * 2 + 1, mid + 1, r, ql, qr));
}
void update(int pos, int l, int r, int ind, ll val) {
if (l == r and r == ind) {
seg[pos] = val;
return;
}
if (l > ind or r < ind)
return;
int mid = (l + r) / 2;
update(pos * 2, l, mid, ind, val);
update(pos * 2 + 1, mid + 1, r, ind, val);
seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
}
int n;
ll val[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> val[i];
dp[0] = 0;
for (int i = 1; i <= n; i++) {
if (h[i] == 1) {
dp[i] = val[i];
update(1, 1, n, h[i], val[i]);
continue;
}
ll here = Q(1, 1, n, 1, h[i] - 1);
dp[i] = val[i] + here;
update(1, 1, n, h[i], dp[i]);
}
cout << *max_element(dp + 1, dp + n + 1);
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p03176 | C++ | Runtime Error | // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#ifdef PERVEEVM_LOCAL
#define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
#define debug(x) 238;
#endif
#define fastIO \
std::ios_base::sync_with_stdio(false); \
std::cin.tie(0); \
std::cout.tie(0)
#define NAME "File"
using ll = long long;
using ld = long double;
#ifdef PERVEEVM_LOCAL
std::mt19937 rnd(238);
#else
std::mt19937
rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 1 << 17;
class Node {
public:
ll max;
int l, r;
Node() : max(-LINF), l(-1), r(-1) {}
Node(ll val, int l, int r) : max(val), l(l), r(r) {}
Node operator+(const Node &other) const {
return Node(std::max(max, other.max), l, other.r);
}
};
Node tree[2 * N];
void build() {
for (int i = 0; i < N; ++i) {
tree[i + N] = Node(0, i, i + 1);
}
for (int i = N - 1; i > 0; --i) {
tree[i] = tree[i * 2] + tree[i * 2 + 1];
}
}
Node get(int v, int l, int r) {
if (tree[v].r <= l || r <= tree[v].l) {
return Node();
}
if (l <= tree[v].l && tree[v].r <= r) {
return tree[v];
}
return get(v * 2, l, r) + get(v * 2 + 1, l, r);
}
void upd(int pos, ll newVal) {
pos += N;
tree[pos].max = newVal;
pos /= 2;
while (pos > 0) {
tree[pos] = tree[pos * 2] + tree[pos * 2 + 1];
pos /= 2;
}
}
int h[N], a[N];
void run() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &h[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
build();
for (int i = 0; i < n; ++i) {
Node val = get(1, 0, h[i]);
upd(h[i], val.max + a[i]);
}
printf("%lld\n", get(1, 0, N).max);
}
int main(void) {
// freopen(NAME".in", "r", stdin);
// freopen(NAME".out", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
run();
auto end = std::chrono::high_resolution_clock::now();
#ifdef PERVEEVM_LOCAL
std::cerr << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
start)
.count()
<< " ms" << std::endl;
#endif
return 0;
}
| // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#ifdef PERVEEVM_LOCAL
#define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
#define debug(x) 238;
#endif
#define fastIO \
std::ios_base::sync_with_stdio(false); \
std::cin.tie(0); \
std::cout.tie(0)
#define NAME "File"
using ll = long long;
using ld = long double;
#ifdef PERVEEVM_LOCAL
std::mt19937 rnd(238);
#else
std::mt19937
rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 1 << 18;
class Node {
public:
ll max;
int l, r;
Node() : max(-LINF), l(-1), r(-1) {}
Node(ll val, int l, int r) : max(val), l(l), r(r) {}
Node operator+(const Node &other) const {
return Node(std::max(max, other.max), l, other.r);
}
};
Node tree[2 * N];
void build() {
for (int i = 0; i < N; ++i) {
tree[i + N] = Node(0, i, i + 1);
}
for (int i = N - 1; i > 0; --i) {
tree[i] = tree[i * 2] + tree[i * 2 + 1];
}
}
Node get(int v, int l, int r) {
if (tree[v].r <= l || r <= tree[v].l) {
return Node();
}
if (l <= tree[v].l && tree[v].r <= r) {
return tree[v];
}
return get(v * 2, l, r) + get(v * 2 + 1, l, r);
}
void upd(int pos, ll newVal) {
pos += N;
tree[pos].max = newVal;
pos /= 2;
while (pos > 0) {
tree[pos] = tree[pos * 2] + tree[pos * 2 + 1];
pos /= 2;
}
}
int h[N], a[N];
void run() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &h[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
build();
for (int i = 0; i < n; ++i) {
Node val = get(1, 0, h[i]);
upd(h[i], val.max + a[i]);
}
printf("%lld\n", get(1, 0, N).max);
}
int main(void) {
// freopen(NAME".in", "r", stdin);
// freopen(NAME".out", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
run();
auto end = std::chrono::high_resolution_clock::now();
#ifdef PERVEEVM_LOCAL
std::cerr << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
start)
.count()
<< " ms" << std::endl;
#endif
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define FOR(i, b) For(i, 0, b)
#define Rev(i, a, b) for (auto i = (a); i > (b); i--)
#define REV(i, a) Rev(i, a, -1)
#define FORE(i, a) for (auto &&i : a)
template <class C> constexpr int sz(const C &c) { return int(c.size()); }
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pill = pair<int, ll>;
using plli = pair<ll, int>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;
constexpr const char nl = '\n', sp = ' ';
constexpr const int INT_INF = 0x3f3f3f3f;
constexpr const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
constexpr const double D_INF = numeric_limits<double>::infinity();
constexpr const ld LD_INF = numeric_limits<ld>::infinity();
template <class T> constexpr const T &_min(const T &x, const T &y) {
return x < y ? x : y;
}
template <class T> constexpr const T &_max(const T &x, const T &y) {
return x < y ? y : x;
}
template <class T, class... Ts>
constexpr const T &_min(const T &x, const Ts &...xs) {
return _min(x, _min(xs...));
}
template <class T, class... Ts>
constexpr const T &_max(const T &x, const Ts &...xs) {
return _max(x, _max(xs...));
}
template <class T, class... Ts> void MIN(T &x, const Ts &...xs) {
x = _min(x, xs...);
}
template <class T, class... Ts> void MAX(T &x, const Ts &...xs) {
x = _max(x, xs...);
}
template <class T>
constexpr const T &_clamp(const T &v, const T &lo, const T &hi) {
return v < lo ? lo : hi < v ? hi : v;
}
template <class T> void CLAMP(T &v, const T &lo, const T &hi) {
v = _clamp(v, lo, hi);
}
template <class T, class... Args> unique_ptr<T> _make_unique(Args &&...args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template <class T, class... Args> shared_ptr<T> _make_shared(Args &&...args) {
return shared_ptr<T>(new T(forward<Args>(args)...));
}
#define min(...) _min(__VA_ARGS__)
#define max(...) _max(__VA_ARGS__)
#define clamp(...) _clamp(__VA_ARGS__)
#define make_unique _make_unique
#define make_shared _make_shared
template <class... Ts> using uset = unordered_set<Ts...>;
template <class... Ts> using umap = unordered_map<Ts...>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <class T> using maxpq = priority_queue<T, vector<T>, less<T>>;
template <class T1, class T2, class H1 = hash<T1>, class H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2> &p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
template <class T> struct is_iterator {
template <class U, typename enable_if<!is_convertible<U, const char *>::value,
int>::type = 0>
constexpr static auto has_indirection(int)
-> decltype(*declval<U>(), bool()) {
return true;
}
template <class> constexpr static bool has_indirection(long) { return false; }
constexpr static bool value = has_indirection<T>(0);
};
seed_seq seq{(uint64_t)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count(),
(uint64_t)__builtin_ia32_rdtsc(),
(uint64_t)(uintptr_t)make_unique<char>().get()};
mt19937 rng(seq);
mt19937_64 rng64(seq);
constexpr const int _bufferSize = 4096, _maxNumLength = 128;
char _inputBuffer[_bufferSize + 1],
*_inputPtr = _inputBuffer, _outputBuffer[_bufferSize], _c, _sign,
*_tempInputBuf = nullptr, _numBuf[_maxNumLength],
_tempOutputBuf[_maxNumLength], _fill = ' ';
FILE *_input = stdin, *_output = stdout, *_error = stderr;
const char *_delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
ull _precisionBase = 1000000;
#define _peekchar() \
(*_inputPtr ? *_inputPtr \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr))
#define _getchar() \
(*_inputPtr ? *_inputPtr++ \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr++))
#define _hasNext() (*_inputPtr || !feof(_input))
#define _readSignAndNum(x) \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
_sign = (x) == '-'; \
if (_sign) \
(x) = _getchar(); \
for ((x) -= '0'; (_c = _getchar()) >= '0'; (x) = (x)*10 + _c - '0')
#define _readFloatingPoint(x, T) \
for (T _div = 1.0; (_c = _getchar()) >= '0'; (x) += (_c - '0') / (_div *= 10))
#define rc(x) \
do { \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
} while (0)
#define ri(x) \
do { \
_readSignAndNum(x); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rd(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, double); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rld(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, ld); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rcs(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) > ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rs(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcs(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define rcln(x) \
do { \
_cur = 0; \
while ((_c = _getchar()) != '\n') { \
if (_c != '\r') \
(x)[_cur++] = _c; \
} \
(x)[_cur] = '\0'; \
} while (0)
#define rln(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcln(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
void setLength(int x) {
if (_tempInputBuf)
delete[] (_tempInputBuf);
_tempInputBuf = new char[x + 1];
}
void read(int &x) { ri(x); }
void read(uint &x) { ri(x); }
void read(ll &x) { ri(x); }
void read(ull &x) { ri(x); }
void read(double &x) { rd(x); }
void read(ld &x) { rld(x); }
void read(char &x) { rc(x); }
void read(char *x) { rcs(x); }
void read(string &x) { rs(x); }
void readln(char *x) { rcln(x); }
void readln(string &x) { rln(x); }
template <class T1, class T2> void read(pair<T1, T2> &x) {
read(x.first);
read(x.second);
}
template <class T> void read(complex<T> &x) {
T _re, _im;
read(_re);
read(_im);
x.real(_re);
x.imag(_im);
}
template <class T> void read(T &x);
template <class T, class... Ts> void read(T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type read(It st, It en) {
for (It _i = st; _i != en; _i++)
read(*_i);
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type read(It st, It en,
Ts &&...xs) {
read(st, en);
read(forward<Ts>(xs)...);
}
template <class T> void read(T &x) {
for (auto &&_i : x)
read(_i);
}
template <class T, class... Ts> void read(T &x, Ts &&...xs) {
read(x);
read(forward<Ts>(xs)...);
}
bool hasNext() {
while (_hasNext() && _peekchar() <= ' ')
_getchar();
return _hasNext();
}
bool hasNextLine() {
while (_hasNext() && _peekchar() == '\r')
_getchar();
return _hasNext();
}
void setInput(FILE *file) {
*_inputPtr = '\0';
_input = file;
}
void setInput(const char *s) {
*_inputPtr = '\0';
_input = fopen(s, "r");
}
void setInput(const string &s) {
*_inputPtr = '\0';
_input = fopen(s.c_str(), "r");
}
#define _flush() \
do { \
_flushBuf(); \
fflush(_output); \
} while (0)
#define _flushBuf() \
(fwrite(_outputBuffer, 1, _outputPtr, _output), _outputPtr = 0)
#define _putchar(x) \
(_outputBuffer[_outputPtr == _bufferSize ? _flushBuf() : _outputPtr] = (x), \
_outputPtr++)
#define _writeTempBuf(x) (_tempOutputBuf[_tempOutputPtr++] = (x))
#define _writeOutput() \
for (int _i = 0; _i < _tempOutputPtr; _putchar(_tempOutputBuf[_i++])) \
; \
_tempOutputPtr = 0
#define _writeNum(x, T, digits) \
_cnt = 0; \
for (T _y = (x); _y; _y /= 10, _cnt++) \
_numBuf[_numPtr++] = '0' + _y % 10; \
for (; _cnt < digits; _cnt++) \
_numBuf[_numPtr++] = '0'; \
_flushNumBuf();
#define _writeFloatingPoint(x, T) \
ull _I = (ull)(x); \
ull _F = ((x)-_I) * _precisionBase + (T)(0.5); \
if (_F >= _precisionBase) { \
_I++; \
_F = 0; \
} \
_writeNum(_I, ull, 1); \
_writeTempBuf('.'); \
_writeNum(_F, ull, _precision)
#define _checkFinite(x) \
if (std::isnan(x)) { \
wcs("NaN"); \
} else if (std::isinf(x)) { \
wcs("Inf"); \
}
#define _flushNumBuf() for (; _numPtr; _writeTempBuf(_numBuf[--_numPtr]))
#define _fillBuf(x) \
for (int _i = 0; _i < (x); _i++) \
_putchar(_fill)
#define _flushTempBuf() \
int _tempLen = _tempOutputPtr; \
_fillBuf(_width - _tempLen); \
_writeOutput(); \
_fillBuf(-_width - _tempLen)
#define wb(x) \
do { \
if (x) \
_writeTempBuf('1'); \
else \
_writeTempBuf('0'); \
_flushTempBuf(); \
} while (0)
#define wc(x) \
do { \
_writeTempBuf(x); \
_flushTempBuf(); \
} while (0)
#define wi(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), uint, 1); \
} else { \
_writeNum(x, uint, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wll(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), ull, 1); \
} else { \
_writeNum(x, ull, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wd(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), double); \
} \
else { \
_writeFloatingPoint(x, double); \
} \
_flushTempBuf(); \
} while (0)
#define wld(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), ld); \
} \
else { \
_writeFloatingPoint(x, ld); \
} \
_flushTempBuf(); \
} while (0)
#define wcs(x) \
do { \
int _slen = strlen(x); \
_fillBuf(_width - _slen); \
for (const char *_p = (x); *_p; _putchar(*_p++)) \
; \
_fillBuf(-_width - _slen); \
} while (0)
#define ws(x) \
do { \
_fillBuf(_width - int((x).length())); \
for (int _i = 0; _i < int((x).length()); _putchar(x[_i++])) \
; \
_fillBuf(-_width - int((x).length())); \
} while (0)
void setPrecision(int x) {
_precision = x;
_precisionBase = 1;
for (int _i = 0; _i < x; _i++, _precisionBase *= 10)
;
}
void setWidth(int x) { _width = x; }
void setFill(char x) { _fill = x; }
void setDelimiter(const char *x) { _delimiter = x; }
void setDelimiter(const string &x) { _delimiter = x.c_str(); }
void writeDelimiter() {
for (const char *_p = _delimiter; *_p; _putchar(*_p++))
;
}
void write(const bool &x) { wb(x); }
void write(const int &x) { wi(x); }
void write(const uint &x) { wi(x); }
void write(const ll &x) { wll(x); }
void write(const ull &x) { wll(x); }
void write(const double &x) { wd(x); }
void write(const ld &x) { wld(x); }
void write(const char &x) { wc(x); }
void write(const char *x) { wcs(x); }
void write(const string &x) { ws(x); }
template <class T1, class T2> void write(const pair<T1, T2> &x) {
write(x.first);
writeDelimiter();
write(x.second);
}
template <class T> void write(const complex<T> &x) {
write(x.real());
writeDelimiter();
write(x.imag());
}
template <class T> void write(const T &x);
template <class T, class... Ts> void write(const T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type write(It st, It en) {
bool _first = 1;
for (It _i = st; _i != en; _i++) {
if (_first)
_first = 0;
else
writeDelimiter();
write(*_i);
}
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type write(It st, It en,
Ts &&...xs) {
write(st, en);
writeDelimiter();
write(forward<Ts>(xs)...);
}
template <class T> void write(const T &x) {
bool _first = 1;
for (auto &&_i : x) {
if (_first)
_first = 0;
else
writeDelimiter();
write(_i);
}
}
template <class T, class... Ts> void write(const T &x, Ts &&...xs) {
write(x);
writeDelimiter();
write(forward<Ts>(xs)...);
}
void writeln() { _putchar('\n'); }
template <class... Ts> void writeln(Ts &&...xs) {
write(forward<Ts>(xs)...);
_putchar('\n');
}
void flush() { _flush(); }
class IOManager {
public:
~IOManager() {
flush();
if (_tempInputBuf)
delete[] (_tempInputBuf);
}
};
unique_ptr<IOManager> iomanager = make_unique<IOManager>();
void setOutput(FILE *file) {
flush();
_output = file;
}
void setOutput(const char *s) {
flush();
_output = fopen(s, "w");
}
void setOutput(const string &s) {
flush();
_output = fopen(s.c_str(), "w");
}
template <class... Ts> void debug(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
write(xs...);
setOutput(_temp);
}
template <class... Ts> void debugln(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
writeln(xs...);
setOutput(_temp);
}
void setError(FILE *file) {
flush();
_error = file;
}
void setError(const char *s) {
flush();
_error = fopen(s, "w");
}
void setError(const string &s) {
flush();
_error = fopen(s.c_str(), "w");
}
template <const int MAXN, class T> struct FenwickTreeMax {
T BIT[MAXN], NEG_INF;
FenwickTreeMax(T NEG_INF) : NEG_INF(NEG_INF) {
fill(BIT, BIT + MAXN, NEG_INF);
}
void update(int i, T v) {
for (; i < MAXN; i += i & -i)
BIT[i] = max(BIT[i], v);
}
T rmq(int i) {
T ret = NEG_INF;
for (; i > 0; i -= i & -i)
ret = max(ret, BIT[i]);
return ret;
}
};
const int MAXN = 1e5 + 5;
int N, H[MAXN];
ll A[MAXN];
FenwickTreeMax<MAXN, ll> BIT(0);
int main() {
// setInput("in.txt");
// setOutput("out.txt");
// setError("err.txt");
read(N);
read(H, H + N, A, A + N);
ll ans = 0;
FOR(i, N) {
ll val = BIT.rmq(H[i]) + A[i];
MAX(ans, val);
BIT.update(H[i], val);
}
writeln(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define FOR(i, b) For(i, 0, b)
#define Rev(i, a, b) for (auto i = (a); i > (b); i--)
#define REV(i, a) Rev(i, a, -1)
#define FORE(i, a) for (auto &&i : a)
template <class C> constexpr int sz(const C &c) { return int(c.size()); }
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pill = pair<int, ll>;
using plli = pair<ll, int>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;
constexpr const char nl = '\n', sp = ' ';
constexpr const int INT_INF = 0x3f3f3f3f;
constexpr const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
constexpr const double D_INF = numeric_limits<double>::infinity();
constexpr const ld LD_INF = numeric_limits<ld>::infinity();
template <class T> constexpr const T &_min(const T &x, const T &y) {
return x < y ? x : y;
}
template <class T> constexpr const T &_max(const T &x, const T &y) {
return x < y ? y : x;
}
template <class T, class... Ts>
constexpr const T &_min(const T &x, const Ts &...xs) {
return _min(x, _min(xs...));
}
template <class T, class... Ts>
constexpr const T &_max(const T &x, const Ts &...xs) {
return _max(x, _max(xs...));
}
template <class T, class... Ts> void MIN(T &x, const Ts &...xs) {
x = _min(x, xs...);
}
template <class T, class... Ts> void MAX(T &x, const Ts &...xs) {
x = _max(x, xs...);
}
template <class T>
constexpr const T &_clamp(const T &v, const T &lo, const T &hi) {
return v < lo ? lo : hi < v ? hi : v;
}
template <class T> void CLAMP(T &v, const T &lo, const T &hi) {
v = _clamp(v, lo, hi);
}
template <class T, class... Args> unique_ptr<T> _make_unique(Args &&...args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template <class T, class... Args> shared_ptr<T> _make_shared(Args &&...args) {
return shared_ptr<T>(new T(forward<Args>(args)...));
}
#define min(...) _min(__VA_ARGS__)
#define max(...) _max(__VA_ARGS__)
#define clamp(...) _clamp(__VA_ARGS__)
#define make_unique _make_unique
#define make_shared _make_shared
template <class... Ts> using uset = unordered_set<Ts...>;
template <class... Ts> using umap = unordered_map<Ts...>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <class T> using maxpq = priority_queue<T, vector<T>, less<T>>;
template <class T1, class T2, class H1 = hash<T1>, class H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2> &p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
template <class T> struct is_iterator {
template <class U, typename enable_if<!is_convertible<U, const char *>::value,
int>::type = 0>
constexpr static auto has_indirection(int)
-> decltype(*declval<U>(), bool()) {
return true;
}
template <class> constexpr static bool has_indirection(long) { return false; }
constexpr static bool value = has_indirection<T>(0);
};
seed_seq seq{(uint64_t)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count(),
(uint64_t)__builtin_ia32_rdtsc(),
(uint64_t)(uintptr_t)make_unique<char>().get()};
mt19937 rng(seq);
mt19937_64 rng64(seq);
constexpr const int _bufferSize = 4096, _maxNumLength = 128;
char _inputBuffer[_bufferSize + 1],
*_inputPtr = _inputBuffer, _outputBuffer[_bufferSize], _c, _sign,
*_tempInputBuf = nullptr, _numBuf[_maxNumLength],
_tempOutputBuf[_maxNumLength], _fill = ' ';
FILE *_input = stdin, *_output = stdout, *_error = stderr;
const char *_delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
ull _precisionBase = 1000000;
#define _peekchar() \
(*_inputPtr ? *_inputPtr \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr))
#define _getchar() \
(*_inputPtr ? *_inputPtr++ \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr++))
#define _hasNext() (*_inputPtr || !feof(_input))
#define _readSignAndNum(x) \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
_sign = (x) == '-'; \
if (_sign) \
(x) = _getchar(); \
for ((x) -= '0'; (_c = _getchar()) >= '0'; (x) = (x)*10 + _c - '0')
#define _readFloatingPoint(x, T) \
for (T _div = 1.0; (_c = _getchar()) >= '0'; (x) += (_c - '0') / (_div *= 10))
#define rc(x) \
do { \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
} while (0)
#define ri(x) \
do { \
_readSignAndNum(x); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rd(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, double); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rld(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, ld); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rcs(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) > ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rs(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcs(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define rcln(x) \
do { \
_cur = 0; \
while ((_c = _getchar()) != '\n') { \
if (_c != '\r') \
(x)[_cur++] = _c; \
} \
(x)[_cur] = '\0'; \
} while (0)
#define rln(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcln(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
void setLength(int x) {
if (_tempInputBuf)
delete[] (_tempInputBuf);
_tempInputBuf = new char[x + 1];
}
void read(int &x) { ri(x); }
void read(uint &x) { ri(x); }
void read(ll &x) { ri(x); }
void read(ull &x) { ri(x); }
void read(double &x) { rd(x); }
void read(ld &x) { rld(x); }
void read(char &x) { rc(x); }
void read(char *x) { rcs(x); }
void read(string &x) { rs(x); }
void readln(char *x) { rcln(x); }
void readln(string &x) { rln(x); }
template <class T1, class T2> void read(pair<T1, T2> &x) {
read(x.first);
read(x.second);
}
template <class T> void read(complex<T> &x) {
T _re, _im;
read(_re);
read(_im);
x.real(_re);
x.imag(_im);
}
template <class T> void read(T &x);
template <class T, class... Ts> void read(T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type read(It st, It en) {
for (It _i = st; _i != en; _i++)
read(*_i);
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type read(It st, It en,
Ts &&...xs) {
read(st, en);
read(forward<Ts>(xs)...);
}
template <class T> void read(T &x) {
for (auto &&_i : x)
read(_i);
}
template <class T, class... Ts> void read(T &x, Ts &&...xs) {
read(x);
read(forward<Ts>(xs)...);
}
bool hasNext() {
while (_hasNext() && _peekchar() <= ' ')
_getchar();
return _hasNext();
}
bool hasNextLine() {
while (_hasNext() && _peekchar() == '\r')
_getchar();
return _hasNext();
}
void setInput(FILE *file) {
*_inputPtr = '\0';
_input = file;
}
void setInput(const char *s) {
*_inputPtr = '\0';
_input = fopen(s, "r");
}
void setInput(const string &s) {
*_inputPtr = '\0';
_input = fopen(s.c_str(), "r");
}
#define _flush() \
do { \
_flushBuf(); \
fflush(_output); \
} while (0)
#define _flushBuf() \
(fwrite(_outputBuffer, 1, _outputPtr, _output), _outputPtr = 0)
#define _putchar(x) \
(_outputBuffer[_outputPtr == _bufferSize ? _flushBuf() : _outputPtr] = (x), \
_outputPtr++)
#define _writeTempBuf(x) (_tempOutputBuf[_tempOutputPtr++] = (x))
#define _writeOutput() \
for (int _i = 0; _i < _tempOutputPtr; _putchar(_tempOutputBuf[_i++])) \
; \
_tempOutputPtr = 0
#define _writeNum(x, T, digits) \
_cnt = 0; \
for (T _y = (x); _y; _y /= 10, _cnt++) \
_numBuf[_numPtr++] = '0' + _y % 10; \
for (; _cnt < digits; _cnt++) \
_numBuf[_numPtr++] = '0'; \
_flushNumBuf();
#define _writeFloatingPoint(x, T) \
ull _I = (ull)(x); \
ull _F = ((x)-_I) * _precisionBase + (T)(0.5); \
if (_F >= _precisionBase) { \
_I++; \
_F = 0; \
} \
_writeNum(_I, ull, 1); \
_writeTempBuf('.'); \
_writeNum(_F, ull, _precision)
#define _checkFinite(x) \
if (std::isnan(x)) { \
wcs("NaN"); \
} else if (std::isinf(x)) { \
wcs("Inf"); \
}
#define _flushNumBuf() for (; _numPtr; _writeTempBuf(_numBuf[--_numPtr]))
#define _fillBuf(x) \
for (int _i = 0; _i < (x); _i++) \
_putchar(_fill)
#define _flushTempBuf() \
int _tempLen = _tempOutputPtr; \
_fillBuf(_width - _tempLen); \
_writeOutput(); \
_fillBuf(-_width - _tempLen)
#define wb(x) \
do { \
if (x) \
_writeTempBuf('1'); \
else \
_writeTempBuf('0'); \
_flushTempBuf(); \
} while (0)
#define wc(x) \
do { \
_writeTempBuf(x); \
_flushTempBuf(); \
} while (0)
#define wi(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), uint, 1); \
} else { \
_writeNum(x, uint, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wll(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), ull, 1); \
} else { \
_writeNum(x, ull, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wd(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), double); \
} \
else { \
_writeFloatingPoint(x, double); \
} \
_flushTempBuf(); \
} while (0)
#define wld(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), ld); \
} \
else { \
_writeFloatingPoint(x, ld); \
} \
_flushTempBuf(); \
} while (0)
#define wcs(x) \
do { \
int _slen = strlen(x); \
_fillBuf(_width - _slen); \
for (const char *_p = (x); *_p; _putchar(*_p++)) \
; \
_fillBuf(-_width - _slen); \
} while (0)
#define ws(x) \
do { \
_fillBuf(_width - int((x).length())); \
for (int _i = 0; _i < int((x).length()); _putchar(x[_i++])) \
; \
_fillBuf(-_width - int((x).length())); \
} while (0)
void setPrecision(int x) {
_precision = x;
_precisionBase = 1;
for (int _i = 0; _i < x; _i++, _precisionBase *= 10)
;
}
void setWidth(int x) { _width = x; }
void setFill(char x) { _fill = x; }
void setDelimiter(const char *x) { _delimiter = x; }
void setDelimiter(const string &x) { _delimiter = x.c_str(); }
void writeDelimiter() {
for (const char *_p = _delimiter; *_p; _putchar(*_p++))
;
}
void write(const bool &x) { wb(x); }
void write(const int &x) { wi(x); }
void write(const uint &x) { wi(x); }
void write(const ll &x) { wll(x); }
void write(const ull &x) { wll(x); }
void write(const double &x) { wd(x); }
void write(const ld &x) { wld(x); }
void write(const char &x) { wc(x); }
void write(const char *x) { wcs(x); }
void write(const string &x) { ws(x); }
template <class T1, class T2> void write(const pair<T1, T2> &x) {
write(x.first);
writeDelimiter();
write(x.second);
}
template <class T> void write(const complex<T> &x) {
write(x.real());
writeDelimiter();
write(x.imag());
}
template <class T> void write(const T &x);
template <class T, class... Ts> void write(const T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type write(It st, It en) {
bool _first = 1;
for (It _i = st; _i != en; _i++) {
if (_first)
_first = 0;
else
writeDelimiter();
write(*_i);
}
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type write(It st, It en,
Ts &&...xs) {
write(st, en);
writeDelimiter();
write(forward<Ts>(xs)...);
}
template <class T> void write(const T &x) {
bool _first = 1;
for (auto &&_i : x) {
if (_first)
_first = 0;
else
writeDelimiter();
write(_i);
}
}
template <class T, class... Ts> void write(const T &x, Ts &&...xs) {
write(x);
writeDelimiter();
write(forward<Ts>(xs)...);
}
void writeln() { _putchar('\n'); }
template <class... Ts> void writeln(Ts &&...xs) {
write(forward<Ts>(xs)...);
_putchar('\n');
}
void flush() { _flush(); }
class IOManager {
public:
~IOManager() {
flush();
if (_tempInputBuf)
delete[] (_tempInputBuf);
}
};
unique_ptr<IOManager> iomanager = make_unique<IOManager>();
void setOutput(FILE *file) {
flush();
_output = file;
}
void setOutput(const char *s) {
flush();
_output = fopen(s, "w");
}
void setOutput(const string &s) {
flush();
_output = fopen(s.c_str(), "w");
}
template <class... Ts> void debug(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
write(xs...);
setOutput(_temp);
}
template <class... Ts> void debugln(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
writeln(xs...);
setOutput(_temp);
}
void setError(FILE *file) {
flush();
_error = file;
}
void setError(const char *s) {
flush();
_error = fopen(s, "w");
}
void setError(const string &s) {
flush();
_error = fopen(s.c_str(), "w");
}
template <const int MAXN, class T> struct FenwickTreeMax {
T BIT[MAXN], NEG_INF;
FenwickTreeMax(T NEG_INF) : NEG_INF(NEG_INF) {
fill(BIT, BIT + MAXN, NEG_INF);
}
void update(int i, T v) {
for (; i < MAXN; i += i & -i)
BIT[i] = max(BIT[i], v);
}
T rmq(int i) {
T ret = NEG_INF;
for (; i > 0; i -= i & -i)
ret = max(ret, BIT[i]);
return ret;
}
};
const int MAXN = 2e5 + 5;
int N, H[MAXN];
ll A[MAXN];
FenwickTreeMax<MAXN, ll> BIT(0);
int main() {
// setInput("in.txt");
// setOutput("out.txt");
// setError("err.txt");
read(N);
read(H, H + N, A, A + N);
ll ans = 0;
FOR(i, N) {
ll val = BIT.rmq(H[i]) + A[i];
MAX(ans, val);
BIT.update(H[i], val);
}
writeln(ans);
return 0;
}
| replace | 513 | 514 | 513 | 514 | 0 | |
p03176 | C++ | Runtime Error |
// Problem: Q - Flowers
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_q
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
const int N = 800080;
long long lc[N], rc[N], t[N];
long long h[N], a[N];
int n;
#define ls (p << 1)
#define rs (p << 1 | 1)
void pushup(int p) { t[p] = max(max(t[p], t[ls]), t[rs]); }
void build(int p, int l, int r) {
lc[p] = l;
rc[p] = r;
if (l == r)
return;
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
// pushup(p);
}
long long query(int p, int l, int r) {
if (l <= lc[p] && rc[p] <= r)
return t[p];
if (l > rc[p] || rc[p] < l)
return 0LL;
return max(query(ls, l, r), query(rs, l, r));
}
void modify(int p, int x, long long v) {
if (x == lc[p] && x == rc[p]) {
t[p] = v;
return;
}
if (x > rc[p] || x < lc[p])
return;
modify(ls, x, v);
modify(rs, x, v);
pushup(p);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
build(1, 0, n);
long long ans = 0;
for (int i = 1; i <= n; i++) {
long long cur;
cur = query(1, 0, h[i] - 1) + a[i];
ans = max(ans, cur);
modify(1, h[i], cur);
}
cout << ans << endl;
}
|
// Problem: Q - Flowers
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_q
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
const int N = 800080;
long long lc[N], rc[N], t[N];
long long h[N], a[N];
int n;
#define ls (p << 1)
#define rs (p << 1 | 1)
void pushup(int p) { t[p] = max(max(t[p], t[ls]), t[rs]); }
void build(int p, int l, int r) {
lc[p] = l;
rc[p] = r;
if (l == r)
return;
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
// pushup(p);
}
long long query(int p, int l, int r) {
if (l <= lc[p] && rc[p] <= r)
return t[p];
if (l > rc[p] || r < lc[p])
return 0LL;
return max(query(ls, l, r), query(rs, l, r));
}
void modify(int p, int x, long long v) {
if (x == lc[p] && x == rc[p]) {
t[p] = v;
return;
}
if (x > rc[p] || x < lc[p])
return;
modify(ls, x, v);
modify(rs, x, v);
pushup(p);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> a[i];
build(1, 0, n);
long long ans = 0;
for (int i = 1; i <= n; i++) {
long long cur;
cur = query(1, 0, h[i] - 1) + a[i];
ans = max(ans, cur);
modify(1, h[i], cur);
}
cout << ans << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long segTree[1000000] = {};
int segSize;
void init(int n) {
segSize = 1;
while (segSize < n)
segSize *= 2;
return;
}
void update(int i, long long val) {
i = segSize - 1 + i;
segTree[i] = val;
while (i > 0) {
i = (i - 1) / 2;
segTree[i] = max(segTree[i * 2 + 1], segTree[i * 2 + 2]);
}
return;
}
long long getmax(int a, int b, int k = 0, int l = 0, int r = segSize) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return segTree[k];
long long vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
long long vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
return max(vl, vr);
}
int h[100010];
long long a[100010];
priority_queue<pair<int, int>> que;
int main() {
int n;
cin >> n;
init(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
que.push(make_pair(h[i], i));
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0;
while (!que.empty()) {
int i = que.top().second;
que.pop();
long long next = a[i] + getmax(i + 1, n);
update(i, next);
ans = max(ans, next);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long segTree[1000000] = {};
int segSize;
void init(int n) {
segSize = 1;
while (segSize < n)
segSize *= 2;
return;
}
void update(int i, long long val) {
i = segSize - 1 + i;
segTree[i] = val;
while (i > 0) {
i = (i - 1) / 2;
segTree[i] = max(segTree[i * 2 + 1], segTree[i * 2 + 2]);
}
return;
}
long long getmax(int a, int b, int k = 0, int l = 0, int r = segSize) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return segTree[k];
long long vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
long long vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
return max(vl, vr);
}
int h[200010];
long long a[200010];
priority_queue<pair<int, int>> que;
int main() {
int n;
cin >> n;
init(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
que.push(make_pair(h[i], i));
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0;
while (!que.empty()) {
int i = que.top().second;
que.pop();
long long next = a[i] + getmax(i + 1, n);
update(i, next);
ans = max(ans, next);
}
cout << ans << endl;
return 0;
} | replace | 36 | 38 | 36 | 38 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout << "debuglandฤฑnฤฑz\n";
#define md 1000000007
#define MP make_pair
ll int n, m;
ll int ar[200005][2], vt[400005][3], i, j, mx, x, y;
void bul(ll int node) {
if (vt[node][1] >= x and vt[node][2] <= y) {
mx = max(mx, vt[node][0]);
return;
}
if (vt[node][2] < x or vt[node][1] > y)
return;
bul(2 * node);
bul((2 * node) + 1);
}
void ekle(ll int x, ll int y) {
if (x > 1)
ekle(x / 2, y);
vt[x][0] = max(vt[x][0], y);
return;
}
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> n;
m = 1;
while (n > m)
m *= 2;
for (i = 0; i < m; i++) {
vt[i][1] = 2 * m;
vt[i][2] = m;
}
for (i = m; i < 2 * m; i++) {
for (j = i; j > 0; j /= 2) {
vt[j][1] = min(vt[j][1], i);
vt[j][2] = max(vt[j][2], i);
}
}
for (i = m; i < 2 * m; i++)
vt[i][1] = vt[i][2];
for (i = 0; i < n; i++)
cin >> ar[i][0];
for (i = 0; i < n; i++)
cin >> ar[i][1];
for (i = 0; i < n; i++) {
mx = 0;
x = m;
y = m + ar[i][0] - 1;
bul(1);
ekle(m + ar[i][0] - 1, mx + ar[i][1]);
}
cout << vt[1][0];
// for(i=0;i<2*m;i++)cout<<vt[i][0]<<" "<<vt[i][1]<<" "<<vt[i][2]<<" "<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout << "debuglandฤฑnฤฑz\n";
#define md 1000000007
#define MP make_pair
ll int n, m;
ll int ar[200005][2], vt[500010][3], i, j, mx, x, y;
void bul(ll int node) {
if (vt[node][1] >= x and vt[node][2] <= y) {
mx = max(mx, vt[node][0]);
return;
}
if (vt[node][2] < x or vt[node][1] > y)
return;
bul(2 * node);
bul((2 * node) + 1);
}
void ekle(ll int x, ll int y) {
if (x > 1)
ekle(x / 2, y);
vt[x][0] = max(vt[x][0], y);
return;
}
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> n;
m = 1;
while (n > m)
m *= 2;
for (i = 0; i < m; i++) {
vt[i][1] = 2 * m;
vt[i][2] = m;
}
for (i = m; i < 2 * m; i++) {
for (j = i; j > 0; j /= 2) {
vt[j][1] = min(vt[j][1], i);
vt[j][2] = max(vt[j][2], i);
}
}
for (i = m; i < 2 * m; i++)
vt[i][1] = vt[i][2];
for (i = 0; i < n; i++)
cin >> ar[i][0];
for (i = 0; i < n; i++)
cin >> ar[i][1];
for (i = 0; i < n; i++) {
mx = 0;
x = m;
y = m + ar[i][0] - 1;
bul(1);
ekle(m + ar[i][0] - 1, mx + ar[i][1]);
}
cout << vt[1][0];
// for(i=0;i<2*m;i++)cout<<vt[i][0]<<" "<<vt[i][1]<<" "<<vt[i][2]<<" "<<endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define mid ((l + r) >> 1)
#define lson (x << 1)
#define rson ((x << 1) | 1)
using namespace std;
typedef long long LL;
LL val[400005] = {0};
void pushup(LL x) { val[x] = max(val[lson], val[rson]); }
void modify(LL x, LL l, LL r, LL L, LL R, LL v) {
if (L > R)
return;
if (L <= l && r <= R) {
val[x] = max(val[x], v);
return;
}
if (L <= mid)
modify(lson, l, mid, L, R, v);
if (R > mid)
modify(rson, mid + 1, r, L, R, v);
pushup(x);
}
LL query(LL x, LL l, LL r, LL L, LL R) {
if (L > R)
return 0;
if (L <= l && r <= R)
return val[x];
LL ret = 0;
if (L <= mid)
ret = max(ret, query(lson, l, mid, L, R));
if (R > mid)
ret = max(ret, query(rson, mid + 1, r, L, R));
pushup(x);
return ret;
}
LL n;
LL h[200005];
LL a[200005];
LL dp[200005] = {0};
int main() {
scanf("%lld", &n);
for (LL i = 1; i <= n; i++)
scanf("%lld", &h[i]);
for (LL i = 1; i <= n; i++)
scanf("%lld", &a[i]);
LL ans = 0;
for (LL i = 1; i <= n; i++) {
dp[i] = query(1, 1, n, 1, h[i]) + a[i];
modify(1, 1, n, h[i], h[i], dp[i]);
ans = max(ans, dp[i]);
}
printf("%lld\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define mid ((l + r) >> 1)
#define lson (x << 1)
#define rson ((x << 1) | 1)
using namespace std;
typedef long long LL;
LL val[800005] = {0};
void pushup(LL x) { val[x] = max(val[lson], val[rson]); }
void modify(LL x, LL l, LL r, LL L, LL R, LL v) {
if (L > R)
return;
if (L <= l && r <= R) {
val[x] = max(val[x], v);
return;
}
if (L <= mid)
modify(lson, l, mid, L, R, v);
if (R > mid)
modify(rson, mid + 1, r, L, R, v);
pushup(x);
}
LL query(LL x, LL l, LL r, LL L, LL R) {
if (L > R)
return 0;
if (L <= l && r <= R)
return val[x];
LL ret = 0;
if (L <= mid)
ret = max(ret, query(lson, l, mid, L, R));
if (R > mid)
ret = max(ret, query(rson, mid + 1, r, L, R));
pushup(x);
return ret;
}
LL n;
LL h[200005];
LL a[200005];
LL dp[200005] = {0};
int main() {
scanf("%lld", &n);
for (LL i = 1; i <= n; i++)
scanf("%lld", &h[i]);
for (LL i = 1; i <= n; i++)
scanf("%lld", &a[i]);
LL ans = 0;
for (LL i = 1; i <= n; i++) {
dp[i] = query(1, 1, n, 1, h[i]) + a[i];
modify(1, 1, n, h[i], h[i], dp[i]);
ans = max(ans, dp[i]);
}
printf("%lld\n", ans);
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03176 | C++ | Runtime Error | /*
author: madhav_1999 aka orthodoxparadox
22-Jan-2019
00:04:07
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define fup(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fnu for (ll i = 0; i < n; i++)
#define rev(Y) reverse(all(Y))
#define oiint ostream_iterator<int>(cout, " ")
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); // only for sorted
// vector
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
for (int i = 0; i < v.size(); ++i)
x << v[i] << " ";
return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
for (auto it : v)
x << it << " ";
return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
x << v.ff << " " << v.ss;
return x;
}
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {
inline std::size_t operator()(const std::pair<int, int> &v) const {
return v.first * 31 + v.second;
}
};
const int mod = 1e9 + 7;
int takemod(int a) { return ((a % mod) + mod) % mod; }
int fast_exp(int base, int expo) {
int res = 1;
while (expo > 0) {
if (expo & 1)
res = (res * base) % mod;
base = (base * base) % mod;
expo >>= 1;
}
return res;
}
int modinv(int a) { return takemod(fast_exp(takemod(a), mod - 2)); }
const int N = 1e5 + 10;
int h[N];
int bt[N];
int st[4 * N];
int query(int id, int l, int r, int s, int e) {
if (s > r or e < l)
return 0;
if (l >= s and r <= e) {
return st[id];
}
int mid = (l + r) >> 1;
int q1 = query(2 * id, l, mid, s, e);
int q2 = query(2 * id + 1, mid + 1, r, s, e);
return max(q1, q2);
}
void update(int id, int l, int r, int pos, int val) {
if (l == r) {
st[id] = val;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
update(2 * id, l, mid, pos, val);
} else {
update(2 * id + 1, mid + 1, r, pos, val);
}
st[id] = max(st[2 * id], st[2 * id + 1]);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
clock_t t1, t2;
t1 = clock();
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> bt[i];
}
for (int i = 1; i <= n; i++) {
int r = query(1, 1, n, 1, h[i] - 1);
update(1, 1, n, h[i], r + bt[i]);
}
cout << st[1];
t2 = clock();
cerr << "time taken: " << (t2 - t1) / (dbl)CLOCKS_PER_SEC;
return 0;
} | /*
author: madhav_1999 aka orthodoxparadox
22-Jan-2019
00:04:07
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define fup(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fnu for (ll i = 0; i < n; i++)
#define rev(Y) reverse(all(Y))
#define oiint ostream_iterator<int>(cout, " ")
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); // only for sorted
// vector
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
for (int i = 0; i < v.size(); ++i)
x << v[i] << " ";
return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
for (auto it : v)
x << it << " ";
return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
x << v.ff << " " << v.ss;
return x;
}
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {
inline std::size_t operator()(const std::pair<int, int> &v) const {
return v.first * 31 + v.second;
}
};
const int mod = 1e9 + 7;
int takemod(int a) { return ((a % mod) + mod) % mod; }
int fast_exp(int base, int expo) {
int res = 1;
while (expo > 0) {
if (expo & 1)
res = (res * base) % mod;
base = (base * base) % mod;
expo >>= 1;
}
return res;
}
int modinv(int a) { return takemod(fast_exp(takemod(a), mod - 2)); }
const int N = 2e5 + 10;
int h[N];
int bt[N];
int st[4 * N];
int query(int id, int l, int r, int s, int e) {
if (s > r or e < l)
return 0;
if (l >= s and r <= e) {
return st[id];
}
int mid = (l + r) >> 1;
int q1 = query(2 * id, l, mid, s, e);
int q2 = query(2 * id + 1, mid + 1, r, s, e);
return max(q1, q2);
}
void update(int id, int l, int r, int pos, int val) {
if (l == r) {
st[id] = val;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
update(2 * id, l, mid, pos, val);
} else {
update(2 * id + 1, mid + 1, r, pos, val);
}
st[id] = max(st[2 * id], st[2 * id + 1]);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
clock_t t1, t2;
t1 = clock();
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> bt[i];
}
for (int i = 1; i <= n; i++) {
int r = query(1, 1, n, 1, h[i] - 1);
update(1, 1, n, h[i], r + bt[i]);
}
cout << st[1];
t2 = clock();
cerr << "time taken: " << (t2 - t1) / (dbl)CLOCKS_PER_SEC;
return 0;
} | replace | 94 | 95 | 94 | 95 | 0 | time taken: 5.8e-05 |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define inf 1e18 + 5
using namespace std;
const int N = 1e5 + 5;
int h[N], a[N];
int seg[4 * N];
void update(int t, int l, int r, int idx, int val) {
if (l == r) {
seg[t] = max(seg[t], val);
return;
}
int mid = (l + r) / 2;
if (idx <= mid)
update(2 * t + 1, l, mid, idx, val);
else
update(2 * t + 2, mid + 1, r, idx, val);
seg[t] = max(seg[2 * t + 1], seg[2 * t + 2]);
return;
}
int query(int t, int l, int r, int c, int d) {
if (r < c || l > d)
return 0;
if (l >= c && r <= d)
return seg[t];
int mid = (l + r) / 2;
int q1 = query(2 * t + 1, l, mid, c, d);
int q2 = query(2 * t + 2, mid + 1, r, c, d);
return max(q1, q2);
}
void solve() {
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
h[i]--;
}
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
int q = 0;
if (h[i])
q = query(0, 0, n - 1, 0, h[i] - 1);
ans = max(ans, a[i] + q);
update(0, 0, n - 1, h[i], a[i] + q);
}
cout << ans;
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define inf 1e18 + 5
using namespace std;
const int N = 2e5 + 5;
int h[N], a[N];
int seg[4 * N];
void update(int t, int l, int r, int idx, int val) {
if (l == r) {
seg[t] = max(seg[t], val);
return;
}
int mid = (l + r) / 2;
if (idx <= mid)
update(2 * t + 1, l, mid, idx, val);
else
update(2 * t + 2, mid + 1, r, idx, val);
seg[t] = max(seg[2 * t + 1], seg[2 * t + 2]);
return;
}
int query(int t, int l, int r, int c, int d) {
if (r < c || l > d)
return 0;
if (l >= c && r <= d)
return seg[t];
int mid = (l + r) / 2;
int q1 = query(2 * t + 1, l, mid, c, d);
int q2 = query(2 * t + 2, mid + 1, r, c, d);
return max(q1, q2);
}
void solve() {
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
h[i]--;
}
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
int q = 0;
if (h[i])
q = query(0, 0, n - 1, 0, h[i] - 1);
ans = max(ans, a[i] + q);
update(0, 0, n - 1, h[i], a[i] + q);
}
cout << ans;
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll h[100003], v[100003], f[100003], tree[400003];
pair<ll, pair<ll, int>> a[100003];
void Update(int node, int start, int endd, int id, ll val) {
if (id < start || id > endd) {
return;
}
if (start == endd) {
tree[node] = val;
return;
}
int mid = (start + endd) / 2;
Update(2 * node, start, mid, id, val);
Update(2 * node + 1, mid + 1, endd, id, val);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
ll Maxx(int node, int start, int endd, int l, int r) {
if (r < start || l > endd) {
return 0;
}
if (l <= start && endd <= r) {
return tree[node];
}
int mid = (start + endd) / 2;
return max(Maxx(2 * node, start, mid, l, r),
Maxx(2 * node + 1, mid + 1, endd, l, r));
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
for (int i = 1; i <= n; ++i) {
cin >> v[i];
a[i] = {h[i], {v[i], -i}};
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i) {
if (-a[i].second.second == 1) {
f[i] = a[i].second.first;
} else {
f[i] = Maxx(1, 1, n, 1, -a[i].second.second - 1) + a[i].second.first;
}
Update(1, 1, n, -a[i].second.second, f[i]);
}
ll res = 0;
for (int i = 1; i <= n; ++i) {
res = max(res, f[i]);
}
cout << res;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll h[200003], v[200003], f[200003], tree[900003];
pair<ll, pair<ll, int>> a[200003];
void Update(int node, int start, int endd, int id, ll val) {
if (id < start || id > endd) {
return;
}
if (start == endd) {
tree[node] = val;
return;
}
int mid = (start + endd) / 2;
Update(2 * node, start, mid, id, val);
Update(2 * node + 1, mid + 1, endd, id, val);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
ll Maxx(int node, int start, int endd, int l, int r) {
if (r < start || l > endd) {
return 0;
}
if (l <= start && endd <= r) {
return tree[node];
}
int mid = (start + endd) / 2;
return max(Maxx(2 * node, start, mid, l, r),
Maxx(2 * node + 1, mid + 1, endd, l, r));
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
for (int i = 1; i <= n; ++i) {
cin >> v[i];
a[i] = {h[i], {v[i], -i}};
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i) {
if (-a[i].second.second == 1) {
f[i] = a[i].second.first;
} else {
f[i] = Maxx(1, 1, n, 1, -a[i].second.second - 1) + a[i].second.first;
}
Update(1, 1, n, -a[i].second.second, f[i]);
}
ll res = 0;
for (int i = 1; i <= n; ++i) {
res = max(res, f[i]);
}
cout << res;
}
| replace | 5 | 7 | 5 | 7 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first
#define ss second
#define mk0(a) memset(a, 0, sizeof(a))
#define mk_1(a) memset(a, -1, sizeof(a))
const ll MAX = 1e5 + 2;
const ll MAX1 = 1e2 + 5;
const ll INF = 1e15 + 2;
const ll MOD = 1e9 + 7;
#define pb push_back
#define faster \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define pi pair<ll, ll>
#define map1 unordered_map
inline ll nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline ll read() {
ll ret = 0;
bool f = 0;
char ch = nc();
while (ch > '9' || ch < '0')
f ^= ch == '-', ch = nc();
while (ch <= '9' && ch >= '0')
ret = ret * 10 + ch - '0', ch = nc();
return f ? -ret : ret;
}
ll power(ll base, ll ind, ll mod) {
ll res = 1;
while (ind) {
if (ind & 1)
res = (res * base) % mod;
base = (base * base) % mod;
ind >>= 1;
}
return res;
}
ll inv(ll den, ll mod) { return power(den, mod - 2, mod); }
ll a[MAX], h[MAX], bit[MAX];
ll n, max_val;
ll dp[MAX];
ll query(ll ind) {
if (ind <= 0)
return 0;
ll val = -INF;
for (int i = ind; i > 0; i -= i & (-i))
val = max(bit[i], val);
return val;
}
void update(ll ind) {
for (int i = ind; i <= n; i += i & (-i))
bit[i] = max(bit[i], dp[ind]);
}
int main() {
faster;
cin >> n;
ll bound = 0;
rep1(i, n) cin >> h[i], bound = max(bound, h[i]);
rep1(i, n) cin >> a[i];
for (int i = 1; i <= n; ++i) {
ll max_val = query(h[i] - 1);
dp[h[i]] = max(dp[h[i]], max_val + a[i]);
update(h[i]);
}
ll mxx = -INF;
rep1(i, bound) mxx = max(mxx, dp[i]);
cout << mxx << endl;
} | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first
#define ss second
#define mk0(a) memset(a, 0, sizeof(a))
#define mk_1(a) memset(a, -1, sizeof(a))
const ll MAX = 2e5 + 2;
const ll MAX1 = 1e2 + 5;
const ll INF = 1e15 + 2;
const ll MOD = 1e9 + 7;
#define pb push_back
#define faster \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define pi pair<ll, ll>
#define map1 unordered_map
inline ll nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline ll read() {
ll ret = 0;
bool f = 0;
char ch = nc();
while (ch > '9' || ch < '0')
f ^= ch == '-', ch = nc();
while (ch <= '9' && ch >= '0')
ret = ret * 10 + ch - '0', ch = nc();
return f ? -ret : ret;
}
ll power(ll base, ll ind, ll mod) {
ll res = 1;
while (ind) {
if (ind & 1)
res = (res * base) % mod;
base = (base * base) % mod;
ind >>= 1;
}
return res;
}
ll inv(ll den, ll mod) { return power(den, mod - 2, mod); }
ll a[MAX], h[MAX], bit[MAX];
ll n, max_val;
ll dp[MAX];
ll query(ll ind) {
if (ind <= 0)
return 0;
ll val = -INF;
for (int i = ind; i > 0; i -= i & (-i))
val = max(bit[i], val);
return val;
}
void update(ll ind) {
for (int i = ind; i <= n; i += i & (-i))
bit[i] = max(bit[i], dp[ind]);
}
int main() {
faster;
cin >> n;
ll bound = 0;
rep1(i, n) cin >> h[i], bound = max(bound, h[i]);
rep1(i, n) cin >> a[i];
for (int i = 1; i <= n; ++i) {
ll max_val = query(h[i] - 1);
dp[h[i]] = max(dp[h[i]], max_val + a[i]);
update(h[i]);
}
ll mxx = -INF;
rep1(i, bound) mxx = max(mxx, dp[i]);
cout << mxx << endl;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#define MAX_N (200000)
// #define NUM_ELEM (1 << 18)
#define NUM_ELEM (1 << 4)
#define SIZE_BUF (2 * NUM_ELEM - 1)
#define INF (1000000000000000000L)
using namespace std;
long buf[SIZE_BUF];
void st_init() {
for (int i = 0; i < SIZE_BUF; i++) {
buf[i] = 0;
}
}
void st_update(long k, long v) {
long cur = NUM_ELEM - 1 + k;
buf[cur] = v;
while (cur > 0) {
const long par = (cur - 1) / 2;
const long chl = 2 * par + 1, chr = 2 * par + 2;
buf[par] = max(buf[chl], buf[chr]);
cur = par;
}
}
void st_print() {
for (int k = 1; k <= NUM_ELEM; k *= 2) {
for (int i = 0; i < k; i++) {
printf("%ld ", buf[k - 1 + i]);
}
printf("\n");
}
}
long st_query_r(long queryb, long querye, long cur, long curb, long cure) {
if (queryb >= cure || querye <= curb) { // no intersection
return 0;
} else if (queryb <= curb && querye >= cure) { // current section included
return buf[cur];
} else { // currect section includes query
const long chl = 2 * cur + 1, chr = 2 * cur + 2;
const long m = (curb + cure) / 2;
return max(st_query_r(queryb, querye, chl, curb, m),
st_query_r(queryb, querye, chr, m, cure));
}
}
long st_query(long queryb, long querye) {
return st_query_r(queryb, querye, 0, 0, NUM_ELEM);
}
int main() {
// read inputs
long N, hs[MAX_N], as[MAX_N];
scanf("%ld", &N);
for (long i = 0; i < N; i++) {
scanf("%ld", &hs[i]);
hs[i]--; // NOTE : modified input
}
for (long i = 0; i < N; i++) {
scanf("%ld", &as[i]);
}
// solve dp
// initialize
st_init();
// update
for (long i = N - 1; i >= 0; i--) {
const long h = hs[i], a = as[i];
const long dp = a + st_query(h + 1, N);
// st_print();
// printf("i = %ld, dps[i] = %ld\n", i, dp);
st_update(h, dp);
}
printf("%ld\n", st_query(0, N));
} | #include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#define MAX_N (200000)
#define NUM_ELEM (1 << 18)
// #define NUM_ELEM (1 << 4)
#define SIZE_BUF (2 * NUM_ELEM - 1)
#define INF (1000000000000000000L)
using namespace std;
long buf[SIZE_BUF];
void st_init() {
for (int i = 0; i < SIZE_BUF; i++) {
buf[i] = 0;
}
}
void st_update(long k, long v) {
long cur = NUM_ELEM - 1 + k;
buf[cur] = v;
while (cur > 0) {
const long par = (cur - 1) / 2;
const long chl = 2 * par + 1, chr = 2 * par + 2;
buf[par] = max(buf[chl], buf[chr]);
cur = par;
}
}
void st_print() {
for (int k = 1; k <= NUM_ELEM; k *= 2) {
for (int i = 0; i < k; i++) {
printf("%ld ", buf[k - 1 + i]);
}
printf("\n");
}
}
long st_query_r(long queryb, long querye, long cur, long curb, long cure) {
if (queryb >= cure || querye <= curb) { // no intersection
return 0;
} else if (queryb <= curb && querye >= cure) { // current section included
return buf[cur];
} else { // currect section includes query
const long chl = 2 * cur + 1, chr = 2 * cur + 2;
const long m = (curb + cure) / 2;
return max(st_query_r(queryb, querye, chl, curb, m),
st_query_r(queryb, querye, chr, m, cure));
}
}
long st_query(long queryb, long querye) {
return st_query_r(queryb, querye, 0, 0, NUM_ELEM);
}
int main() {
// read inputs
long N, hs[MAX_N], as[MAX_N];
scanf("%ld", &N);
for (long i = 0; i < N; i++) {
scanf("%ld", &hs[i]);
hs[i]--; // NOTE : modified input
}
for (long i = 0; i < N; i++) {
scanf("%ld", &as[i]);
}
// solve dp
// initialize
st_init();
// update
for (long i = N - 1; i >= 0; i--) {
const long h = hs[i], a = as[i];
const long dp = a + st_query(h + 1, N);
// st_print();
// printf("i = %ld, dps[i] = %ld\n", i, dp);
st_update(h, dp);
}
printf("%ld\n", st_query(0, N));
} | replace | 5 | 7 | 5 | 7 | 0 | |
p03176 | C++ | Runtime Error | /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n;
scanf("%d", &n);
int base = 1;
while (base <= n) {
base *= 2;
}
vector<ll> dp(n + 1), bit(2 * base);
vector<int> h(n), a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &h[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
int tmp = a[i] + h[i];
ll best = 0;
while (tmp > 1) {
if (tmp % 2 == 1) {
if (bit[tmp - 1] > best) {
best = bit[tmp - 1];
}
}
tmp /= 2;
}
dp[h[i]] = best + a[i];
for (int j = base + h[i]; j >= 1; j /= 2) {
if (dp[h[i]] > bit[j]) {
bit[j] = dp[h[i]];
}
}
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] > ans) {
ans = dp[i];
}
}
printf("%lld\n", ans);
} | /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n;
scanf("%d", &n);
int base = 1;
while (base <= n) {
base *= 2;
}
vector<ll> dp(n + 1), bit(2 * base);
vector<int> h(n), a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &h[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
int tmp = base + h[i];
ll best = 0;
while (tmp > 1) {
if (tmp % 2 == 1) {
if (bit[tmp - 1] > best) {
best = bit[tmp - 1];
}
}
tmp /= 2;
}
dp[h[i]] = best + a[i];
for (int j = base + h[i]; j >= 1; j /= 2) {
if (dp[h[i]] > bit[j]) {
bit[j] = dp[h[i]];
}
}
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] > ans) {
ans = dp[i];
}
}
printf("%lld\n", ans);
} | replace | 35 | 36 | 35 | 36 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n, h[100007], x, a[100007];
long long it[400007];
void update(int k, int l, int r, int pos, long long val) {
if (l > pos || r < pos)
return;
if (l == r) {
it[k] = val;
return;
}
int mid = (l + r) >> 1;
update(k << 1, l, mid, pos, val);
update(k << 1 | 1, mid + 1, r, pos, val);
it[k] = max(it[k << 1], it[k << 1 | 1]);
}
long long get(int k, int l, int r, int L, int R) {
if (l > R || r < L)
return 0;
if (l >= L && r <= R)
return it[k];
int mid = (l + r) >> 1;
return max(get(k << 1, l, mid, L, R), get(k << 1 | 1, mid + 1, r, L, R));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
h[x] = i;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
long long val = 0;
for (int i = 1; i <= n; i++) {
int id = h[i];
val = get(1, 1, n, 1, id);
val += a[id];
// cout << val << endl;
update(1, 1, n, id, val);
}
cout << it[1];
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n, h[200007], x, a[200007];
long long it[800007];
void update(int k, int l, int r, int pos, long long val) {
if (l > pos || r < pos)
return;
if (l == r) {
it[k] = val;
return;
}
int mid = (l + r) >> 1;
update(k << 1, l, mid, pos, val);
update(k << 1 | 1, mid + 1, r, pos, val);
it[k] = max(it[k << 1], it[k << 1 | 1]);
}
long long get(int k, int l, int r, int L, int R) {
if (l > R || r < L)
return 0;
if (l >= L && r <= R)
return it[k];
int mid = (l + r) >> 1;
return max(get(k << 1, l, mid, L, R), get(k << 1 | 1, mid + 1, r, L, R));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
h[x] = i;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
long long val = 0;
for (int i = 1; i <= n; i++) {
int id = h[i];
val = get(1, 1, n, 1, id);
val += a[id];
// cout << val << endl;
update(1, 1, n, id, val);
}
cout << it[1];
}
| replace | 7 | 9 | 7 | 9 | 0 | |
p03176 | C++ | Time Limit Exceeded | #pragma GCC optimize(2)
#pragma G++ optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) (x & -x)
using namespace std;
const int N = 1e5 + 7, p = 1e9 + 7;
ll tre[N];
int n, a[N], h[N];
void change(int p, ll v) {
for (int i = p; i <= n; i += lowbit(i)) {
tre[i] = max(tre[i], v);
}
return;
}
ll query(int p) {
ll res = 0;
for (int i = p; i >= 1; i -= lowbit(i)) {
res = max(res, tre[i]);
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
change(h[i], query(h[i]) + a[i]);
}
printf("%lld\n", query(n));
return 0;
} | #pragma GCC optimize(2)
#pragma G++ optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) (x & -x)
using namespace std;
const int N = 2e5 + 7, p = 1e9 + 7;
ll tre[N];
int n, a[N], h[N];
void change(int p, ll v) {
for (int i = p; i <= n; i += lowbit(i)) {
tre[i] = max(tre[i], v);
}
return;
}
ll query(int p) {
ll res = 0;
for (int i = p; i >= 1; i -= lowbit(i)) {
res = max(res, tre[i]);
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
change(h[i], query(h[i]) + a[i]);
}
printf("%lld\n", query(n));
return 0;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll) a.size()
#define rep(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define sep(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pii pair<ll, ll>
#define mod 10000007
#define MAXN 200002
ll dp[200002], h[200002], a[200002];
ll query(ll node, ll st, ll en, ll l, ll r) {
if (st >= l and en <= r)
return dp[node];
if (en < l or st > r)
return 0;
ll mid = (st + en) / 2;
return max(query(2 * node, st, mid, l, r),
query(2 * node + 1, mid + 1, en, l, r));
}
void upd(ll node, ll st, ll en, ll ind, ll val) {
if (st == en) {
dp[node] = val;
return;
}
ll mid = (st + en) / 2;
if (ind <= mid)
upd(2 * node, st, mid, ind, val);
else
upd(2 * node + 1, mid + 1, en, ind, val);
dp[node] = max(dp[2 * node], dp[2 * node + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
for (ll i = 1; i <= n; i++)
cin >> h[i];
for (ll i = 1; i <= n; i++)
cin >> a[i];
ll ans = 0;
for (ll i = 1; i <= n; i++) {
ll dd = query(1, 1, n, 1, h[i]) + a[i];
upd(1, 1, n, h[i], dd);
ans = max(ans, dd);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll) a.size()
#define rep(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define sep(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pii pair<ll, ll>
#define mod 10000007
#define MAXN 200002
ll dp[2000002], h[200002], a[200002];
ll query(ll node, ll st, ll en, ll l, ll r) {
if (st >= l and en <= r)
return dp[node];
if (en < l or st > r)
return 0;
ll mid = (st + en) / 2;
return max(query(2 * node, st, mid, l, r),
query(2 * node + 1, mid + 1, en, l, r));
}
void upd(ll node, ll st, ll en, ll ind, ll val) {
if (st == en) {
dp[node] = val;
return;
}
ll mid = (st + en) / 2;
if (ind <= mid)
upd(2 * node, st, mid, ind, val);
else
upd(2 * node + 1, mid + 1, en, ind, val);
dp[node] = max(dp[2 * node], dp[2 * node + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
for (ll i = 1; i <= n; i++)
cin >> h[i];
for (ll i = 1; i <= n; i++)
cin >> a[i];
ll ans = 0;
for (ll i = 1; i <= n; i++) {
ll dd = query(1, 1, n, 1, h[i]) + a[i];
upd(1, 1, n, h[i], dd);
ans = max(ans, dd);
}
cout << ans;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
ll a[MAXN], h[MAXN], n, ans = 0;
ll lo[4 * MAXN + 1], hi[4 * MAXN + 1], tree[4 * MAXN + 1], delta[4 * MAXN + 1];
void init(int i, int l, int r) {
lo[i] = l;
hi[i] = r;
if (l == r)
return;
int m = (l + r) / 2;
init(2 * i, l, m);
init(2 * i + 1, m + 1, r);
}
void prop(int i) {
delta[2 * i] += delta[i];
delta[2 * i + 1] += delta[i];
delta[i] = 0;
}
void update(int i) {
tree[i] = max(tree[2 * i] + delta[2 * i], tree[2 * i + 1] + delta[2 * i + 1]);
}
void inc(int i, int l, int r, ll val) {
if (r < lo[i] || hi[i] < l)
return;
if (hi[i] <= r && lo[i] >= l) {
delta[i] += val;
return;
}
// partial cover case
prop(i);
inc(2 * i, l, r, val);
inc(2 * i + 1, l, r, val);
update(i);
}
ll query(int i, int l, int r) {
if (r < lo[i] || hi[i] < l)
return 0; // not in range
if (hi[i] <= r && lo[i] >= l)
return tree[i] + delta[i]; // completely in range
prop(i);
ll maxLeft = query(2 * i, l, r);
ll maxRight = query(2 * i + 1, l, r);
update(i);
return max(maxLeft, maxRight);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
init(1, 0, n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
inc(1, h[i], h[i], a[i] + query(1, 0, h[i]));
ans = max(ans, query(1, 0, h[i]));
}
cout << ans;
} | #include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
ll a[MAXN], h[MAXN], n, ans = 0;
ll lo[4 * MAXN + 1], hi[4 * MAXN + 1], tree[4 * MAXN + 1], delta[4 * MAXN + 1];
void init(int i, int l, int r) {
lo[i] = l;
hi[i] = r;
if (l == r)
return;
int m = (l + r) / 2;
init(2 * i, l, m);
init(2 * i + 1, m + 1, r);
}
void prop(int i) {
delta[2 * i] += delta[i];
delta[2 * i + 1] += delta[i];
delta[i] = 0;
}
void update(int i) {
tree[i] = max(tree[2 * i] + delta[2 * i], tree[2 * i + 1] + delta[2 * i + 1]);
}
void inc(int i, int l, int r, ll val) {
if (r < lo[i] || hi[i] < l)
return;
if (hi[i] <= r && lo[i] >= l) {
delta[i] += val;
return;
}
// partial cover case
prop(i);
inc(2 * i, l, r, val);
inc(2 * i + 1, l, r, val);
update(i);
}
ll query(int i, int l, int r) {
if (r < lo[i] || hi[i] < l)
return 0; // not in range
if (hi[i] <= r && lo[i] >= l)
return tree[i] + delta[i]; // completely in range
prop(i);
ll maxLeft = query(2 * i, l, r);
ll maxRight = query(2 * i + 1, l, r);
update(i);
return max(maxLeft, maxRight);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
init(1, 0, n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
inc(1, h[i], h[i], a[i] + query(1, 0, h[i]));
ans = max(ans, query(1, 0, h[i]));
}
cout << ans;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define DBG(x) cout << #x << ":" << x << endl
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const ll p = 1e9 + 7;
const ll INF = 1LL << 60;
#define MAX_N 1 << 17
#define int long long
int n, dat[2 * (MAX_N)-1];
// INT๏ผฟMAXใงๅๆๅ
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
// k็ช็ฎใฎ่ฆ็ด ใaใซๅคๆด
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)ใฎๆๅฐๅคใๆฑใใ
int query(int a, int b, int k = 0, int l = 0, int r = n) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
ll cc, h[222222], c[222222];
cin >> cc;
init(cc + 1);
for (int i = 0; i < cc; i++)
cin >> h[i];
for (int i = 0; i < cc; i++) {
cin >> c[i];
ll ma = query(0, h[i]);
if (ma == INT_MAX)
ma = 0;
update(h[i], (ma - c[i]));
}
cout << -query(0, cc + 1) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define DBG(x) cout << #x << ":" << x << endl
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const ll p = 1e9 + 7;
const ll INF = 1LL << 60;
#define MAX_N 1 << 18
#define int long long
int n, dat[2 * (MAX_N)-1];
// INT๏ผฟMAXใงๅๆๅ
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
// k็ช็ฎใฎ่ฆ็ด ใaใซๅคๆด
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)ใฎๆๅฐๅคใๆฑใใ
int query(int a, int b, int k = 0, int l = 0, int r = n) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
ll cc, h[222222], c[222222];
cin >> cc;
init(cc + 1);
for (int i = 0; i < cc; i++)
cin >> h[i];
for (int i = 0; i < cc; i++) {
cin >> c[i];
ll ma = query(0, h[i]);
if (ma == INT_MAX)
ma = 0;
update(h[i], (ma - c[i]));
}
cout << -query(0, cc + 1) << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
class kawaii {
#define boi(X) (X & -X)
public:
kawaii(int N = 0) { poldo.resize(N + 1, 0); };
long long int qry(int pos) {
long long int x = -1;
for (; pos > 0; pos -= boi(pos)) {
x = max(x, poldo[pos]);
}
return x;
}
void upd(int pos, long long int val) {
for (; pos < poldo.size(); pos += boi(pos)) {
poldo[pos] = max(poldo[pos], val);
}
}
private:
vector<long long int> poldo;
};
int main() {
#ifdef EVAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int N;
cin >> N;
kawaii kono(20003);
long long int h[N], vet[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < N; i++) {
cin >> vet[i];
}
long long int sol = -1;
for (int i = 0; i < N; i++) {
kono.upd(h[i], kono.qry(h[i]) + vet[i]);
sol = max(kono.qry(h[i]), sol);
}
cout << sol;
} | #include <bits/stdc++.h>
using namespace std;
class kawaii {
#define boi(X) (X & -X)
public:
kawaii(int N = 0) { poldo.resize(N + 1, 0); };
long long int qry(int pos) {
long long int x = -1;
for (; pos > 0; pos -= boi(pos)) {
x = max(x, poldo[pos]);
}
return x;
}
void upd(int pos, long long int val) {
for (; pos < poldo.size(); pos += boi(pos)) {
poldo[pos] = max(poldo[pos], val);
}
}
private:
vector<long long int> poldo;
};
int main() {
#ifdef EVAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int N;
cin >> N;
kawaii kono(200002);
long long int h[N], vet[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < N; i++) {
cin >> vet[i];
}
long long int sol = -1;
for (int i = 0; i < N; i++) {
kono.upd(h[i], kono.qry(h[i]) + vet[i]);
sol = max(kono.qry(h[i]), sol);
}
cout << sol;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
ll n, height[N], value[N], bit[N];
void upd(ll x, ll val) {
for (; x <= n; x += x & -x)
bit[x] = max(bit[x], val);
}
ll query(ll x) {
ll ret = 0;
for (; x >= 1; x -= x & -x)
ret = max(ret, bit[x]);
return ret;
}
int main() {
inlld(n);
for (ll a = 1; a <= n; a++)
inlld(height[a]);
for (ll a = 1; a <= n; a++)
inlld(value[a]);
ll ans = 0;
for (ll a = 1; a <= n; a++) {
ll maxi_here = query(height[a]);
ans = max(ans, maxi_here + value[a]);
upd(height[a], maxi_here + value[a]);
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
ll n, height[N], value[N], bit[N];
void upd(ll x, ll val) {
for (; x <= n; x += x & -x)
bit[x] = max(bit[x], val);
}
ll query(ll x) {
ll ret = 0;
for (; x >= 1; x -= x & -x)
ret = max(ret, bit[x]);
return ret;
}
int main() {
inlld(n);
for (ll a = 1; a <= n; a++)
inlld(height[a]);
for (ll a = 1; a <= n; a++)
inlld(value[a]);
ll ans = 0;
for (ll a = 1; a <= n; a++) {
ll maxi_here = query(height[a]);
ans = max(ans, maxi_here + value[a]);
upd(height[a], maxi_here + value[a]);
}
printf("%lld\n", ans);
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
long long a[100002], b[100002], aib[100002];
void upd(int poz, long long val) {
for (; poz <= n; poz += poz & (-poz))
aib[poz] = max(aib[poz], val);
}
long long compute(int poz) {
long long ans = 0;
for (; poz; poz -= poz & (-poz))
ans = max(ans, aib[poz]);
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
cin >> b[i];
long long ans = 0;
for (int i = 1; i <= n; ++i) {
long long sum = compute(a[i] - 1) + b[i];
ans = max(ans, sum);
upd(a[i], sum);
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
long long a[200002], b[200002], aib[200002];
void upd(int poz, long long val) {
for (; poz <= n; poz += poz & (-poz))
aib[poz] = max(aib[poz], val);
}
long long compute(int poz) {
long long ans = 0;
for (; poz; poz -= poz & (-poz))
ans = max(ans, aib[poz]);
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
cin >> b[i];
long long ans = 0;
for (int i = 1; i <= n; ++i) {
long long sum = compute(a[i] - 1) + b[i];
ans = max(ans, sum);
upd(a[i], sum);
}
cout << ans;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x, n) \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 10;
const ll MOD = 1e9 + 7;
template <typename T> struct SegmentTree {
using F = function<T(T, T)>;
int n;
F f;
T ti;
vector<T> dat;
SegmentTree(){};
SegmentTree(F f, T ti) : f(f), ti(ti) {}
void init(int n_) {
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
}
void build(const vector<T> &v) {
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
void set_val(int k, T x) {
dat[k += n] = x;
while (k >>= 1)
dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
}
//[a,b)
T query(int a, int b) {
T vl = ti, vr = ti;
for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, dat[l++]);
if (r & 1)
vr = f(dat[--r], vr);
}
return f(vl, vr);
}
};
ll dp[20010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vll h(N);
for (ll i = 0; i < N; i++) {
cin >> h[i];
h[i]--;
}
vll A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
SegmentTree<ll> seg([](ll a, ll b) { return max(a, b); }, 0ll);
seg.init(N);
for (ll i = 0; i < N; i++) {
dp[i] = seg.query(0, h[i] + 1) + A[i];
seg.set_val(h[i], dp[i]);
}
cout << seg.query(0, N) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x, n) \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 10;
const ll MOD = 1e9 + 7;
template <typename T> struct SegmentTree {
using F = function<T(T, T)>;
int n;
F f;
T ti;
vector<T> dat;
SegmentTree(){};
SegmentTree(F f, T ti) : f(f), ti(ti) {}
void init(int n_) {
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
}
void build(const vector<T> &v) {
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
void set_val(int k, T x) {
dat[k += n] = x;
while (k >>= 1)
dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
}
//[a,b)
T query(int a, int b) {
T vl = ti, vr = ti;
for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, dat[l++]);
if (r & 1)
vr = f(dat[--r], vr);
}
return f(vl, vr);
}
};
ll dp[200010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vll h(N);
for (ll i = 0; i < N; i++) {
cin >> h[i];
h[i]--;
}
vll A(N);
for (ll i = 0; i < N; i++)
cin >> A[i];
SegmentTree<ll> seg([](ll a, ll b) { return max(a, b); }, 0ll);
seg.init(N);
for (ll i = 0; i < N; i++) {
dp[i] = seg.query(0, h[i] + 1) + A[i];
seg.set_val(h[i], dp[i]);
}
cout << seg.query(0, N) << endl;
return 0;
}
| replace | 56 | 57 | 56 | 57 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N_MAX 100002
#define ll long long
using namespace std;
int n;
int h[N_MAX];
ll b[N_MAX];
ll aib[N_MAX];
void update(int pos, ll val) {
for (int i = pos; i <= n; i += i & (-i))
aib[i] = max(aib[i], val);
}
ll query(int pos) {
ll ans = 0;
for (int i = pos - 1; i >= 1; i -= i & (-i))
ans = max(ans, aib[i]);
return ans;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
for (int i = 1; i <= n; i++) {
ll dp = query(h[i]) + b[i];
update(h[i], dp);
}
cout << query(n + 1) << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define N_MAX 200002
#define ll long long
using namespace std;
int n;
int h[N_MAX];
ll b[N_MAX];
ll aib[N_MAX];
void update(int pos, ll val) {
for (int i = pos; i <= n; i += i & (-i))
aib[i] = max(aib[i], val);
}
ll query(int pos) {
ll ans = 0;
for (int i = pos - 1; i >= 1; i -= i & (-i))
ans = max(ans, aib[i]);
return ans;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
for (int i = 1; i <= n; i++) {
ll dp = query(h[i]) + b[i];
update(h[i], dp);
}
cout << query(n + 1) << "\n";
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define BPhuong "main"
#define maxn 100005
#define maxm
#define fi(i, a, b) for (int i = a; i <= b; i++)
#define fid(i, a, b) for (int i = a; i >= b; i--)
#define se second
#define f first
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define bit(x, i) ((x >> i) & 1)
#define oo 1e9
struct data {
int x, y, z;
};
using namespace std;
int n, h[maxn], a[maxn];
ll l[maxn], f[maxn];
void upp(int x, ll j) {
while (x <= maxn) {
l[x] = max(l[x], j);
x += (x & -x);
}
}
ll get(int x) {
ll ans = 0;
while (x >= 1) {
ans = max(ans, l[x]);
x -= (x & -x);
}
return ans;
}
void nhap() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// freopen(BPhuong".inp","r",stdin);
// freopen(BPhuong".out","w",stdout);
cin >> n;
fi(i, 1, n) cin >> h[i];
fi(i, 1, n) cin >> a[i];
}
void xuli() {
ll res = 0;
fi(i, 1, n) {
f[i] = max(f[i], get(h[i] - 1) + a[i]);
upp(h[i], f[i]);
res = max(res, f[i]);
}
cout << res;
}
int main() {
nhap();
xuli();
}
| #include <bits/stdc++.h>
#define BPhuong "main"
#define maxn 200005
#define maxm
#define fi(i, a, b) for (int i = a; i <= b; i++)
#define fid(i, a, b) for (int i = a; i >= b; i--)
#define se second
#define f first
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define bit(x, i) ((x >> i) & 1)
#define oo 1e9
struct data {
int x, y, z;
};
using namespace std;
int n, h[maxn], a[maxn];
ll l[maxn], f[maxn];
void upp(int x, ll j) {
while (x <= maxn) {
l[x] = max(l[x], j);
x += (x & -x);
}
}
ll get(int x) {
ll ans = 0;
while (x >= 1) {
ans = max(ans, l[x]);
x -= (x & -x);
}
return ans;
}
void nhap() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// freopen(BPhuong".inp","r",stdin);
// freopen(BPhuong".out","w",stdout);
cin >> n;
fi(i, 1, n) cin >> h[i];
fi(i, 1, n) cin >> a[i];
}
void xuli() {
ll res = 0;
fi(i, 1, n) {
f[i] = max(f[i], get(h[i] - 1) + a[i]);
upp(h[i], f[i]);
res = max(res, f[i]);
}
cout << res;
}
int main() {
nhap();
xuli();
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair<int, int>
#define pal pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpai vector<pii>
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int sze = 20005;
ll tree[4 * sze + 1];
ll dp[sze];
int getMid(int s, int e) { return (s + (e - s) / 2); }
void update(int ind, int ss, int se, int pos, ll val) {
if (ss == se) {
tree[ind] = val;
dp[pos] = val;
return;
}
int mid = getMid(ss, se);
if (pos <= mid)
update(2 * ind, ss, mid, pos, val);
else
update(2 * ind + 1, mid + 1, se, pos, val);
tree[ind] = max(tree[2 * ind], tree[2 * ind + 1]);
}
ll getMax(int ind, int ss, int se, int l, int r) {
if (l > se || r < ss)
return 0;
if (l <= ss && se <= r)
return tree[ind];
int mid = getMid(ss, se);
ll p1 = getMax(2 * ind, ss, mid, l, r);
ll p2 = getMax(2 * ind + 1, mid + 1, se, l, r);
return max(p1, p2);
}
void solve() {
int n;
cin >> n;
int hei[n];
ll be[n];
rep(i, n) cin >> hei[i];
rep(i, n) cin >> be[i];
mem(tree);
for (int i = 0; i < n; i++) {
ll mx = getMax(1, 1, n, 1, hei[i] - 1);
update(1, 1, n, hei[i], be[i] + mx);
}
// cout<<"hello\n";
cout << *max_element(dp, dp + sze) << endl;
}
int main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair<int, int>
#define pal pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpai vector<pii>
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int sze = 200005;
ll tree[4 * sze + 1];
ll dp[sze];
int getMid(int s, int e) { return (s + (e - s) / 2); }
void update(int ind, int ss, int se, int pos, ll val) {
if (ss == se) {
tree[ind] = val;
dp[pos] = val;
return;
}
int mid = getMid(ss, se);
if (pos <= mid)
update(2 * ind, ss, mid, pos, val);
else
update(2 * ind + 1, mid + 1, se, pos, val);
tree[ind] = max(tree[2 * ind], tree[2 * ind + 1]);
}
ll getMax(int ind, int ss, int se, int l, int r) {
if (l > se || r < ss)
return 0;
if (l <= ss && se <= r)
return tree[ind];
int mid = getMid(ss, se);
ll p1 = getMax(2 * ind, ss, mid, l, r);
ll p2 = getMax(2 * ind + 1, mid + 1, se, l, r);
return max(p1, p2);
}
void solve() {
int n;
cin >> n;
int hei[n];
ll be[n];
rep(i, n) cin >> hei[i];
rep(i, n) cin >> be[i];
mem(tree);
for (int i = 0; i < n; i++) {
ll mx = getMax(1, 1, n, 1, hei[i] - 1);
update(1, 1, n, hei[i], be[i] + mx);
}
// cout<<"hello\n";
cout << *max_element(dp, dp + sze) << endl;
}
int main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5;
const LL INF = 1e7;
int n;
int h[N + 5];
LL a[N + 5];
LL ST[4 * N + 5];
void build(int node = 1, int l = 1, int r = n) {
if (l == r) {
ST[node] = -INF;
return;
}
build(node * 2, l, (l + r) / 2);
build(node * 2 + 1, (l + r) / 2 + 1, r);
ST[node] = max(ST[node * 2], ST[node * 2 + 1]);
return;
}
void update(int node, int l, int r, int pos, LL val) {
if (l > pos || r < pos)
return;
if (l == r) {
ST[node] = val;
return;
}
update(node * 2, l, (l + r) / 2, pos, val);
update(node * 2 + 1, (l + r) / 2 + 1, r, pos, val);
ST[node] = max(ST[node * 2], ST[node * 2 + 1]);
return;
}
LL query(int node, int l, int r, int ql, int qr) {
if (l > qr || r < ql)
return -INF;
if (l >= ql && r <= qr)
return ST[node];
return max(query(node * 2, l, (l + r) / 2, ql, qr),
query(node * 2 + 1, (l + r) / 2 + 1, r, ql, qr));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
build();
LL ans = 0LL;
for (int i = 1; i <= n; i++) {
LL tmp = max(0LL, query(1, 1, n, 1, h[i]));
tmp += a[i];
// cout << tmp << endl;
ans = max(ans, tmp);
update(1, 1, n, h[i], tmp);
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5;
const LL INF = 1e7;
int n;
int h[N + 5];
LL a[N + 5];
LL ST[4 * N + 5];
void build(int node = 1, int l = 1, int r = n) {
if (l == r) {
ST[node] = -INF;
return;
}
build(node * 2, l, (l + r) / 2);
build(node * 2 + 1, (l + r) / 2 + 1, r);
ST[node] = max(ST[node * 2], ST[node * 2 + 1]);
return;
}
void update(int node, int l, int r, int pos, LL val) {
if (l > pos || r < pos)
return;
if (l == r) {
ST[node] = val;
return;
}
update(node * 2, l, (l + r) / 2, pos, val);
update(node * 2 + 1, (l + r) / 2 + 1, r, pos, val);
ST[node] = max(ST[node * 2], ST[node * 2 + 1]);
return;
}
LL query(int node, int l, int r, int ql, int qr) {
if (l > qr || r < ql)
return -INF;
if (l >= ql && r <= qr)
return ST[node];
return max(query(node * 2, l, (l + r) / 2, ql, qr),
query(node * 2 + 1, (l + r) / 2 + 1, r, ql, qr));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
build();
LL ans = 0LL;
for (int i = 1; i <= n; i++) {
LL tmp = max(0LL, query(1, 1, n, 1, h[i]));
tmp += a[i];
// cout << tmp << endl;
ans = max(ans, tmp);
update(1, 1, n, h[i], tmp);
}
printf("%lld\n", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int mx = 100005;
int n, a, h[mx];
struct SegTree {
int sz = 2;
vector<long long> dat;
SegTree(int n) {
while (n >= sz)
sz *= 2;
dat.assign(sz * 2, 0);
}
void set(int x, long long n) {
int l = sz, r = x - 1 + sz;
long long res = 0;
while (l <= r) {
if (l & 1)
res = max(res, dat[l++]);
if (r & 1 ^ 1)
res = max(res, dat[r--]);
l /= 2;
r /= 2;
}
dat[x += sz] = n + res;
for (; x; x /= 2)
dat[x / 2] = max(dat[x], dat[x ^ 1]);
}
};
int main() {
scanf("%d", &n);
SegTree sg(n);
for (int i = 0; i < n; i++)
scanf("%d", h + i);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
sg.set(h[i], a);
}
printf("%lld\n", sg.dat[1]);
} | #include <bits/stdc++.h>
using namespace std;
const int mx = 200005;
int n, a, h[mx];
struct SegTree {
int sz = 2;
vector<long long> dat;
SegTree(int n) {
while (n >= sz)
sz *= 2;
dat.assign(sz * 2, 0);
}
void set(int x, long long n) {
int l = sz, r = x - 1 + sz;
long long res = 0;
while (l <= r) {
if (l & 1)
res = max(res, dat[l++]);
if (r & 1 ^ 1)
res = max(res, dat[r--]);
l /= 2;
r /= 2;
}
dat[x += sz] = n + res;
for (; x; x /= 2)
dat[x / 2] = max(dat[x], dat[x ^ 1]);
}
};
int main() {
scanf("%d", &n);
SegTree sg(n);
for (int i = 0; i < n; i++)
scanf("%d", h + i);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
sg.set(h[i], a);
}
printf("%lld\n", sg.dat[1]);
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
bool sortinrev(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
ll query(ll tree[], ll index, ll qs, ll qe, ll s, ll e) {
if (qs <= s && e <= qe) {
return tree[index];
}
if (e < qs || s > qe) {
return 0;
}
ll mid = (s + e) / 2;
return max(query(tree, 2 * index, qs, qe, s, mid),
query(tree, 2 * index + 1, qs, qe, mid + 1, e));
}
void build(ll tree[], ll s, ll e, ll index) {
if (s == e) {
tree[index] = 0;
} else {
int mid = (s + e) / 2;
build(tree, s, mid, 2 * index);
build(tree, mid + 1, e, 2 * index + 1);
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
}
void update(ll tree[], ll s, ll e, ll value, ll hat, ll index) {
if (s == e) {
// arr[value]=1;
tree[index] += hat;
} else {
ll mid = (s + e) / 2;
if (value <= mid) {
update(tree, s, mid, value, hat, 2 * index);
} else {
update(tree, mid + 1, e, value, hat, 2 * index + 1);
}
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
}
int main() {
ll n;
cin >> n;
ll height[n];
ll value[100005];
for (ll i = 0; i < n; i++) {
cin >> height[i];
}
for (ll i = 0; i < n; i++) {
cin >> value[height[i]];
}
ll tree[4 * n + 1];
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
v[i].first = height[i];
v[i].second = i;
}
build(tree, 0, n - 1, 1);
// sort(v.begin(),v.end());
sort(v.begin(), v.end(), sortinrev);
// for(int i=0;i<n;i++)
// {
// cout<<v[i].first<<" "<<v[i].second<<endl;
// }
vector<ll> final;
for (ll i = 0; i < n; i++) {
ll k = v[i].second;
ll ans = query(tree, 1, k, n - 1, 0, n - 1);
update(tree, 0, n - 1, k, ans + value[v[i].first], 1);
final.push_back(ans + value[v[i].first]);
}
ll bug = *max_element(final.begin(), final.end());
cout << bug << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
bool sortinrev(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
ll query(ll tree[], ll index, ll qs, ll qe, ll s, ll e) {
if (qs <= s && e <= qe) {
return tree[index];
}
if (e < qs || s > qe) {
return 0;
}
ll mid = (s + e) / 2;
return max(query(tree, 2 * index, qs, qe, s, mid),
query(tree, 2 * index + 1, qs, qe, mid + 1, e));
}
void build(ll tree[], ll s, ll e, ll index) {
if (s == e) {
tree[index] = 0;
} else {
int mid = (s + e) / 2;
build(tree, s, mid, 2 * index);
build(tree, mid + 1, e, 2 * index + 1);
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
}
void update(ll tree[], ll s, ll e, ll value, ll hat, ll index) {
if (s == e) {
// arr[value]=1;
tree[index] += hat;
} else {
ll mid = (s + e) / 2;
if (value <= mid) {
update(tree, s, mid, value, hat, 2 * index);
} else {
update(tree, mid + 1, e, value, hat, 2 * index + 1);
}
tree[index] = max(tree[2 * index], tree[2 * index + 1]);
}
}
int main() {
ll n;
cin >> n;
ll height[n];
ll value[200005];
for (ll i = 0; i < n; i++) {
cin >> height[i];
}
for (ll i = 0; i < n; i++) {
cin >> value[height[i]];
}
ll tree[4 * n + 1];
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
v[i].first = height[i];
v[i].second = i;
}
build(tree, 0, n - 1, 1);
// sort(v.begin(),v.end());
sort(v.begin(), v.end(), sortinrev);
// for(int i=0;i<n;i++)
// {
// cout<<v[i].first<<" "<<v[i].second<<endl;
// }
vector<ll> final;
for (ll i = 0; i < n; i++) {
ll k = v[i].second;
ll ans = query(tree, 1, k, n - 1, 0, n - 1);
update(tree, 0, n - 1, k, ans + value[v[i].first], 1);
final.push_back(ans + value[v[i].first]);
}
ll bug = *max_element(final.begin(), final.end());
cout << bug << endl;
}
| replace | 51 | 52 | 51 | 52 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second
#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif
template <typename T> void _dbg(const char *_s, T _h) {
cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
int _b = 0;
while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
cerr << *_s++;
cerr << " = " << _h << ",";
_dbg(_s + 1, _t...);
}
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e5) + 17;
struct segtree {
int n;
vector<ll> T;
segtree() = default;
segtree(int n) : n(n) { T.resize(4 * n); }
void upd(int i, ll x, int v, int l, int r) {
if (l == r) {
T[v] = max(T[v], x);
return;
}
auto m = (l + r) / 2;
if (i <= m)
upd(i, x, 2 * v, l, m);
else
upd(i, x, 2 * v + 1, m + 1, r);
T[v] = max(T[2 * v], T[2 * v + 1]);
}
ll get(int lq, int rq, int v, int l, int r) {
if (r < lq || l > rq)
return 0;
if (lq <= l && r <= rq)
return T[v];
auto m = (l + r) / 2;
return max(get(lq, rq, 2 * v, l, m), get(lq, rq, 2 * v + 1, m + 1, r));
}
void upd(int i, ll x) { upd(i, x, 1, 0, n - 1); }
ll get(int lq, int rq) { return get(lq, rq, 1, 0, n - 1); }
};
int n;
int h[MAXN], a[MAXN];
bool read() {
if (!(cin >> n))
return false;
forn(i, n) cin >> h[i];
forn(i, n) cin >> a[i];
return true;
}
void solve() {
segtree T(n + 1);
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll res = T.get(0, h[i] - 1) + a[i];
T.upd(h[i], res);
ans = max(ans, res);
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
#ifdef SEREZHKA
freopen("file.in", "r", stdin);
#endif
while (read())
solve();
return 0;
}
| #include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second
#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif
template <typename T> void _dbg(const char *_s, T _h) {
cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
int _b = 0;
while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
cerr << *_s++;
cerr << " = " << _h << ",";
_dbg(_s + 1, _t...);
}
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e5) + 17;
struct segtree {
int n;
vector<ll> T;
segtree() = default;
segtree(int n) : n(n) { T.resize(4 * n); }
void upd(int i, ll x, int v, int l, int r) {
if (l == r) {
T[v] = max(T[v], x);
return;
}
auto m = (l + r) / 2;
if (i <= m)
upd(i, x, 2 * v, l, m);
else
upd(i, x, 2 * v + 1, m + 1, r);
T[v] = max(T[2 * v], T[2 * v + 1]);
}
ll get(int lq, int rq, int v, int l, int r) {
if (r < lq || l > rq)
return 0;
if (lq <= l && r <= rq)
return T[v];
auto m = (l + r) / 2;
return max(get(lq, rq, 2 * v, l, m), get(lq, rq, 2 * v + 1, m + 1, r));
}
void upd(int i, ll x) { upd(i, x, 1, 0, n - 1); }
ll get(int lq, int rq) { return get(lq, rq, 1, 0, n - 1); }
};
int n;
int h[MAXN], a[MAXN];
bool read() {
if (!(cin >> n))
return false;
forn(i, n) cin >> h[i];
forn(i, n) cin >> a[i];
return true;
}
void solve() {
segtree T(n + 1);
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll res = T.get(0, h[i] - 1) + a[i];
T.upd(h[i], res);
ans = max(ans, res);
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
#ifdef SEREZHKA
freopen("file.in", "r", stdin);
#endif
while (read())
solve();
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
const ll P = 1000000007;
const int N = (1 << 17);
using namespace std;
int n;
ll f[N + 1], h[N], a[N];
void add(int i, ll o) {
for (; i <= N; i += i & -i)
f[i] = max(f[i], o);
}
ll msum(int i) {
ll s = 0;
for (; i > 0; i -= i & -i)
s = max(f[i], s);
return s;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
ll s = msum(h[i] - 1);
ans = max(ans, s + a[i]);
add(h[i], s + a[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
const ll P = 1000000007;
const int N = (1 << 18);
using namespace std;
int n;
ll f[N + 1], h[N], a[N];
void add(int i, ll o) {
for (; i <= N; i += i & -i)
f[i] = max(f[i], o);
}
ll msum(int i) {
ll s = 0;
for (; i > 0; i -= i & -i)
s = max(f[i], s);
return s;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
ll s = msum(h[i] - 1);
ans = max(ans, s + a[i]);
add(h[i], s + a[i]);
}
cout << ans << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03176 | C++ | Time Limit Exceeded | /*Saurav Paul*/
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i, a, b) for (ll i = a; i <= b; ++i)
#define boost ios_base::sync_with_stdio(0);
#define eb emplace_back
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1e9 + 7
#define itoc(c) ((char)(((int)'0') + c))
#define ctoi(c) ((int)(((int)c) - '0'))
#define all(p) p.begin(), p.end()
#define iscn(num) scanf("%d", &num);
#define scn(num) scanf("%lld", &num);
#define scn2(num, num2) scanf("%lld%lld", &num, &num2);
using namespace std;
///////////////////////
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
////////////////////////
template <typename T> T set_bit(T N, T pos) { return N = N | (1 << pos); }
template <typename T> T reset_bit(T N, T pos) { return N = N & ~(1 << pos); }
template <typename T> bool check_bit(T N, T pos) {
return (bool)(N & (1 << pos));
}
template <typename T> void bin_print(T N) {
bitset<25> bit(N);
cerr << bit.to_string() << "\n";
}
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void add_self(T &a, T b) { a += b; }
////////////////////////
const ll INF = 2e18 + 99;
typedef pair<ll, ll> Pair;
typedef vector<ll> vec;
;
template <typename T> void ara_read(T &v, ll n) {
ll temp;
for (ll i = 0; i < n; i++) {
scanf("%lld", &temp);
v.emplace_back(temp);
}
}
template <typename T> void ara_print(T &v) {
for (ll x : v)
printf("%lld ", x);
puts("");
}
////////////////////////
int main() {
int n;
scanf("%d", &n);
vector<int> heights, beauties;
ara_read(heights, n);
ara_read(beauties, n);
// segment tree.....
int base = 1;
while (base <= n) {
base <<= 1;
}
//~ cout << base << endl;
// creating tree....
vector<ll> tree(2 * base);
vector<ll> dp(n + 1);
for (int flower = 0; flower < n; flower++) {
ll m = heights[flower] + base;
ll best = 0;
while (m >= 1) {
if (m & 1) {
max_self(best, tree[m - 1]);
}
m /= 2;
}
dp[heights[flower]] = best + beauties[flower];
for (m = heights[flower] + base; m >= 1; m /= 2) {
max_self(tree[m], dp[heights[flower]]);
}
for (int x = 0; x < heights[flower]; x++) {
max_self(dp[heights[flower]], dp[x] + beauties[flower]);
}
}
ll answer = 0;
for (auto x : dp)
max_self(answer, x);
printf("%lld\n", answer);
return 0;
}
| /*Saurav Paul*/
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i, a, b) for (ll i = a; i <= b; ++i)
#define boost ios_base::sync_with_stdio(0);
#define eb emplace_back
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1e9 + 7
#define itoc(c) ((char)(((int)'0') + c))
#define ctoi(c) ((int)(((int)c) - '0'))
#define all(p) p.begin(), p.end()
#define iscn(num) scanf("%d", &num);
#define scn(num) scanf("%lld", &num);
#define scn2(num, num2) scanf("%lld%lld", &num, &num2);
using namespace std;
///////////////////////
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
////////////////////////
template <typename T> T set_bit(T N, T pos) { return N = N | (1 << pos); }
template <typename T> T reset_bit(T N, T pos) { return N = N & ~(1 << pos); }
template <typename T> bool check_bit(T N, T pos) {
return (bool)(N & (1 << pos));
}
template <typename T> void bin_print(T N) {
bitset<25> bit(N);
cerr << bit.to_string() << "\n";
}
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void add_self(T &a, T b) { a += b; }
////////////////////////
const ll INF = 2e18 + 99;
typedef pair<ll, ll> Pair;
typedef vector<ll> vec;
;
template <typename T> void ara_read(T &v, ll n) {
ll temp;
for (ll i = 0; i < n; i++) {
scanf("%lld", &temp);
v.emplace_back(temp);
}
}
template <typename T> void ara_print(T &v) {
for (ll x : v)
printf("%lld ", x);
puts("");
}
////////////////////////
int main() {
int n;
scanf("%d", &n);
vector<int> heights, beauties;
ara_read(heights, n);
ara_read(beauties, n);
// segment tree.....
int base = 1;
while (base <= n) {
base <<= 1;
}
//~ cout << base << endl;
// creating tree....
vector<ll> tree(2 * base);
vector<ll> dp(n + 1);
for (int flower = 0; flower < n; flower++) {
ll m = heights[flower] + base;
ll best = 0;
while (m >= 1) {
if (m & 1) {
max_self(best, tree[m - 1]);
}
m /= 2;
}
dp[heights[flower]] = best + beauties[flower];
for (m = heights[flower] + base; m >= 1; m /= 2) {
max_self(tree[m], dp[heights[flower]]);
}
//~ for(int x = 0 ; x< heights[flower] ; x++){
//~ max_self(dp[heights[flower]] , dp[x] + beauties[flower]);
//~ }
}
ll answer = 0;
for (auto x : dp)
max_self(answer, x);
printf("%lld\n", answer);
return 0;
}
| replace | 120 | 123 | 120 | 123 | TLE | |
p03176 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int64_t query(vector<int64_t> dp, int l, int r, int v, int b, int e) {
if (b >= r || e <= l)
return 0;
if (b <= l && e >= r)
return dp[v];
int h = (l + r) / 2;
return max(query(dp, l, h, v * 2, b, e), query(dp, h, r, v * 2 + 1, b, e));
}
void update(vector<int64_t> &dp, int l, int r, int v, int i, int64_t x) {
if (i < l || i >= r)
return;
if (l == i && r == i + 1) {
dp[v] = x;
return;
}
int h = (l + r) / 2;
update(dp, l, h, v * 2, i, x);
update(dp, h, r, v * 2 + 1, i, x);
dp[v] = max(dp[v * 2], dp[v * 2 + 1]);
return;
}
int main() {
int n;
cin >> n;
vector<int> h(n);
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> h.at(i);
h.at(i)--;
}
for (int i = 0; i < n; i++)
cin >> a.at(i);
vector<int64_t> dp(n * 4, 0);
for (int i = 0; i < n; i++) {
int64_t q = query(dp, 0, n, 1, 0, h.at(i));
update(dp, 0, n, 1, h.at(i), q + a.at(i));
}
cout << dp[1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int64_t query(vector<int64_t> &dp, int l, int r, int v, int b, int e) {
if (b >= r || e <= l)
return 0;
if (b <= l && e >= r)
return dp[v];
int h = (l + r) / 2;
return max(query(dp, l, h, v * 2, b, e), query(dp, h, r, v * 2 + 1, b, e));
}
void update(vector<int64_t> &dp, int l, int r, int v, int i, int64_t x) {
if (i < l || i >= r)
return;
if (l == i && r == i + 1) {
dp[v] = x;
return;
}
int h = (l + r) / 2;
update(dp, l, h, v * 2, i, x);
update(dp, h, r, v * 2 + 1, i, x);
dp[v] = max(dp[v * 2], dp[v * 2 + 1]);
return;
}
int main() {
int n;
cin >> n;
vector<int> h(n);
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> h.at(i);
h.at(i)--;
}
for (int i = 0; i < n; i++)
cin >> a.at(i);
vector<int64_t> dp(n * 4, 0);
for (int i = 0; i < n; i++) {
int64_t q = query(dp, 0, n, 1, 0, h.at(i));
update(dp, 0, n, 1, h.at(i), q + a.at(i));
}
cout << dp[1] << endl;
} | replace | 2 | 3 | 2 | 3 | TLE | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed << setprecision(pp)
#define FOR(I, N) for (I = 0; I < N; ++I)
#define MS0(x) memset(x, 0, sizeof(x))
#define MS1(x) memset(x, -1, sizeof(x))
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define mod % 1000000007
#define pi 3.141592653
#define MX 1000000007
ll ftree[100005];
ll query(ll x) {
ll ans = 0;
for (; x > 0; x -= (x & -x)) {
ans = max(ans, ftree[x]);
}
return ans;
}
void update(ll x, ll delta, ll n) {
for (; x <= n; x += (x & -x))
ftree[x] = max(ftree[x], delta);
}
int main() {
IOS;
ll n, i, x;
cin >> n;
ll h[n + 1], a[n + 1];
MS0(ftree);
ll ans = 0;
for (i = 1; i <= n; ++i)
cin >> h[i];
for (i = 1; i <= n; ++i) {
cin >> a[i];
ans = max(ans, a[i]);
}
for (i = 1; i <= n; ++i) {
x = query(h[i] - 1);
x += a[i];
ans = max(ans, x);
update(h[i], x, n);
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed << setprecision(pp)
#define FOR(I, N) for (I = 0; I < N; ++I)
#define MS0(x) memset(x, 0, sizeof(x))
#define MS1(x) memset(x, -1, sizeof(x))
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define mod % 1000000007
#define pi 3.141592653
#define MX 1000000007
ll ftree[200005];
ll query(ll x) {
ll ans = 0;
for (; x > 0; x -= (x & -x)) {
ans = max(ans, ftree[x]);
}
return ans;
}
void update(ll x, ll delta, ll n) {
for (; x <= n; x += (x & -x))
ftree[x] = max(ftree[x], delta);
}
int main() {
IOS;
ll n, i, x;
cin >> n;
ll h[n + 1], a[n + 1];
MS0(ftree);
ll ans = 0;
for (i = 1; i <= n; ++i)
cin >> h[i];
for (i = 1; i <= n; ++i) {
cin >> a[i];
ans = max(ans, a[i]);
}
for (i = 1; i <= n; ++i) {
x = query(h[i] - 1);
x += a[i];
ans = max(ans, x);
update(h[i], x, n);
}
cout << ans;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
long long int dp[400005], a[100001];
int h[100001];
long long int maximum(int a, int b, int curr, int z) {
if (a > z)
return 0;
if (b <= z)
return dp[curr];
if (b == a) {
if (a <= z)
return dp[curr];
else
return 0;
}
if (b > a) {
int mid = (a + b) / 2;
long long int x = maximum(a, mid, 2 * curr + 1, z);
long long int y = maximum(mid + 1, b, 2 * curr + 2, z);
return max(x, y);
}
return 0;
}
void update(int curr, int a, int b, long long int z, int i) {
// cout<<a<<" "<<b<<" "<<i<<endl;
if (a > i or b < i) {
return;
}
if (b == a) {
if (a == i)
dp[curr] = max(z, dp[curr]);
return;
}
if (b > a) {
dp[curr] = max(z, dp[curr]);
update(2 * curr + 1, a, (a + b) / 2, z, i);
update(2 * curr + 2, (a + b) / 2 + 1, b, z, i);
}
}
void fn(int i) {
long long int z = maximum(1, n, 0, h[i] - 1) + a[i];
update(0, 1, n, z, h[i]);
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
fn(i);
// cout<<h[i]<<" "<<dp[0]<<endl;
}
long long int ans = maximum(1, n, 0, n);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n;
long long int dp[800005], a[200001];
int h[200001];
long long int maximum(int a, int b, int curr, int z) {
if (a > z)
return 0;
if (b <= z)
return dp[curr];
if (b == a) {
if (a <= z)
return dp[curr];
else
return 0;
}
if (b > a) {
int mid = (a + b) / 2;
long long int x = maximum(a, mid, 2 * curr + 1, z);
long long int y = maximum(mid + 1, b, 2 * curr + 2, z);
return max(x, y);
}
return 0;
}
void update(int curr, int a, int b, long long int z, int i) {
// cout<<a<<" "<<b<<" "<<i<<endl;
if (a > i or b < i) {
return;
}
if (b == a) {
if (a == i)
dp[curr] = max(z, dp[curr]);
return;
}
if (b > a) {
dp[curr] = max(z, dp[curr]);
update(2 * curr + 1, a, (a + b) / 2, z, i);
update(2 * curr + 2, (a + b) / 2 + 1, b, z, i);
}
}
void fn(int i) {
long long int z = maximum(1, n, 0, h[i] - 1) + a[i];
update(0, 1, n, z, h[i]);
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
fn(i);
// cout<<h[i]<<" "<<dp[0]<<endl;
}
long long int ans = maximum(1, n, 0, n);
cout << ans << endl;
return 0;
} | replace | 4 | 6 | 4 | 6 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1 << 18;
int arbre[MAXN];
void ajout(int noeud, int valeur) {
noeud += MAXN;
arbre[noeud] = valeur;
while (noeud > 0) {
noeud /= 2;
arbre[noeud] = max(arbre[noeud * 2], arbre[noeud * 2 + 1]);
}
}
int trouverMax(int gauche, int droite) {
gauche += MAXN, droite += MAXN;
int maxi = 0;
while (gauche <= droite) {
if (gauche % 2 == 1) {
maxi = max(maxi, arbre[gauche]);
gauche++;
}
if (droite % 2 == 0) {
maxi = max(maxi, arbre[droite]);
droite--;
}
gauche /= 2;
droite /= 2;
}
return maxi;
}
int32_t main() {
int N;
cin >> N;
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
h[i]--;
}
int v[N];
for (int i = 0; i < N; i++) {
cin >> v[i];
}
for (int i = 0; i < N; i++) {
ajout(h[i], v[i] + trouverMax(0, h[i]));
}
cout << trouverMax(0, N - 1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1 << 18;
int arbre[MAXN * 2];
void ajout(int noeud, int valeur) {
noeud += MAXN;
arbre[noeud] = valeur;
while (noeud > 0) {
noeud /= 2;
arbre[noeud] = max(arbre[noeud * 2], arbre[noeud * 2 + 1]);
}
}
int trouverMax(int gauche, int droite) {
gauche += MAXN, droite += MAXN;
int maxi = 0;
while (gauche <= droite) {
if (gauche % 2 == 1) {
maxi = max(maxi, arbre[gauche]);
gauche++;
}
if (droite % 2 == 0) {
maxi = max(maxi, arbre[droite]);
droite--;
}
gauche /= 2;
droite /= 2;
}
return maxi;
}
int32_t main() {
int N;
cin >> N;
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
h[i]--;
}
int v[N];
for (int i = 0; i < N; i++) {
cin >> v[i];
}
for (int i = 0; i < N; i++) {
ajout(h[i], v[i] + trouverMax(0, h[i]));
}
cout << trouverMax(0, N - 1) << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
#define inp 20
#define check exit(0)
#define nl cout << endl;
#define mod 1000000007
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
using namespace std;
// Pick yourself up, 'cause...
vector<ll> v(inp), h(inp);
vector<ll> st(inp << 2, 0);
int n;
void update(int i, ll nwans, int si = 1, int ss = 1, int se = n) {
if (ss == se) {
st[si] = max(st[si], nwans);
return;
}
int mid = (ss + se) / 2;
if (i <= mid)
update(i, nwans, si * 2, ss, mid);
else
update(i, nwans, si * 2 + 1, mid + 1, se);
st[si] = max(st[2 * si], st[2 * si + 1]);
}
int ch;
ll query(int l = 1, int r = ch, int si = 1, int ss = 1, int se = n) {
if (ss > r || se < l)
return 0;
if (ss >= l && se <= r)
return st[si];
int mid = (ss + se) / 2;
return max(query(l, r, si * 2, ss, mid),
query(l, r, si * 2 + 1, mid + 1, se));
}
int main() {
jaldi
cin >>
n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
ll ans = 0;
for (int i = 1; i <= n; i++) {
ch = h[i];
ll cv = v[i];
ll maxans = cv + query();
ans = max(ans, maxans);
update(ch, maxans);
// trace(maxans);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define inp 200005
#define check exit(0)
#define nl cout << endl;
#define mod 1000000007
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
using namespace std;
// Pick yourself up, 'cause...
vector<ll> v(inp), h(inp);
vector<ll> st(inp << 2, 0);
int n;
void update(int i, ll nwans, int si = 1, int ss = 1, int se = n) {
if (ss == se) {
st[si] = max(st[si], nwans);
return;
}
int mid = (ss + se) / 2;
if (i <= mid)
update(i, nwans, si * 2, ss, mid);
else
update(i, nwans, si * 2 + 1, mid + 1, se);
st[si] = max(st[2 * si], st[2 * si + 1]);
}
int ch;
ll query(int l = 1, int r = ch, int si = 1, int ss = 1, int se = n) {
if (ss > r || se < l)
return 0;
if (ss >= l && se <= r)
return st[si];
int mid = (ss + se) / 2;
return max(query(l, r, si * 2, ss, mid),
query(l, r, si * 2 + 1, mid + 1, se));
}
int main() {
jaldi
cin >>
n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
ll ans = 0;
for (int i = 1; i <= n; i++) {
ch = h[i];
ll cv = v[i];
ll maxans = cv + query();
ans = max(ans, maxans);
update(ch, maxans);
// trace(maxans);
}
cout << ans;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
// #include <tchar.h>
// #include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 200000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
LL a[N];
int h[N];
LL dp[N];
LL tree[N];
void update(int v, int l, int r, int pos, LL val) {
if (l > pos || r < pos)
return;
if (l == r) {
tree[v] = val;
return;
}
int mid = (l + r) / 2;
update(v * 2, l, mid, pos, val);
update(v * 2 + 1, mid + 1, r, pos, val);
tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}
LL mx(int v, int l, int r, int r1) {
if (l > r1)
return 0;
if (r <= r1)
return tree[v];
int mid = (l + r) / 2;
return max(mx(v * 2, l, mid, r1), mx(v * 2 + 1, mid + 1, r, r1));
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) {
dp[i] = mx(1, 1, n, h[i]) + a[i];
update(1, 1, n, h[i], dp[i]);
}
LL ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
printf("%lld\n", ans);
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
// #include <tchar.h>
// #include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 200000000
#define LINF 1000000000000000000
using namespace std;
const int N = 8e5 + 10;
LL a[N];
int h[N];
LL dp[N];
LL tree[N];
void update(int v, int l, int r, int pos, LL val) {
if (l > pos || r < pos)
return;
if (l == r) {
tree[v] = val;
return;
}
int mid = (l + r) / 2;
update(v * 2, l, mid, pos, val);
update(v * 2 + 1, mid + 1, r, pos, val);
tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}
LL mx(int v, int l, int r, int r1) {
if (l > r1)
return 0;
if (r <= r1)
return tree[v];
int mid = (l + r) / 2;
return max(mx(v * 2, l, mid, r1), mx(v * 2 + 1, mid + 1, r, r1));
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) {
dp[i] = mx(1, 1, n, h[i]) + a[i];
update(1, 1, n, h[i], dp[i]);
}
LL ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
printf("%lld\n", ans);
} | replace | 67 | 68 | 67 | 68 | 0 | |
p03176 | C++ | Runtime Error | // {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) \
for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) \
for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
static inline ll mod(ll x, ll m) {
ll y = x % m;
return (y >= 0 ? y : y + m);
}
// }}}
class SegmentTree {
size_t sz_, rsz_;
vector<ll> v_;
int construct(size_t idx) {
if (idx >= sz_ - 1)
return v_[idx];
return v_[idx] = max(construct(2 * idx + 1), construct(2 * idx + 2));
}
ll query(size_t a, size_t b, size_t k, size_t l, size_t r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return v_[k];
size_t mid = (l + r) / 2;
ll lv = query(a, b, 2 * k + 1, l, mid);
ll rv = query(a, b, 2 * k + 2, mid, r);
return max(lv, rv);
}
public:
SegmentTree(size_t n) : rsz_(n) {
sz_ = 1;
while (sz_ < rsz_)
sz_ *= 2;
v_.resize(2 * sz_ - 1, 0);
}
SegmentTree(vector<ll> &v) : rsz_(v.size()) {
sz_ = 1;
while (sz_ < rsz_)
sz_ *= 2;
v_.resize(2 * sz_ - 1, 0);
for (size_t i = 0; i < rsz_; i++) {
v_[sz_ - 1 + i] = v[i];
}
(void)construct(0);
}
// return min value in [a, b)
ll query(size_t a, size_t b) { return query(a, b, 0, 0, sz_); }
void update(size_t idx, ll k) {
idx += sz_ - 1;
v_[idx] = k;
while (idx > 0) {
idx = (idx - 1) / 2;
v_[idx] = max(v_[2 * idx + 1], v_[2 * idx + 2]);
}
}
void print() {
size_t vsz = v_.size();
for (size_t i = 0; i < vsz; i++) {
cout << v_[i] << " ";
}
cout << endl;
}
};
int N;
ll h[100000], a[100000];
void solve() {
ll hm = 0;
REP(i, N) hm = max(hm, h[i]);
SegmentTree st(hm + 1);
REP(i, N) {
ll val = max(st.query(h[i], h[i] + 1), st.query(0, h[i]) + a[i]);
st.update(h[i], val);
}
cout << st.query(0, hm + 1) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
solve();
return 0;
}
// vim:set foldmethod=marker:
| // {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) \
for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) \
for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
static inline ll mod(ll x, ll m) {
ll y = x % m;
return (y >= 0 ? y : y + m);
}
// }}}
class SegmentTree {
size_t sz_, rsz_;
vector<ll> v_;
int construct(size_t idx) {
if (idx >= sz_ - 1)
return v_[idx];
return v_[idx] = max(construct(2 * idx + 1), construct(2 * idx + 2));
}
ll query(size_t a, size_t b, size_t k, size_t l, size_t r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return v_[k];
size_t mid = (l + r) / 2;
ll lv = query(a, b, 2 * k + 1, l, mid);
ll rv = query(a, b, 2 * k + 2, mid, r);
return max(lv, rv);
}
public:
SegmentTree(size_t n) : rsz_(n) {
sz_ = 1;
while (sz_ < rsz_)
sz_ *= 2;
v_.resize(2 * sz_ - 1, 0);
}
SegmentTree(vector<ll> &v) : rsz_(v.size()) {
sz_ = 1;
while (sz_ < rsz_)
sz_ *= 2;
v_.resize(2 * sz_ - 1, 0);
for (size_t i = 0; i < rsz_; i++) {
v_[sz_ - 1 + i] = v[i];
}
(void)construct(0);
}
// return min value in [a, b)
ll query(size_t a, size_t b) { return query(a, b, 0, 0, sz_); }
void update(size_t idx, ll k) {
idx += sz_ - 1;
v_[idx] = k;
while (idx > 0) {
idx = (idx - 1) / 2;
v_[idx] = max(v_[2 * idx + 1], v_[2 * idx + 2]);
}
}
void print() {
size_t vsz = v_.size();
for (size_t i = 0; i < vsz; i++) {
cout << v_[i] << " ";
}
cout << endl;
}
};
int N;
ll h[200010], a[200010];
void solve() {
ll hm = 0;
REP(i, N) hm = max(hm, h[i]);
SegmentTree st(hm + 1);
REP(i, N) {
ll val = max(st.query(h[i], h[i] + 1), st.query(0, h[i]) + a[i]);
st.update(h[i], val);
}
cout << st.query(0, hm + 1) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
solve();
return 0;
}
// vim:set foldmethod=marker:
| replace | 116 | 117 | 116 | 117 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long t[600000];
int h[200001];
long long query(int index, int lb, int rb, int lq, int rq) {
if (lb == rb || (lq == lb && rb == rq))
return t[index];
int mid = (lb + rb) / 2;
if (lq > mid)
return query(index * 2 + 1, mid + 1, rb, lq, rq);
else if (rq <= mid)
return query(index * 2, lb, mid, lq, rq);
else
return max(query(index * 2, lb, mid, lq, mid),
query(index * 2 + 1, mid + 1, rb, mid + 1, rq));
}
long long update(int index, int lb, int rb, int leaf_id, long long value) {
if (lb == rb && lb == leaf_id)
t[index] = value;
int mid = (lb + rb) / 2;
if (leaf_id <= mid)
return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value));
else
return t[index] = max(t[index],
update(index * 2 + 1, mid + 1, rb, leaf_id, value));
}
int main() {
int i, n, a;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
update(1, 1, n, h[i], query(1, 1, n, 1, h[i] - 1) + a);
}
printf("%lld", t[1]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long t[600000];
int h[200001];
long long query(int index, int lb, int rb, int lq, int rq) {
if (lb == rb || (lq == lb && rb == rq))
return t[index];
int mid = (lb + rb) / 2;
if (lq > mid)
return query(index * 2 + 1, mid + 1, rb, lq, rq);
else if (rq <= mid)
return query(index * 2, lb, mid, lq, rq);
else
return max(query(index * 2, lb, mid, lq, mid),
query(index * 2 + 1, mid + 1, rb, mid + 1, rq));
}
long long update(int index, int lb, int rb, int leaf_id, long long value) {
if (lb == rb && lb == leaf_id)
return t[index] = value;
int mid = (lb + rb) / 2;
if (leaf_id <= mid)
return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value));
else
return t[index] = max(t[index],
update(index * 2 + 1, mid + 1, rb, leaf_id, value));
}
int main() {
int i, n, a;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &h[i]);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
update(1, 1, n, h[i], query(1, 1, n, 1, h[i] - 1) + a);
}
printf("%lld", t[1]);
return 0;
} | replace | 18 | 19 | 18 | 19 | -11 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
const int MAXN = 1 << 18; // 2.6e5
int N = 200000;
ll seg[2 * MAXN]; // root is seg[1]
void update(int p, ll val) {
for (seg[p += N] = val; p > 0; p >>= 1)
seg[p >> 1] = max(seg[p], seg[p ^ 1]);
}
ll query(int l, int r) // [l, r]
{
ll res = 0;
for (l += N, r += N; l <= r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, seg[l++]);
if (!(r & 1))
res = max(res, seg[r--]);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vi a(n), h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
update(h[i], query(1, h[i] - 1) + a[i]);
}
cout << query(1, N);
} | #include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
const int MAXN = 1 << 18; // 2.6e5
int N = 200000;
ll seg[2 * MAXN]; // root is seg[1]
void update(int p, ll val) {
for (seg[p += N] = val; p > 0; p >>= 1)
seg[p >> 1] = max(seg[p], seg[p ^ 1]);
}
ll query(int l, int r) // [l, r]
{
ll res = 0;
for (l += N, r += N; l <= r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, seg[l++]);
if (!(r & 1))
res = max(res, seg[r--]);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vi a(n), h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
update(h[i], query(1, h[i] - 1) + a[i]);
}
cout << query(1, N);
} | delete | 37 | 42 | 37 | 37 | 0 | |
p03176 | C++ | Runtime Error | #pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const long long lmax = 1999999999;
const long long lmx = 1999999999999999999;
const long long MAXN = 100003;
long long n, t[4 * MAXN];
void build(long long a[], long long v, long long tl, long long tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
long long tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
long long sum(long long v, long long tl, long long tr, long long l,
long long r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
long long tm = (tl + tr) / 2;
long long summ1 = sum(v * 2, tl, tm, l, min(r, tm));
long long summ2 = sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
return max(summ1, summ2);
}
void update(long long v, long long tl, long long tr, long long pos,
long long new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
long long tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
long long h[200003], b[200003];
long long dp[200003], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> h[i];
}
for (long long i = 1; i <= n; i++) {
cin >> b[i];
ans = max(ans, b[i]);
}
for (long long i = 1; i <= n; i++) {
long long r = sum(1, 0, n + 1, 0, h[i]);
dp[i] = r + b[i];
ans = max(dp[i], ans);
update(1, 0, n + 1, h[i], dp[i]);
}
cout << ans << endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
| #pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const long long lmax = 1999999999;
const long long lmx = 1999999999999999999;
const long long MAXN = 200003;
long long n, t[4 * MAXN];
void build(long long a[], long long v, long long tl, long long tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
long long tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
long long sum(long long v, long long tl, long long tr, long long l,
long long r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
long long tm = (tl + tr) / 2;
long long summ1 = sum(v * 2, tl, tm, l, min(r, tm));
long long summ2 = sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
return max(summ1, summ2);
}
void update(long long v, long long tl, long long tr, long long pos,
long long new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
long long tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
long long h[200003], b[200003];
long long dp[200003], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> h[i];
}
for (long long i = 1; i <= n; i++) {
cin >> b[i];
ans = max(ans, b[i]);
}
for (long long i = 1; i <= n; i++) {
long long r = sum(1, 0, n + 1, 0, h[i]);
dp[i] = r + b[i];
ans = max(dp[i], ans);
update(1, 0, n + 1, h[i], dp[i]);
}
cout << ans << endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
| replace | 6 | 7 | 6 | 7 | 0 | |
p03176 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int inf = 1e9 + 7;
const int maxn = 1e5 + 5;
LL b[maxn], d[maxn];
LL query(int p) {
LL res = 0;
while (p > 0) {
res = max(b[p], res);
p -= p & -p;
}
return res;
}
void add(LL x, int p) {
while (p < maxn) {
b[p] = max(b[p], x);
p += p & -p;
}
}
LL w[maxn], h[maxn];
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 0; i < n; ++i) {
cin >> w[i];
}
for (int i = 0; i < n; ++i) {
d[i] = query(h[i]) + w[i];
add(d[i], h[i]);
}
cout << *max_element(d, d + n) << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int inf = 1e9 + 7;
const int maxn = 2e5 + 5;
LL b[maxn], d[maxn];
LL query(int p) {
LL res = 0;
while (p > 0) {
res = max(b[p], res);
p -= p & -p;
}
return res;
}
void add(LL x, int p) {
while (p < maxn) {
b[p] = max(b[p], x);
p += p & -p;
}
}
LL w[maxn], h[maxn];
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 0; i < n; ++i) {
cin >> w[i];
}
for (int i = 0; i < n; ++i) {
d[i] = query(h[i]) + w[i];
add(d[i], h[i]);
}
cout << *max_element(d, d + n) << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define For(i, n) for (int i = 1; i <= (int)(n); i++)
#define Rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
#define cmax(x, y) x = max(x, y)
#define cmin(x, y) x = min(x, y)
#define pii pair<int, int>
#define vi vector<int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF = 0x7fffffff;
const int MAXN = 2e5 + 3;
int n, a[MAXN], b[MAXN];
ll tr[MAXN * 2], ans;
#define lson l, mid, k << 1
#define rson mid + 1, r, k << 1 | 1
void change(const int &p, const ll &v, const int &l, const int &r,
const int &k) {
if (l == p && r == p) {
tr[k] = v;
re;
}
int mid = (l + r) >> 1;
if (p <= mid)
change(p, v, lson);
if (p > mid)
change(p, v, rson);
tr[k] = max(tr[k << 1], tr[k << 1 | 1]);
}
ll query(const int &L, const int &R, const int &l, const int &r, const int &k) {
if (L > R)
re 0;
if (l >= L && r <= R)
re tr[k];
int mid = (l + r) >> 1;
ll ret = 0;
if (L <= mid)
cmax(ret, query(L, R, lson));
if (R > mid)
cmax(ret, query(L, R, rson));
re ret;
}
int main() {
fio;
cin >> n;
For(i, n) { cin >> a[i]; }
For(i, n) { cin >> b[i]; }
For(i, n) {
ll x = query(1, a[i] - 1, 1, n, 1);
change(a[i], x + b[i], 1, n, 1);
cmax(ans, x + b[i]);
}
cout << ans << endl;
re 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define For(i, n) for (int i = 1; i <= (int)(n); i++)
#define Rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
#define cmax(x, y) x = max(x, y)
#define cmin(x, y) x = min(x, y)
#define pii pair<int, int>
#define vi vector<int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF = 0x7fffffff;
const int MAXN = 2e5 + 3;
int n, a[MAXN], b[MAXN];
ll tr[MAXN * 4], ans;
#define lson l, mid, k << 1
#define rson mid + 1, r, k << 1 | 1
void change(const int &p, const ll &v, const int &l, const int &r,
const int &k) {
if (l == p && r == p) {
tr[k] = v;
re;
}
int mid = (l + r) >> 1;
if (p <= mid)
change(p, v, lson);
if (p > mid)
change(p, v, rson);
tr[k] = max(tr[k << 1], tr[k << 1 | 1]);
}
ll query(const int &L, const int &R, const int &l, const int &r, const int &k) {
if (L > R)
re 0;
if (l >= L && r <= R)
re tr[k];
int mid = (l + r) >> 1;
ll ret = 0;
if (L <= mid)
cmax(ret, query(L, R, lson));
if (R > mid)
cmax(ret, query(L, R, rson));
re ret;
}
int main() {
fio;
cin >> n;
For(i, n) { cin >> a[i]; }
For(i, n) { cin >> b[i]; }
For(i, n) {
ll x = query(1, a[i] - 1, 1, n, 1);
change(a[i], x + b[i], 1, n, 1);
cmax(ans, x + b[i]);
}
cout << ans << endl;
re 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll segtree[500001], n, h[300001], a[300001];
void update(ll node, ll start, ll end, ll ix, ll val) {
if (start == end) {
segtree[node] = val;
} else {
ll mid = (start + end) / 2;
if (ix <= mid)
update(2 * node, start, mid, ix, val);
else
update(2 * node + 1, mid + 1, end, ix, val);
segtree[node] = max(segtree[2 * node], segtree[2 * node + 1]);
}
}
ll qmax(ll node, ll start, ll end, ll l, ll r) {
ll mid = (start + end) / 2;
if (r < start || end < l)
return 0;
else if (l <= start && end <= r)
return segtree[node];
else
return max(qmax(2 * node, start, mid, l, r),
qmax(2 * node + 1, mid + 1, end, l, r));
}
int main() {
cin >> n;
memset(segtree, 0, sizeof(segtree));
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
update(1, 1, n, h[i], qmax(1, 1, n, 1, h[i] - 1) + a[i]);
}
cout << segtree[1] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll segtree[1000001], n, h[300001], a[300001];
void update(ll node, ll start, ll end, ll ix, ll val) {
if (start == end) {
segtree[node] = val;
} else {
ll mid = (start + end) / 2;
if (ix <= mid)
update(2 * node, start, mid, ix, val);
else
update(2 * node + 1, mid + 1, end, ix, val);
segtree[node] = max(segtree[2 * node], segtree[2 * node + 1]);
}
}
ll qmax(ll node, ll start, ll end, ll l, ll r) {
ll mid = (start + end) / 2;
if (r < start || end < l)
return 0;
else if (l <= start && end <= r)
return segtree[node];
else
return max(qmax(2 * node, start, mid, l, r),
qmax(2 * node + 1, mid + 1, end, l, r));
}
int main() {
cin >> n;
memset(segtree, 0, sizeof(segtree));
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
update(1, 1, n, h[i], qmax(1, 1, n, 1, h[i] - 1) + a[i]);
}
cout << segtree[1] << "\n";
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)
#define ITER(it, a) \
for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;
const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;
const int MAX = 1 << 18;
LL t[MAX];
int n;
pair<PII, int> a[MAX];
void a1(int v, int tl, int tr, int pos, LL add) {
if (tl == tr)
t[v] += add;
else {
int tm = (tl + tr) >> 1;
if (pos <= tm)
a1(v + v, tl, tm, pos, add);
else
a1(v + v + 1, tm + 1, tr, pos, add);
t[v] = max(t[v + v], t[v + v + 1]);
}
}
LL get(int v, int tl, int tr, int l, int r) {
if (l == tl && r == tr)
return t[v];
if (l > r || tl > tr)
return 0;
int tm = (tl + tr) >> 1;
return max(get(v + v, tl, tm, l, min(tm, r)),
get(v + v + 1, tm + 1, tr, max(tm + 1, l), r));
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("In.txt", "r", stdin);
// freopen("In.txt", "w", stdout);
cin >> n;
FOR(i, 0, n)
cin >> a[i].X.X, a[i].Y = i;
FOR(i, 0, n)
cin >> a[i].X.Y;
sort(a, a + n);
FOR(i, 0, n) {
int pl = a[i].Y;
// debug(pl);
LL que = get(1, 0, n - 1, 0, pl);
a1(1, 0, n - 1, pl, que + a[i].X.Y);
}
cout << get(1, 0, n - 1, 0, n - 1) << endl;
cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)
#define ITER(it, a) \
for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;
const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;
const int MAX = 1 << 20;
LL t[MAX];
int n;
pair<PII, int> a[MAX];
void a1(int v, int tl, int tr, int pos, LL add) {
if (tl == tr)
t[v] += add;
else {
int tm = (tl + tr) >> 1;
if (pos <= tm)
a1(v + v, tl, tm, pos, add);
else
a1(v + v + 1, tm + 1, tr, pos, add);
t[v] = max(t[v + v], t[v + v + 1]);
}
}
LL get(int v, int tl, int tr, int l, int r) {
if (l == tl && r == tr)
return t[v];
if (l > r || tl > tr)
return 0;
int tm = (tl + tr) >> 1;
return max(get(v + v, tl, tm, l, min(tm, r)),
get(v + v + 1, tm + 1, tr, max(tm + 1, l), r));
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("In.txt", "r", stdin);
// freopen("In.txt", "w", stdout);
cin >> n;
FOR(i, 0, n)
cin >> a[i].X.X, a[i].Y = i;
FOR(i, 0, n)
cin >> a[i].X.Y;
sort(a, a + n);
FOR(i, 0, n) {
int pl = a[i].Y;
// debug(pl);
LL que = get(1, 0, n - 1, 0, pl);
a1(1, 0, n - 1, pl, que + a[i].X.Y);
}
cout << get(1, 0, n - 1, 0, n - 1) << endl;
cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | Time elapsed: 0.034482
|
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PII pair<ll, ll>
#define VI vector<ll>
#define VB vector<bool>
#define VC vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS vector<string>
#define VP vector<PII>
#define lf(i, a, b) for (ll i = a; i <= b; i++)
#define lr(i, a, b) for (ll i = a; i >= b; i--)
#define lfl(i, v) for (ll i = 0; i < v.size(); i++)
#define lrl(i, v) for (ll i = (ll)(v.size()) - 1; i >= 0; i--)
#define chk2(a, b) cout << "check : " << a << " " << b << endl
#define chk3(a, b, c) cout << "check : " << a << " " << b << " " << c << endl
#define chk4(a, b, c, d) \
cout << "check : " << a << " " << b << " " << c << " " << d << endl
#define chk5(a, b, c, d, e) \
cout << "check : " << a << " " << b << " " << c << " " << d << " " << e \
<< endl
#define l_b(v, k) lower_bound(v.begin(), v.end(), k) - v.begin()
#define u_b(v, k) upper_bound(v.begin(), v.end(), k) - v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(), v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()
ll n, m, k;
VI v;
VI cmprs(VI &ht) {
VP vp(n);
VI ans(n + 1);
lf(i, 0, n - 1) { vp[i] = m_p(ht[i + 1], i + 1); }
sort(vp);
lf(i, 1, n) { ans[vp[i - 1].sec] = i; }
// cout<<endl;
// lf(i,1,n)
// cout<<ans[i]<<" ";
// cout<<endl;
return ans;
}
vector<ll> tree(400000, 0);
ll qry(vector<ll> &tree, ll ti, ll fi, ll ls, ll str, ll end) {
ll mid = (ls + fi) / 2;
if (str > ls || end < fi || fi > ls)
return 0;
if (str <= fi && ls <= end)
return tree[ti];
else
return max(qry(tree, ti * 2, fi, mid, str, end),
qry(tree, ti * 2 + 1, mid + 1, ls, str, end));
}
void updt(vector<ll> &tree, ll ti, ll fi, ll ls, ll ind, ll val) {
if (ind > ls || ind < fi || ls < fi)
return;
else if (ind <= fi && ls <= ind) {
tree[ti] += val;
} else {
ll mid = (ls + fi) / 2;
updt(tree, ti * 2, fi, mid, ind, val);
updt(tree, ti * 2 + 1, mid + 1, ls, ind, val);
tree[ti] = max(tree[ti * 2], tree[ti * 2 + 1]);
}
}
int main() {
cin >> n;
VI a = VI(n + 1);
VI ht = VI(n + 1);
lf(i, 1, n) { cin >> ht[i]; }
ht = cmprs(ht);
lf(i, 1, n) cin >> a[i];
VI dp(n + 1, 0);
lf(i, 1, n) {
dp[i] = a[i];
ll sum = qry(tree, 1, 0, n + 1, 1, ht[i] - 1);
dp[i] = max(dp[i], a[i] + sum);
updt(tree, 1, 0, n + 1, ht[i], dp[i]);
}
ll maxi = 0;
lf(i, 1, n) { maxi = max(maxi, dp[i]); } // cout<<dp[i]<<" ";}
cout << maxi << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PII pair<ll, ll>
#define VI vector<ll>
#define VB vector<bool>
#define VC vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS vector<string>
#define VP vector<PII>
#define lf(i, a, b) for (ll i = a; i <= b; i++)
#define lr(i, a, b) for (ll i = a; i >= b; i--)
#define lfl(i, v) for (ll i = 0; i < v.size(); i++)
#define lrl(i, v) for (ll i = (ll)(v.size()) - 1; i >= 0; i--)
#define chk2(a, b) cout << "check : " << a << " " << b << endl
#define chk3(a, b, c) cout << "check : " << a << " " << b << " " << c << endl
#define chk4(a, b, c, d) \
cout << "check : " << a << " " << b << " " << c << " " << d << endl
#define chk5(a, b, c, d, e) \
cout << "check : " << a << " " << b << " " << c << " " << d << " " << e \
<< endl
#define l_b(v, k) lower_bound(v.begin(), v.end(), k) - v.begin()
#define u_b(v, k) upper_bound(v.begin(), v.end(), k) - v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(), v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()
ll n, m, k;
VI v;
VI cmprs(VI &ht) {
VP vp(n);
VI ans(n + 1);
lf(i, 0, n - 1) { vp[i] = m_p(ht[i + 1], i + 1); }
sort(vp);
lf(i, 1, n) { ans[vp[i - 1].sec] = i; }
// cout<<endl;
// lf(i,1,n)
// cout<<ans[i]<<" ";
// cout<<endl;
return ans;
}
vector<ll> tree(800000, 0);
ll qry(vector<ll> &tree, ll ti, ll fi, ll ls, ll str, ll end) {
ll mid = (ls + fi) / 2;
if (str > ls || end < fi || fi > ls)
return 0;
if (str <= fi && ls <= end)
return tree[ti];
else
return max(qry(tree, ti * 2, fi, mid, str, end),
qry(tree, ti * 2 + 1, mid + 1, ls, str, end));
}
void updt(vector<ll> &tree, ll ti, ll fi, ll ls, ll ind, ll val) {
if (ind > ls || ind < fi || ls < fi)
return;
else if (ind <= fi && ls <= ind) {
tree[ti] += val;
} else {
ll mid = (ls + fi) / 2;
updt(tree, ti * 2, fi, mid, ind, val);
updt(tree, ti * 2 + 1, mid + 1, ls, ind, val);
tree[ti] = max(tree[ti * 2], tree[ti * 2 + 1]);
}
}
int main() {
cin >> n;
VI a = VI(n + 1);
VI ht = VI(n + 1);
lf(i, 1, n) { cin >> ht[i]; }
ht = cmprs(ht);
lf(i, 1, n) cin >> a[i];
VI dp(n + 1, 0);
lf(i, 1, n) {
dp[i] = a[i];
ll sum = qry(tree, 1, 0, n + 1, 1, ht[i] - 1);
dp[i] = max(dp[i], a[i] + sum);
updt(tree, 1, 0, n + 1, ht[i], dp[i]);
}
ll maxi = 0;
lf(i, 1, n) { maxi = max(maxi, dp[i]); } // cout<<dp[i]<<" ";}
cout << maxi << endl;
} | replace | 48 | 49 | 48 | 49 | 0 | |
p03176 | C++ | Runtime Error | /*
_____ _ _ _ _
|_ _| |__ ___ / \ _ __ ___| |__ _ _| |
| | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
| | | | | | __// ___ \| | | \__ \ | | | |_| | |
|_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define ppb pop_back
#define endl '\n'
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define vs vector<string>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define lbnd lower_bound
#define ubnd upper_bound
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
/* For Debugging */
#define DEBUG cerr << "\n>>>I'm Here<<<\n" << endl;
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl;
#define what_is(x) cerr << #x << " is " << x << endl;
std::mt19937_64
rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define TIME \
cerr << "\nTime elapsed: " << setprecision(5) \
<< 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n) \
cout << fixed; \
cout << setprecision(n);
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N 100005
vi seg(4 * N);
void build(ll cur, ll st, ll end) {
if (st == end) {
seg[cur] = 0;
return;
}
ll mid = (st + end) >> 1;
build(2 * cur, st, mid);
build(2 * cur + 1, mid + 1, end);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 1-change here */
}
ll query(ll cur, ll st, ll end, ll l, ll r) {
if (l <= st && r >= end)
return seg[cur];
if (l > r || r < st || l > end)
return 0; /* 2-change here */
ll mid = (st + end) >> 1;
ll ans1 = query(2 * cur, st, mid, l, r);
ll ans2 = query(2 * cur + 1, mid + 1, end, l, r);
return max(ans1, ans2); /* 3-change here */
}
void update(ll cur, ll st, ll end, ll pos, ll upd) {
if (st == end) {
// a[pos]+=upd; /* 4-change here */
seg[cur] += upd; /* 5-change here */
return;
}
ll mid = (st + end) >> 1;
if (st <= pos && pos <= mid)
update(2 * cur, st, mid, pos, upd);
else
update(2 * cur + 1, mid + 1, end, pos, upd);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 6-change here */
}
void solve() {
ll n;
cin >> n;
vi v(n), a(n);
rep(i, 0, n) cin >> v[i];
rep(i, 0, n) cin >> a[i];
build(1, 1, n);
repr(i, 0, n) { update(1, 1, n, v[i], query(1, 1, n, v[i] + 1, n) + a[i]); }
cout << query(1, 1, n, 1, n) << endl;
return;
}
int main() {
FAST int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
solve();
}
TIME return 0;
} | /*
_____ _ _ _ _
|_ _| |__ ___ / \ _ __ ___| |__ _ _| |
| | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
| | | | | | __// ___ \| | | \__ \ | | | |_| | |
|_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define ppb pop_back
#define endl '\n'
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define vs vector<string>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define lbnd lower_bound
#define ubnd upper_bound
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
/* For Debugging */
#define DEBUG cerr << "\n>>>I'm Here<<<\n" << endl;
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl;
#define what_is(x) cerr << #x << " is " << x << endl;
std::mt19937_64
rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define TIME \
cerr << "\nTime elapsed: " << setprecision(5) \
<< 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n) \
cout << fixed; \
cout << setprecision(n);
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N 200005
vi seg(4 * N);
void build(ll cur, ll st, ll end) {
if (st == end) {
seg[cur] = 0;
return;
}
ll mid = (st + end) >> 1;
build(2 * cur, st, mid);
build(2 * cur + 1, mid + 1, end);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 1-change here */
}
ll query(ll cur, ll st, ll end, ll l, ll r) {
if (l <= st && r >= end)
return seg[cur];
if (l > r || r < st || l > end)
return 0; /* 2-change here */
ll mid = (st + end) >> 1;
ll ans1 = query(2 * cur, st, mid, l, r);
ll ans2 = query(2 * cur + 1, mid + 1, end, l, r);
return max(ans1, ans2); /* 3-change here */
}
void update(ll cur, ll st, ll end, ll pos, ll upd) {
if (st == end) {
// a[pos]+=upd; /* 4-change here */
seg[cur] += upd; /* 5-change here */
return;
}
ll mid = (st + end) >> 1;
if (st <= pos && pos <= mid)
update(2 * cur, st, mid, pos, upd);
else
update(2 * cur + 1, mid + 1, end, pos, upd);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 6-change here */
}
void solve() {
ll n;
cin >> n;
vi v(n), a(n);
rep(i, 0, n) cin >> v[i];
rep(i, 0, n) cin >> a[i];
build(1, 1, n);
repr(i, 0, n) { update(1, 1, n, v[i], query(1, 1, n, v[i] + 1, n) + a[i]); }
cout << query(1, 1, n, 1, n) << endl;
return;
}
int main() {
FAST int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
solve();
}
TIME return 0;
} | replace | 59 | 60 | 59 | 60 | 0 |
Time elapsed: 36.739ms
|
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long int ll;
ll beauty[N];
ll bit[N];
ll height[N];
void update(int i, int n, ll w) {
int k = i;
ll sum = 0;
while (k <= n) {
bit[k] = max(bit[k], w);
k = k + (k & (-k));
}
}
ll getsum(ll x) {
ll sum = 0;
while (x != 0) {
sum = max(sum, bit[x]);
x = x - (x & (-x));
}
return sum;
}
int main() {
map<ll, ll> unique;
map<ll, ll>::iterator it;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> height[i];
for (int i = 1; i <= n; i++)
cin >> beauty[i];
ll ct = 1;
for (int i = 1; i <= n; i++) {
unique[height[i]] = 0;
}
for (it = unique.begin(); it != unique.end(); it++) {
if (it->second == 0) {
it->second = ct;
ct++;
}
}
for (int i = 0; i <= ct; i++) {
bit[i] = 0;
}
for (int i = 1; i <= n; i++) {
ll max_sum = getsum(unique[height[i]] - 1);
update(unique[height[i]], ct, max_sum + beauty[i]);
}
ll ans = getsum(ct);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define N 200005
typedef long long int ll;
ll beauty[N];
ll bit[N];
ll height[N];
void update(int i, int n, ll w) {
int k = i;
ll sum = 0;
while (k <= n) {
bit[k] = max(bit[k], w);
k = k + (k & (-k));
}
}
ll getsum(ll x) {
ll sum = 0;
while (x != 0) {
sum = max(sum, bit[x]);
x = x - (x & (-x));
}
return sum;
}
int main() {
map<ll, ll> unique;
map<ll, ll>::iterator it;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> height[i];
for (int i = 1; i <= n; i++)
cin >> beauty[i];
ll ct = 1;
for (int i = 1; i <= n; i++) {
unique[height[i]] = 0;
}
for (it = unique.begin(); it != unique.end(); it++) {
if (it->second == 0) {
it->second = ct;
ct++;
}
}
for (int i = 0; i <= ct; i++) {
bit[i] = 0;
}
for (int i = 1; i <= n; i++) {
ll max_sum = getsum(unique[height[i]] - 1);
update(unique[height[i]], ct, max_sum + beauty[i]);
}
ll ans = getsum(ct);
cout << ans << endl;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MAXN = 112345;
int n, m, k;
ll ft[MAXN];
ll get(int x) {
ll ans = 0;
for (; x; x -= x & -x) {
ans = max(ans, ft[x]);
}
return ans;
}
void update(int x, ll v) {
for (; x <= n; x += x & -x) {
ft[x] = max(v, ft[x]);
}
}
int h[MAXN], v[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", h + i);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", v + i);
}
ll ans = 0, sum;
for (int i = 1; i <= n; ++i) {
sum = get(h[i]) + v[i];
ans = max(ans, sum);
update(h[i], sum);
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MAXN = 212345;
int n, m, k;
ll ft[MAXN];
ll get(int x) {
ll ans = 0;
for (; x; x -= x & -x) {
ans = max(ans, ft[x]);
}
return ans;
}
void update(int x, ll v) {
for (; x <= n; x += x & -x) {
ft[x] = max(v, ft[x]);
}
}
int h[MAXN], v[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", h + i);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", v + i);
}
ll ans = 0, sum;
for (int i = 1; i <= n; ++i) {
sum = get(h[i]) + v[i];
ans = max(ans, sum);
update(h[i], sum);
}
printf("%lld\n", ans);
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03176 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define int long long
#define trace(x) cerr << #x << ": " << x << " " << endl;
inline int add(int a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
return a;
}
inline int sub(int a, int b) {
a -= b;
if (a < 0)
a += MOD;
return a;
}
inline int mul(int a, int b) { return (int)((int)a * b % MOD); }
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define N 2 * 10000
int h[2 * 10000 + 5];
int v[2 * 10000 + 5];
int dp[2 * 10000 + 5];
int segtree[4 * (N + 1)];
int query_segtree(int si, int l, int r, int ql, int qr) {
if (l > qr || r < ql)
return LONG_LONG_MIN;
if (ql <= l && qr >= r)
return segtree[si];
auto t1 = query_segtree(2 * si, l, (l + r) / 2, ql, qr);
auto t2 = query_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, qr);
return max(t1, t2);
}
void update_segtree(int si, int l, int r, int ql, int s) {
if (l > ql || r < ql)
return;
if (ql == l && l == r) {
segtree[si] = s;
return;
}
update_segtree(2 * si, l, (l + r) / 2, ql, s);
update_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, s);
auto t1 = segtree[2 * si];
auto t2 = segtree[2 * si + 1];
segtree[si] = max(t1, t2);
}
signed main() {
IOS map<int, int> ind;
map<int, int> rmap;
int n;
cin >> n;
REP(i, n)
cin >> h[i];
REP(i, n)
cin >> v[i];
int mans = 0;
REP(i, n) {
int ret = query_segtree(1, 1, n, 1, h[i] - 1);
if (ret <= 0) {
dp[i] = v[i];
update_segtree(1, 1, n, h[i], dp[i]);
} else {
dp[i] = ret + v[i];
update_segtree(1, 1, n, h[i], dp[i]);
}
mans = max(mans, dp[i]);
// cout << i << " " << dp[i] << "\n";
}
cout << mans;
} |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define int long long
#define trace(x) cerr << #x << ": " << x << " " << endl;
inline int add(int a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
return a;
}
inline int sub(int a, int b) {
a -= b;
if (a < 0)
a += MOD;
return a;
}
inline int mul(int a, int b) { return (int)((int)a * b % MOD); }
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define N 2 * 100000 + 1
int h[2 * 100000 + 5];
int v[2 * 100000 + 5];
int dp[2 * 100000 + 5];
int segtree[4 * (N + 1)];
int query_segtree(int si, int l, int r, int ql, int qr) {
if (l > qr || r < ql)
return LONG_LONG_MIN;
if (ql <= l && qr >= r)
return segtree[si];
auto t1 = query_segtree(2 * si, l, (l + r) / 2, ql, qr);
auto t2 = query_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, qr);
return max(t1, t2);
}
void update_segtree(int si, int l, int r, int ql, int s) {
if (l > ql || r < ql)
return;
if (ql == l && l == r) {
segtree[si] = s;
return;
}
update_segtree(2 * si, l, (l + r) / 2, ql, s);
update_segtree(2 * si + 1, (l + r) / 2 + 1, r, ql, s);
auto t1 = segtree[2 * si];
auto t2 = segtree[2 * si + 1];
segtree[si] = max(t1, t2);
}
signed main() {
IOS map<int, int> ind;
map<int, int> rmap;
int n;
cin >> n;
REP(i, n)
cin >> h[i];
REP(i, n)
cin >> v[i];
int mans = 0;
REP(i, n) {
int ret = query_segtree(1, 1, n, 1, h[i] - 1);
if (ret <= 0) {
dp[i] = v[i];
update_segtree(1, 1, n, h[i], dp[i]);
} else {
dp[i] = ret + v[i];
update_segtree(1, 1, n, h[i], dp[i]);
}
mans = max(mans, dp[i]);
// cout << i << " " << dp[i] << "\n";
}
cout << mans;
} | replace | 42 | 46 | 42 | 46 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
vector<ll> dp(N);
int main() {
int n;
cin >> n;
int base = 1;
while (base <= n) {
base <<= 1;
}
vector<ll> tree(2 * N);
int h[n], a[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
int x = h[i] + base;
ll best = 0;
while (x > 1) {
if (x % 2 == 1) {
best = max(best, tree[x - 1]);
}
x >>= 1;
}
dp[h[i]] = best + a[i];
for (int j = base + h[i]; j >= 1; j >>= 1) {
tree[j] = max(tree[j], dp[h[i]]);
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
vector<ll> dp(N);
int main() {
int n;
cin >> n;
int base = 1;
while (base <= n) {
base <<= 1;
}
vector<ll> tree(2 * base);
int h[n], a[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
int x = h[i] + base;
ll best = 0;
while (x > 1) {
if (x % 2 == 1) {
best = max(best, tree[x - 1]);
}
x >>= 1;
}
dp[h[i]] = best + a[i];
for (int j = base + h[i]; j >= 1; j >>= 1) {
tree[j] = max(tree[j], dp[h[i]]);
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p03176 | C++ | Runtime Error | // #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define REP(i, a, b) for (long long int i = a; i < b; i++)
#define mp make_pair
#define mt make_tuple
#define INF 1000000000000000000
#define mod 1000000007
#define pi pair<ll, ll>
#define pd pair<ld, ld>
#define tp tuple<ll, ll, ll>
#define td tuple<ld, ld, ld>
#define vi vector<ll>
#define vd vector<ld>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvd vector<vd>
#define vpi vector<pi>
#define vpd vector<pd>
#define vs vector<string>
#define vvs vector<vs>
#define us unordered_set<ll>
#define um unordered_map<ll, ll>
#define MXPQ priority_queue<ll>
#define MNPQ priority_queue<ll, vi, greater<ll>>
#define sortA(a) sort(a.begin(), a.end())
#define sortD(a) sort(a.begin(), a.end(), greater<ll>())
#define all(a) a.begin(), a.end()
#define bll __builtin_popcountll
#define N 200005
const ld PI = acos(-1);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
#define in insert
#define fbo find_by_order
#define ook order_of_key
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(char s) {
string x = "";
x += s;
return x;
}
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t sze> string to_string(bitset<sze> v) {
string res = "";
for (size_t i = 0; i < sze; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll powmod(ll a, ll b, ll p) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = (res * a) % p;
}
a = (a * a) % p;
b >>= 1;
}
return res;
}
void print1D(vi a) {
for (ll i = 0; i < (ll)a.size(); ++i) {
cout << a[i] << " ";
}
cout << endl;
}
void print2D(vector<vi> a) {
for (ll i = 0; i < (ll)a.size(); ++i) {
for (ll j = 0; j < (ll)a[i].size(); ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
vi h(N), a(N);
vi T(4 * N);
ll rangeQuery(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r) {
return 0;
}
if (l == tl && r == tr) {
return T[v];
}
ll tm = (tl + tr) / 2;
return max(rangeQuery(2 * v, tl, tm, l, min(r, tm)),
rangeQuery(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
if (tl == tr) {
T[v] = new_val;
} else {
ll tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, pos, new_val);
else
update(2 * v + 1, tm + 1, tr, pos, new_val);
T[v] = max(T[2 * v], T[2 * v + 1]);
}
}
void solve() {
ll n;
cin >> n;
for (ll i = 0; i < n; ++i) {
cin >> h[i];
}
for (ll i = 0; i < n; ++i) {
cin >> a[i];
}
ll ans = 0;
for (ll i = 0; i < n; ++i) {
ll x = rangeQuery(1, 0, N - 1, 1, h[i] - 1);
ans = max(ans, a[i] + x);
update(1, 0, N - 1, h[i], a[i] + x);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| // #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define REP(i, a, b) for (long long int i = a; i < b; i++)
#define mp make_pair
#define mt make_tuple
#define INF 1000000000000000000
#define mod 1000000007
#define pi pair<ll, ll>
#define pd pair<ld, ld>
#define tp tuple<ll, ll, ll>
#define td tuple<ld, ld, ld>
#define vi vector<ll>
#define vd vector<ld>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvd vector<vd>
#define vpi vector<pi>
#define vpd vector<pd>
#define vs vector<string>
#define vvs vector<vs>
#define us unordered_set<ll>
#define um unordered_map<ll, ll>
#define MXPQ priority_queue<ll>
#define MNPQ priority_queue<ll, vi, greater<ll>>
#define sortA(a) sort(a.begin(), a.end())
#define sortD(a) sort(a.begin(), a.end(), greater<ll>())
#define all(a) a.begin(), a.end()
#define bll __builtin_popcountll
#define N 200005
const ld PI = acos(-1);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
#define in insert
#define fbo find_by_order
#define ook order_of_key
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(char s) {
string x = "";
x += s;
return x;
}
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t sze> string to_string(bitset<sze> v) {
string res = "";
for (size_t i = 0; i < sze; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll powmod(ll a, ll b, ll p) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = (res * a) % p;
}
a = (a * a) % p;
b >>= 1;
}
return res;
}
void print1D(vi a) {
for (ll i = 0; i < (ll)a.size(); ++i) {
cout << a[i] << " ";
}
cout << endl;
}
void print2D(vector<vi> a) {
for (ll i = 0; i < (ll)a.size(); ++i) {
for (ll j = 0; j < (ll)a[i].size(); ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
vi h(N), a(N);
vi T(4 * N);
ll rangeQuery(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r) {
return 0;
}
if (l == tl && r == tr) {
return T[v];
}
ll tm = (tl + tr) / 2;
return max(rangeQuery(2 * v, tl, tm, l, min(r, tm)),
rangeQuery(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
if (tl == tr) {
T[v] = new_val;
} else {
ll tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, pos, new_val);
else
update(2 * v + 1, tm + 1, tr, pos, new_val);
T[v] = max(T[2 * v], T[2 * v + 1]);
}
}
void solve() {
ll n;
cin >> n;
for (ll i = 0; i < n; ++i) {
cin >> h[i];
}
for (ll i = 0; i < n; ++i) {
cin >> a[i];
}
ll ans = 0;
for (ll i = 0; i < n; ++i) {
ll x = rangeQuery(1, 0, N - 1, 1, h[i] - 1);
ans = max(ans, a[i] + x);
update(1, 0, N - 1, h[i], a[i] + x);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| replace | 197 | 201 | 197 | 201 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
const int MAX_N = 1 << 17;
// ใปใฐใกใณใๆจใๆใคใฐใญใผใใซ้
ๅ
LL n, dat[2 * MAX_N - 1];
// ๅๆๅ
void init(int n_) {
// ็ฐกๅใฎใใใซ่ฆ็ด ๆฐใ2ใฎในใไนใซ
n = 1;
while (n < n_)
n *= 2;
// ๅ
จใฆใฎๅคใINT_MAXใซ
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 1e12;
}
// k็ช็ฎใฎๅค(0-index)ใaใซๅคๆด
void update(int k, LL a) {
// ่ใฎ็ฏ็น
k += n - 1;
dat[k] = a;
// ็ปใใชใใๆดๆฐ
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b]ใฎๆๅฐๅคใๆฑใใ
// ๅพใใฎๆนใฎๅผๆฐใฏ่จ็ฎใฎ็ฐกๅใฎใใใฎๅผๆฐ
// kใฏ็ฏ็น็ชๅท๏ผl.rใฏใใฎ็ฏ็นใ[l,r]ใซๅฏพๅฟใฅใใฆใใใใจใ่กจใ
// ๅพใฃใฆๅคใใใฏquery(a,b,0,0,n-1)ใจใใฆๅผใถ
LL query(int a, int b, LL k, int l, int r) {
//[a,b]ใจ[l,r]ใไบคๅทฎใใชใใใฐINT_MAX
if (r < a || b < l)
return 1e12;
//[a,b]ใ[l,r]ใๅฎๅ
จใซๅซใใงใใใฐใใฎ็ฏ็นใฎๅค
if (a <= l && r <= b)
return dat[k];
else {
// ใใใงใชใใใฐ2ใคใฎๅญใฎๆๅฐๅค
LL vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
LL vr = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);
return min(vl, vr);
}
}
int h[200001];
LL a[200001];
typedef pair<int, int> P;
vector<P> v;
LL dp[200001];
int main() {
int N;
cin >> N;
init(200010);
REP(i, N + 5) { update(i, 0); }
REP(i, N) {
cin >> h[i];
v.push_back(P(h[i], i));
}
sort(v.begin(), v.end());
REP(i, N) { cin >> a[i]; }
REP(i, v.size()) {
int x = v[i].second;
// cout<<v[i].first<<v[i].second<<endl;
if (x == 0) {
dp[x] = a[x];
update(x, -dp[x]);
} else {
LL aa = query(0, x - 1, 0, 0, n - 1);
dp[x] = a[x] - aa;
update(x, -dp[x]);
}
}
LL ans = 0;
REP(i, N) {
// cout<<dp[i]<<endl;
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
const int MAX_N = 1 << 20;
// ใปใฐใกใณใๆจใๆใคใฐใญใผใใซ้
ๅ
LL n, dat[2 * MAX_N - 1];
// ๅๆๅ
void init(int n_) {
// ็ฐกๅใฎใใใซ่ฆ็ด ๆฐใ2ใฎในใไนใซ
n = 1;
while (n < n_)
n *= 2;
// ๅ
จใฆใฎๅคใINT_MAXใซ
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 1e12;
}
// k็ช็ฎใฎๅค(0-index)ใaใซๅคๆด
void update(int k, LL a) {
// ่ใฎ็ฏ็น
k += n - 1;
dat[k] = a;
// ็ปใใชใใๆดๆฐ
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b]ใฎๆๅฐๅคใๆฑใใ
// ๅพใใฎๆนใฎๅผๆฐใฏ่จ็ฎใฎ็ฐกๅใฎใใใฎๅผๆฐ
// kใฏ็ฏ็น็ชๅท๏ผl.rใฏใใฎ็ฏ็นใ[l,r]ใซๅฏพๅฟใฅใใฆใใใใจใ่กจใ
// ๅพใฃใฆๅคใใใฏquery(a,b,0,0,n-1)ใจใใฆๅผใถ
LL query(int a, int b, LL k, int l, int r) {
//[a,b]ใจ[l,r]ใไบคๅทฎใใชใใใฐINT_MAX
if (r < a || b < l)
return 1e12;
//[a,b]ใ[l,r]ใๅฎๅ
จใซๅซใใงใใใฐใใฎ็ฏ็นใฎๅค
if (a <= l && r <= b)
return dat[k];
else {
// ใใใงใชใใใฐ2ใคใฎๅญใฎๆๅฐๅค
LL vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
LL vr = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);
return min(vl, vr);
}
}
int h[200001];
LL a[200001];
typedef pair<int, int> P;
vector<P> v;
LL dp[200001];
int main() {
int N;
cin >> N;
init(200010);
REP(i, N + 5) { update(i, 0); }
REP(i, N) {
cin >> h[i];
v.push_back(P(h[i], i));
}
sort(v.begin(), v.end());
REP(i, N) { cin >> a[i]; }
REP(i, v.size()) {
int x = v[i].second;
// cout<<v[i].first<<v[i].second<<endl;
if (x == 0) {
dp[x] = a[x];
update(x, -dp[x]);
} else {
LL aa = query(0, x - 1, 0, 0, n - 1);
dp[x] = a[x] - aa;
update(x, -dp[x]);
}
}
LL ans = 0;
REP(i, N) {
// cout<<dp[i]<<endl;
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03176 | C++ | Runtime Error | /*โ โโโโโโโPrashikโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x, it) for (auto it = x.begin(); it != x.end(); ++it)
#define fpresent(x, c) ((c).find(x) != (c).end()) // set,map
#define present(c, x) (find(all(c), x) != (c).end()) // vector
#define pb push_back
#define mp make_pair
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
vector<ll> tree(100000);
ll n;
void buildtree(ll a[], ll node, ll left, ll right) {
if (left == right) {
tree[node] = a[left];
} else {
ll mid = (left + right) / 2;
buildtree(a, 2 * node + 1, left, mid);
buildtree(a, 2 * node + 2, mid + 1, right);
tree[node] =
max(tree[2 * node + 1],
tree[2 * node +
2]); // this tree is for the sum in the given range query ,
// this line can be modified according to the need for
// example, if we have to find the minimum in the given
// range we can accordingly change the line of command;
}
}
void updateutil(
ll a[], ll x, ll pos, ll left, ll right,
ll node) // give the val to be updated and the pos where to update. pos
// should be with respect to the original array.
{
if (left == right) {
a[pos] = x;
tree[node] = x;
} else {
ll mid = (left + right) / 2;
if (pos <= mid) {
updateutil(a, x, pos, left, mid, 2 * node + 1);
} else
updateutil(a, x, pos, mid + 1, right, 2 * node + 2);
tree[node] = max(tree[2 * node + 1],
tree[2 * node + 2]); // this line can be changed
// accordingly for a different query
}
}
void update(ll a[], ll x, ll pos) { updateutil(a, x, pos - 1, 0, n - 1, 0); }
void prlltree() {
for (ll i = 0; i < 2 * n - 1; i++)
cout << tree[i] << endl;
}
ll queryutil(ll left, ll right, ll l, ll r, ll node) {
if (left == l && right == r) {
return tree[node];
} else {
if (left <= right) {
ll mid = (l + r) / 2;
if (mid >= right) {
return queryutil(left, right, l, mid, 2 * node + 1);
}
if (left > mid) {
return queryutil(left, right, mid + 1, r, 2 * node + 2);
}
if (left <= mid && right > mid) {
return max(queryutil(left, mid, l, mid, 2 * node + 1),
queryutil(mid + 1, right, mid + 1, r,
2 * node + 2)); // this line can be changed for
// minimum or maximum query
}
} else
return 0;
}
}
ll query(ll left, ll right) {
return queryutil(left - 1, right - 1, 0, n - 1, 0);
}
int main() {
// freopen("input.in","r",stdin);
// freopen("output.in","w",stdout);
fastio;
cin.tie(NULL);
ll m, i, j, k, ans = 0;
cin >> n;
ll h[n], a[n], rev[n + 1];
for (i = 0; i < n; i++) {
cin >> h[i];
rev[h[i]] = i;
}
for (i = 0; i < n; i++)
cin >> a[i];
ll val[n];
for (i = 0; i < n; i++)
val[i] = 0;
buildtree(val, 0, 0, n - 1);
for (i = 1; i <= n; i++) {
ll pos = rev[i];
ll temp = query(1, pos + 1);
ans = max(ans, temp + a[pos]);
update(val, a[pos] + temp, pos + 1);
val[pos] = a[pos] + temp;
// for(j=0;j<n;j++)
// cout<<val[j]<<" ";
// cout<<endl;
}
cout << ans << endl;
return 0;
}
| /*โ โโโโโโโPrashikโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโ*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x, it) for (auto it = x.begin(); it != x.end(); ++it)
#define fpresent(x, c) ((c).find(x) != (c).end()) // set,map
#define present(c, x) (find(all(c), x) != (c).end()) // vector
#define pb push_back
#define mp make_pair
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
vector<ll> tree(4000000);
ll n;
void buildtree(ll a[], ll node, ll left, ll right) {
if (left == right) {
tree[node] = a[left];
} else {
ll mid = (left + right) / 2;
buildtree(a, 2 * node + 1, left, mid);
buildtree(a, 2 * node + 2, mid + 1, right);
tree[node] =
max(tree[2 * node + 1],
tree[2 * node +
2]); // this tree is for the sum in the given range query ,
// this line can be modified according to the need for
// example, if we have to find the minimum in the given
// range we can accordingly change the line of command;
}
}
void updateutil(
ll a[], ll x, ll pos, ll left, ll right,
ll node) // give the val to be updated and the pos where to update. pos
// should be with respect to the original array.
{
if (left == right) {
a[pos] = x;
tree[node] = x;
} else {
ll mid = (left + right) / 2;
if (pos <= mid) {
updateutil(a, x, pos, left, mid, 2 * node + 1);
} else
updateutil(a, x, pos, mid + 1, right, 2 * node + 2);
tree[node] = max(tree[2 * node + 1],
tree[2 * node + 2]); // this line can be changed
// accordingly for a different query
}
}
void update(ll a[], ll x, ll pos) { updateutil(a, x, pos - 1, 0, n - 1, 0); }
void prlltree() {
for (ll i = 0; i < 2 * n - 1; i++)
cout << tree[i] << endl;
}
ll queryutil(ll left, ll right, ll l, ll r, ll node) {
if (left == l && right == r) {
return tree[node];
} else {
if (left <= right) {
ll mid = (l + r) / 2;
if (mid >= right) {
return queryutil(left, right, l, mid, 2 * node + 1);
}
if (left > mid) {
return queryutil(left, right, mid + 1, r, 2 * node + 2);
}
if (left <= mid && right > mid) {
return max(queryutil(left, mid, l, mid, 2 * node + 1),
queryutil(mid + 1, right, mid + 1, r,
2 * node + 2)); // this line can be changed for
// minimum or maximum query
}
} else
return 0;
}
}
ll query(ll left, ll right) {
return queryutil(left - 1, right - 1, 0, n - 1, 0);
}
int main() {
// freopen("input.in","r",stdin);
// freopen("output.in","w",stdout);
fastio;
cin.tie(NULL);
ll m, i, j, k, ans = 0;
cin >> n;
ll h[n], a[n], rev[n + 1];
for (i = 0; i < n; i++) {
cin >> h[i];
rev[h[i]] = i;
}
for (i = 0; i < n; i++)
cin >> a[i];
ll val[n];
for (i = 0; i < n; i++)
val[i] = 0;
buildtree(val, 0, 0, n - 1);
for (i = 1; i <= n; i++) {
ll pos = rev[i];
ll temp = query(1, pos + 1);
ans = max(ans, temp + a[pos]);
update(val, a[pos] + temp, pos + 1);
val[pos] = a[pos] + temp;
// for(j=0;j<n;j++)
// cout<<val[j]<<" ";
// cout<<endl;
}
cout << ans << endl;
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
int mo = 1000000007;
struct stnode {
int ma;
};
stnode st[500005];
int h[200005];
int bty[200005];
int n;
void merge(stnode &f, stnode &n1, stnode &n2) { f.ma = max(n1.ma, n2.ma); }
void build(int node, int l, int r) {
if (l == r) {
st[node].ma = 0;
return;
}
int m = (l + r) / 2;
build(2 * node, l, m);
build(2 * node + 1, m + 1, r);
merge(st[node], st[2 * node], st[2 * node + 1]);
}
void update(int node, int l, int r, int pos, int val) {
if (l == r) {
st[node].ma = max(st[node].ma, val);
} else {
int mid = (l + r) / 2;
if (pos <= mid)
update(2 * node, l, mid, pos, val);
else
update(2 * node + 1, mid + 1, r, pos, val);
merge(st[node], st[2 * node], st[2 * node + 1]);
// cout<<ind<<" "<<st[ind].best<<"\n";
}
}
stnode query(int ind, int l, int r, int lo, int hi) {
if (l == lo && r == hi)
return st[ind];
int mid = (l + r) / 2;
if (lo > mid)
return query(2 * ind + 1, mid + 1, r, lo, hi);
if (hi <= mid)
return query(2 * ind, l, mid, lo, hi);
stnode left = query(2 * ind, l, mid, lo, mid);
stnode right = query(2 * ind + 1, mid + 1, r, mid + 1, hi);
stnode result;
merge(result, left, right);
return result;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
build(1, 1, n);
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> bty[i];
int ans = 0;
for (int i = 0; i < n; i++) {
int q = 0;
if (h[i] > 1)
q = query(1, 1, n, 1, h[i] - 1).ma;
ans = max(ans, q + bty[i]);
update(1, 1, n, h[i], q + bty[i]);
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
int mo = 1000000007;
struct stnode {
int ma;
};
stnode st[1000005];
int h[200005];
int bty[200005];
int n;
void merge(stnode &f, stnode &n1, stnode &n2) { f.ma = max(n1.ma, n2.ma); }
void build(int node, int l, int r) {
if (l == r) {
st[node].ma = 0;
return;
}
int m = (l + r) / 2;
build(2 * node, l, m);
build(2 * node + 1, m + 1, r);
merge(st[node], st[2 * node], st[2 * node + 1]);
}
void update(int node, int l, int r, int pos, int val) {
if (l == r) {
st[node].ma = max(st[node].ma, val);
} else {
int mid = (l + r) / 2;
if (pos <= mid)
update(2 * node, l, mid, pos, val);
else
update(2 * node + 1, mid + 1, r, pos, val);
merge(st[node], st[2 * node], st[2 * node + 1]);
// cout<<ind<<" "<<st[ind].best<<"\n";
}
}
stnode query(int ind, int l, int r, int lo, int hi) {
if (l == lo && r == hi)
return st[ind];
int mid = (l + r) / 2;
if (lo > mid)
return query(2 * ind + 1, mid + 1, r, lo, hi);
if (hi <= mid)
return query(2 * ind, l, mid, lo, hi);
stnode left = query(2 * ind, l, mid, lo, mid);
stnode right = query(2 * ind + 1, mid + 1, r, mid + 1, hi);
stnode result;
merge(result, left, right);
return result;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
build(1, 1, n);
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> bty[i];
int ans = 0;
for (int i = 0; i < n; i++) {
int q = 0;
if (h[i] > 1)
q = query(1, 1, n, 1, h[i] - 1).ma;
ans = max(ans, q + bty[i]);
update(1, 1, n, h[i], q + bty[i]);
}
cout << ans;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p * p) % m;
if (n % 2)
return (p * a) % m;
else
return p;
}
const ll mod = 1e9 + 7;
const int N = int(3e5) + 999;
#define int long long int
#define inf 1e18
int n;
int st[400005];
int dp[100005];
int query(int l, int r, int i, int qs, int qe) {
if (l > r)
return -inf;
if (qs > r or qe < l)
return -inf;
if (qs <= l and qe >= r)
return st[i];
int m = (l + r) / 2;
return max(query(l, m, 2 * i + 1, qs, qe),
query(m + 1, r, 2 * i + 2, qs, qe));
}
void update(int l, int r, int i, int index, int val) {
if (l > r)
return;
if (index > r or index < l)
return;
if (l == r) {
st[i] = val;
return;
}
int m = (l + r) / 2;
update(l, m, 2 * i + 1, index, val);
update(m + 1, r, 2 * i + 2, index, val);
st[i] = max(st[2 * i + 1], st[2 * i + 2]);
}
int32_t main() {
IOS;
cin >> n;
int h[n], b[n];
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int dp[n];
for (int i = 0; i < n; i++) {
int mx = 0;
if (h[i] > 1)
mx = query(0, n - 1, 0, 0, h[i] - 2);
dp[i] = b[i] + mx;
update(0, n - 1, 0, h[i] - 1, dp[i]);
}
int ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, dp[i]);
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p * p) % m;
if (n % 2)
return (p * a) % m;
else
return p;
}
const ll mod = 1e9 + 7;
const int N = int(3e5) + 999;
#define int long long int
#define inf 1e18
int n;
int st[4000005];
int dp[1000005];
int query(int l, int r, int i, int qs, int qe) {
if (l > r)
return -inf;
if (qs > r or qe < l)
return -inf;
if (qs <= l and qe >= r)
return st[i];
int m = (l + r) / 2;
return max(query(l, m, 2 * i + 1, qs, qe),
query(m + 1, r, 2 * i + 2, qs, qe));
}
void update(int l, int r, int i, int index, int val) {
if (l > r)
return;
if (index > r or index < l)
return;
if (l == r) {
st[i] = val;
return;
}
int m = (l + r) / 2;
update(l, m, 2 * i + 1, index, val);
update(m + 1, r, 2 * i + 2, index, val);
st[i] = max(st[2 * i + 1], st[2 * i + 2]);
}
int32_t main() {
IOS;
cin >> n;
int h[n], b[n];
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int dp[n];
for (int i = 0; i < n; i++) {
int mx = 0;
if (h[i] > 1)
mx = query(0, n - 1, 0, 0, h[i] - 2);
dp[i] = b[i] + mx;
update(0, n - 1, 0, h[i] - 1, dp[i]);
}
int ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, dp[i]);
cout << ans;
return 0;
} | replace | 43 | 45 | 43 | 45 | 0 | |
p03176 | C++ | Runtime Error | /* * * * * * * * * * * **
* *
* saurabh8522 *
* I will handle *
* IT. *
* *
* * * * * * * * * * * **/
#include <bits/stdc++.h>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a), 0, sizeof((a)))
#define one(a) memset((a), 1, sizeof((a)))
#define minus(a) memset((a), -1, sizeof((a)))
#define all(g) g.begin(), g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
ll numdigit(ll n) { return floor(log10(n)) + 1; }
bool isPowerTwo(ll x) { return x && (!(x & (x - 1))); }
ll seg[500005];
ll dp[500005];
void build(ll node, ll s, ll e) {
// cout<<node<<" "<<s<<" "<<e<<endl;
if (s == e) {
seg[node] = dp[s];
return;
}
ll mid = (s + e) >> 1;
build(2 * node + 1, s, mid);
build(2 * node + 2, mid + 1, e);
seg[node] = max(seg[2 * node + 1], seg[2 * node + 2]);
}
ll query(ll node, ll s, ll e, ll qs, ll qe) {
if (qs <= s && qe >= e) {
return seg[node];
}
if (qe < s || qs > e) {
return 0;
}
ll mid = (s + e) >> 1;
return max(query(2 * node + 1, s, mid, qs, qe),
query(2 * node + 2, mid + 1, e, qs, qe));
}
void update(ll node, ll s, ll e, ll index, ll val) {
if (s == e) {
seg[node] += val;
return;
}
ll mid = (s + e) >> 1;
if (index <= mid && index >= s) {
update(2 * node + 1, s, mid, index, val);
} else {
update(2 * node + 2, mid + 1, e, index, val);
}
seg[node] = max(seg[2 * node + 1], seg[2 * node + 2]);
}
int main() {
// FastRead;
ll t = 1;
// cin>>t;
while (t--) {
ll n;
cin >> n;
vector<ll> h(n), a(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// ll dp[n+1];
zero(dp);
build(0, 0, n);
// cout<<0<<endl;
for (int i = 0; i < n; i++) {
ll ans = query(0, 0, n, 0, h[i] - 1);
ll diff = dp[h[i]];
dp[h[i]] = ans + a[i];
update(0, 0, n, h[i], dp[h[i]] - diff);
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, dp[h[i]]);
}
cout << ans << endl;
}
} | /* * * * * * * * * * * **
* *
* saurabh8522 *
* I will handle *
* IT. *
* *
* * * * * * * * * * * **/
#include <bits/stdc++.h>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a), 0, sizeof((a)))
#define one(a) memset((a), 1, sizeof((a)))
#define minus(a) memset((a), -1, sizeof((a)))
#define all(g) g.begin(), g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
ll numdigit(ll n) { return floor(log10(n)) + 1; }
bool isPowerTwo(ll x) { return x && (!(x & (x - 1))); }
ll seg[900005];
ll dp[500005];
void build(ll node, ll s, ll e) {
// cout<<node<<" "<<s<<" "<<e<<endl;
if (s == e) {
seg[node] = dp[s];
return;
}
ll mid = (s + e) >> 1;
build(2 * node + 1, s, mid);
build(2 * node + 2, mid + 1, e);
seg[node] = max(seg[2 * node + 1], seg[2 * node + 2]);
}
ll query(ll node, ll s, ll e, ll qs, ll qe) {
if (qs <= s && qe >= e) {
return seg[node];
}
if (qe < s || qs > e) {
return 0;
}
ll mid = (s + e) >> 1;
return max(query(2 * node + 1, s, mid, qs, qe),
query(2 * node + 2, mid + 1, e, qs, qe));
}
void update(ll node, ll s, ll e, ll index, ll val) {
if (s == e) {
seg[node] += val;
return;
}
ll mid = (s + e) >> 1;
if (index <= mid && index >= s) {
update(2 * node + 1, s, mid, index, val);
} else {
update(2 * node + 2, mid + 1, e, index, val);
}
seg[node] = max(seg[2 * node + 1], seg[2 * node + 2]);
}
int main() {
// FastRead;
ll t = 1;
// cin>>t;
while (t--) {
ll n;
cin >> n;
vector<ll> h(n), a(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// ll dp[n+1];
zero(dp);
build(0, 0, n);
// cout<<0<<endl;
for (int i = 0; i < n; i++) {
ll ans = query(0, 0, n, 0, h[i] - 1);
ll diff = dp[h[i]];
dp[h[i]] = ans + a[i];
update(0, 0, n, h[i], dp[h[i]] - diff);
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, dp[h[i]]);
}
cout << ans << endl;
}
} | replace | 47 | 48 | 47 | 48 | 0 | |
p03176 | C++ | Time Limit Exceeded | /*
JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<lli, lli>
#define vi vector<lli>
#define mii map<lli, lli>
#define pqb priority_queue<lli>
#define pqs priority_queue<lli, vi, greater<lli>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
lli x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void zanj0() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const lli N = 2e5 + 10;
const lli offset = 6;
lli BIT[N + 10];
void update(lli idx, lli val) {
while (idx < N) {
BIT[idx] = max(BIT[idx], val);
idx += (idx & (-idx));
}
}
lli query(lli idx) {
lli ret = 0;
while (idx > 0) {
ret = max(BIT[idx], ret);
idx -= (idx & (-idx));
}
return ret;
}
void solve() {
lli n;
cin >> n;
lli ret = 0;
vi dp(n + 1);
vi val(n);
vi h(n);
for (lli i = 0; i < n; i++) {
cin >> h[i];
}
for (lli i = 0; i < n; i++) {
cin >> val[i];
}
for (lli i = 0; i < n; i++) {
for (lli j = 0; j < h[i]; j++) {
dp[h[i]] = val[i] + query(offset + h[i] - 1);
ret = max(dp[h[i]], ret);
update(offset + h[i], dp[h[i]]);
}
}
cout << ret << endl;
}
int main() {
zanj0();
solve();
return 0;
} | /*
JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<lli, lli>
#define vi vector<lli>
#define mii map<lli, lli>
#define pqb priority_queue<lli>
#define pqs priority_queue<lli, vi, greater<lli>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
lli x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void zanj0() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const lli N = 2e5 + 10;
const lli offset = 6;
lli BIT[N + 10];
void update(lli idx, lli val) {
while (idx < N) {
BIT[idx] = max(BIT[idx], val);
idx += (idx & (-idx));
}
}
lli query(lli idx) {
lli ret = 0;
while (idx > 0) {
ret = max(BIT[idx], ret);
idx -= (idx & (-idx));
}
return ret;
}
void solve() {
lli n;
cin >> n;
lli ret = 0;
vi dp(n + 1);
vi val(n);
vi h(n);
for (lli i = 0; i < n; i++) {
cin >> h[i];
}
for (lli i = 0; i < n; i++) {
cin >> val[i];
}
for (lli i = 0; i < n; i++) {
dp[h[i]] = val[i] + query(offset + h[i] - 1);
ret = max(dp[h[i]], ret);
update(offset + h[i], dp[h[i]]);
}
cout << ret << endl;
}
int main() {
zanj0();
solve();
return 0;
} | replace | 72 | 77 | 72 | 76 | TLE | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long int N = 200000;
long long int dp[N + 1], h[N + 1], v[N + 1], bit[N + 1];
long long int sgtr[4 * N + 5];
int n;
void update(int s, int e, int node, int i, long long int y) {
if (i < s || i > e)
return;
if (s == e && s == i) {
sgtr[node] = y;
return;
}
long long int mid = (s + e) / 2;
if (i <= mid)
update(s, mid, 2 * node + 1, i, y);
else
update(mid + 1, e, 2 * node + 2, i, y);
sgtr[node] = max(sgtr[2 * node + 1], sgtr[2 * node + 2]);
return;
}
long long int query(int s, int e, int node, int i, int j) {
if (s >= i && e <= j)
return sgtr[node];
if (e < i || s > j)
return -1;
long long int mid = (s + e) / 2;
long long int ans1 = query(s, mid, 2 * node + 1, i, j);
long long int ans2 = query(mid + 1, e, 2 * node + 2, i, j);
return max(ans1, ans2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
freopen("intt.txt", "r", stdin);
freopen("outt.txt", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= n; i++) {
if (h[i] != 1)
dp[h[i]] = query(1, n, 0, 1, h[i] - 1);
dp[h[i]] += v[i];
update(1, n, 0, h[i], dp[h[i]]);
}
long long int ans = 0;
for (long long int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long int N = 200000;
long long int dp[N + 1], h[N + 1], v[N + 1], bit[N + 1];
long long int sgtr[4 * N + 5];
int n;
void update(int s, int e, int node, int i, long long int y) {
if (i < s || i > e)
return;
if (s == e && s == i) {
sgtr[node] = y;
return;
}
long long int mid = (s + e) / 2;
if (i <= mid)
update(s, mid, 2 * node + 1, i, y);
else
update(mid + 1, e, 2 * node + 2, i, y);
sgtr[node] = max(sgtr[2 * node + 1], sgtr[2 * node + 2]);
return;
}
long long int query(int s, int e, int node, int i, int j) {
if (s >= i && e <= j)
return sgtr[node];
if (e < i || s > j)
return -1;
long long int mid = (s + e) / 2;
long long int ans1 = query(s, mid, 2 * node + 1, i, j);
long long int ans2 = query(mid + 1, e, 2 * node + 2, i, j);
return max(ans1, ans2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= n; i++) {
if (h[i] != 1)
dp[h[i]] = query(1, n, 0, 1, h[i] - 1);
dp[h[i]] += v[i];
update(1, n, 0, h[i], dp[h[i]]);
}
long long int ans = 0;
for (long long int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
} | delete | 35 | 39 | 35 | 35 | 0 | |
p03176 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <typename T> void vprint(T &v) {
REP(i, v.size()) { cout << v[i] << " "; }
cout << endl;
}
typedef ll V;
typedef pair<V, V> pVV;
const V INF_V = LLONG_MAX;
const int ME = 17;
const int N = 1 << ME;
class RMQ_segtree {
public:
pVV dat[2 * N - 1];
RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = make_pair(INF_V, -1); }
void update(int k, V a) {
// k็ช็ฎใฎ่ฆ็ด ใaใซๅคๆด
k += N - 1;
dat[k] = make_pair(a, k - (N - 1));
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
pVV recursion(int a, int b, int k, int l, int r) {
// ๆๅฐๅค่จ็ฎ็จใฎๅๅธฐ้ขๆฐ
if (r <= a || b <= l)
return make_pair(INF_V, -1);
if (a <= l && r <= b)
return dat[k];
else {
pVV vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
pVV vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
pVV minimum(int a, int b) {
// ๅบ้[a, b)ใฎๆๅฐๅค
return recursion(a, b, 0, 0, N);
}
void print_val(int a, int b) {
// ๅบ้[a, b)ใฎๅคใๅบๅ
for (int i = a; i < b; i++)
cout << dat[i + N - 1].first << endl;
cout << endl;
}
};
int main() {
ll N;
cin >> N;
vector<ll> h(N), a(N);
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
vector<pll> x(N);
REP(i, N) x[i].first = h[i], x[i].second = i;
sort(x.begin(), x.end());
RMQ_segtree rs;
REP(i, N) {
ll tmp;
if (x[i].second == 0)
tmp = 0;
else
tmp = -rs.minimum(0, x[i].second).first;
if (tmp == -INF_V)
tmp = 0;
rs.update(x[i].second, -tmp - a[x[i].second]);
}
ll res = -1;
REP(i, N) res = max(res, -rs.minimum(i, i + 1).first);
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <typename T> void vprint(T &v) {
REP(i, v.size()) { cout << v[i] << " "; }
cout << endl;
}
typedef ll V;
typedef pair<V, V> pVV;
const V INF_V = LLONG_MAX;
const int ME = 18;
const int N = 1 << ME;
class RMQ_segtree {
public:
pVV dat[2 * N - 1];
RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = make_pair(INF_V, -1); }
void update(int k, V a) {
// k็ช็ฎใฎ่ฆ็ด ใaใซๅคๆด
k += N - 1;
dat[k] = make_pair(a, k - (N - 1));
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
pVV recursion(int a, int b, int k, int l, int r) {
// ๆๅฐๅค่จ็ฎ็จใฎๅๅธฐ้ขๆฐ
if (r <= a || b <= l)
return make_pair(INF_V, -1);
if (a <= l && r <= b)
return dat[k];
else {
pVV vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
pVV vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
pVV minimum(int a, int b) {
// ๅบ้[a, b)ใฎๆๅฐๅค
return recursion(a, b, 0, 0, N);
}
void print_val(int a, int b) {
// ๅบ้[a, b)ใฎๅคใๅบๅ
for (int i = a; i < b; i++)
cout << dat[i + N - 1].first << endl;
cout << endl;
}
};
int main() {
ll N;
cin >> N;
vector<ll> h(N), a(N);
REP(i, N) cin >> h[i];
REP(i, N) cin >> a[i];
vector<pll> x(N);
REP(i, N) x[i].first = h[i], x[i].second = i;
sort(x.begin(), x.end());
RMQ_segtree rs;
REP(i, N) {
ll tmp;
if (x[i].second == 0)
tmp = 0;
else
tmp = -rs.minimum(0, x[i].second).first;
if (tmp == -INF_V)
tmp = 0;
rs.update(x[i].second, -tmp - a[x[i].second]);
}
ll res = -1;
REP(i, N) res = max(res, -rs.minimum(i, i + 1).first);
cout << res << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.