QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564254 | #3850. DJ Darko | Fortitude | WA | 411ms | 39528kb | C++23 | 4.3kb | 2024-09-14 21:31:40 | 2024-09-14 21:31:41 |
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) {
assert(!lz2[v] || lz1[v] == -inf);
if (lz2[v]) {
lz2[2 * v] += lz2[v];
lz2[2 * v + 1] += lz2[v];
lz1[2 * v] = lz1[2 * v + 1] = -inf;
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];
lz2[2 * v] = lz2[2 * v + 1] = 0;
t[v * 2] = t[v * 2 + 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;
lz2[v] = 0;
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 411ms
memory: 39528kb
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 1749348519 467651597 874061694 0 874061694 874061694 0 0 -893932302 -423982510 -423982510 333555864 333555864 333555864 0 0 0 0 -423982510 -251972176 0 -251972176 1428518677 298425491 298425491 298425491 0 -313534533 0 0 0 0 0 0 0 0 0 -894055877 -894055877 0 -444736294 208897940...
result:
wrong answer 6th lines differ - expected: '874061694', found: '0'