QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#564243 | #3850. DJ Darko | Fortitude# | WA | 470ms | 39476kb | C++23 | 4.2kb | 2024-09-14 21:27:14 | 2024-09-14 21:27:14 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define int long long
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int N = 2e5 + 5;
const ll inf = 1e18;
int n, q;
ll a[N], b[N], t[N * 4], lz1[N * 4], lz2[N * 4];
ll p[N];
void push(int v) {
if (lz2[v]) {
lz2[2 * v] += lz2[v];
lz2[2 * v + 1] += lz2[v];
t[2 * v] += lz2[v];
t[2 * v + 1] += lz2[v];
lz2[v] = 0;
}
if (lz1[v] != -inf) {
lz1[2 * v] = lz1[2 * v + 1] = lz1[v];
lz1[v] = -inf;
}
}
void assign(int l, int r, ll x, int v = 1, int tl = 1, int tr = n) {
if (l > tr || r < tl)
return;
if (l <= tl && tr <= r) {
t[v] = x;
lz1[v] = x;
return;
}
int tm = (tl + tr) / 2;
push(v);
assign(l, r, x, v * 2, tl, tm);
assign(l, r, x, v * 2 + 1, tm + 1, tr);
}
void add(int l, int r, int x, int v = 1, int tl = 1, int tr = n) {
if (l > tr || r < tl)
return;
if (l <= tl && tr <= r) {
t[v] += x;
if (lz1[v] != -inf)
lz1[v] += x;
else lz2[v] += x;
return;
}
int tm = (tl + tr) / 2;
push(v);
add(l, r, x, v * 2, tl, tm);
add(l, r, x, v * 2 + 1, tm + 1, tr);
}
ll get(int x, int v = 1, int tl = 1, int tr = n) {
if (tl == tr)
return t[v];
int tm = (tl + tr) / 2;
push(v);
if (x <= tm)
return get(x, v * 2, tl, tm);
return get(x, v * 2 + 1, tm + 1, tr);
}
main() {
ios :: sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q;
for (int i = 1; i <= 4 * n; ++i)
lz1[i] = -inf;
set <pii> st;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
assign(i, i, a[i]);
st.insert({i, i});
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
p[i] = p[i - 1] + b[i];
}
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int l, r, x;
cin >> l >> r >> x;
auto lb = st.lower_bound({l, 0});
auto rb = st.lower_bound({r + 1, 0});
rb--;
bool flag = 0;
if (lb != st.begin()) {
--lb;
flag = (lb == rb);
++lb;
}
if (flag) {
lb--;
auto [L, R] = *lb;
st.erase(lb);
if (L < l)
st.insert({L, l - 1});
if (r < R)
st.insert({r + 1, R});
st.insert({l, r});
}
else {
if (lb != st.begin()) {
lb--;
if (lb -> s >= l) {
auto [L, R] = *lb;
//[lb -> f, l - 1]
//[l, lb -> s]
st.erase(lb);
st.insert({l, R});
if (L < l) st.insert({L, l - 1});
}
}
rb = st.lower_bound({r + 1, 0});
rb--;
auto [L, R] = *rb;
st.erase(rb);
st.insert({L, r});
if (r < R)
st.insert({r + 1, R});
}
add(l, r, x);
}
else {
int l, r;
cin >> l >> r;
vector <pii> vec;
vector <ll> vals;
{
auto lb = st.lower_bound({l, 0});
auto rb = st.lower_bound({r + 1, 0});
rb--;
bool flag = 0;
if (lb != st.begin()) {
--lb;
flag = (lb == rb);
++lb;
}
if (flag) {
--lb;
auto [L, R] = *lb;
st.erase(lb);
if (L < l)
st.insert({L, l - 1});
if (r < R)
st.insert({r + 1, R});
}
else {
if (lb != st.begin()) {
lb--;
if (lb -> s >= l) {
auto [L, R] = *lb;
//[lb -> f, l - 1]
//[l, lb -> s]
vec.pb({l, R});
st.erase(lb);
if (L < l) st.insert({L, l - 1});
}
}
rb = st.lower_bound({r + 1, 0});
rb--;
auto [L, R] = *rb;
vec.pb({L, r});
st.erase(rb);
if (r < R)
st.insert({r + 1, R});
}
}
auto lb = st.lower_bound({l, 0});
while (lb != st.end() && lb -> s <= r) {
vec.pb(*lb);
lb = st.erase(lb);
}
st.insert({l, r});
ll tot = p[r] - p[l - 1];
for (auto [i, j] : vec) {
vals.pb(get(i));
}
vector <int> order;
for (int i = 0; i < sz(vec); ++i)
order.pb(i);
sort(all(order), [&] (int x, int y) {
return vals[x] < vals[y];
});
ll cur = 0, x = 0;
for (auto i : order) {
auto [L, R] = vec[i];
cur += p[R] - p[L - 1];
if (cur >= (tot + 1) / 2) {
x = vals[i];
break;
}
}
cout << x << '\n';
assign(l, r, x);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 470ms
memory: 39476kb
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1648748099 467651597 1201433969 0 1201433969 307214679 0 0 -893932302 -205760183 1037671081 434152109 434152109 341489249 0 934836539 0 934836539 -1544433150 248705236 0 -839878190 1286550580 -300044631 1542474117 965553489 0 -611960024 0 0 0 -295499765 0 0 0 0 0 660681641 33667...
result:
wrong answer 3rd lines differ - expected: '1749348519', found: '1648748099'