QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#320691 | #3850. DJ Darko | PetroTarnavskyi# | WA | 387ms | 22396kb | C++20 | 2.7kb | 2024-02-03 20:06:20 | 2024-02-03 20:06:20 |
Judging History
answer
#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 = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;
const LL LINF = 1e18;
struct Segtree
{
int n;
vector<PLL> t;
void init(int _n)
{
n = 1;
while (n < _n) n *= 2;
t.assign(n * 2 - 1, {LINF, 0});
}
void push(int v, int tl, int tr)
{
if (tl + 1 == tr) return;
if (t[v].F != LINF)
{
t[v * 2 + 1] = {t[v].F, 0};
t[v * 2 + 2] = {t[v].F, 0};
}
t[v * 2 + 1].S += t[v].S;
t[v * 2 + 2].S += t[v].S;
t[v] = {LINF, 0};
}
LL query(int v, int tl, int tr, int i)
{
push(v, tl, tr);
if (tl + 1 == tr)
{
return t[v].F + t[v].S;
}
int tm = (tl + tr) / 2;
if (tm > i)
return query(v * 2 + 1, tl, tm, i);
else
return query(v * 2 + 2, tm, tr, i);
}
LL query(int i)
{
return query(0, 0, n, i);
}
void upd(int v, int tl, int tr, int l, int r, PLL x)
{
push(v, tl, tr);
if (tl >= r || l >= tr)
return;
if (l <= tl && tr <= r)
{
t[v] = x;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
upd(v * 2 + 1, tl, tm, l, r, x);
upd(v * 2 + 2, tm, tr, l, r, x);
}
void upd(int l, int r, PLL x)
{
return upd(0, 0, n, l, r, x);
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
Segtree st;
st.init(n);
set<int> pos;
FOR (i, 0, n)
{
int a;
cin >> a;
st.upd(i, i + 1, {a, 0});
pos.insert(i);
}
pos.insert(n);
vector<LL> b(n + 1);
FOR (i, 0, n)
{
cin >> b[i + 1];
b[i + 1] += b[i];
}
FOR (iter, 0, q)
{
int t;
cin >> t;
if (t == 1)
{
int l, r, x;
cin >> l >> r >> x;
l--;
pos.insert(l);
pos.insert(r);
st.upd(l, r, {LINF, x});
}
else
{
int l, r;
cin >> l >> r;
l--;
pos.insert(l);
pos.insert(r);
vector<PLL> v;
auto it = pos.lower_bound(l);
while (*it != r)
{
int ps = *it;
LL x = st.query(ps);
it++;
pos.erase(prev(it));
v.PB({x, b[*it] - b[ps]});
}
pos.insert(l);
sort(ALL(v));
__int128 sum = 0;
FOR (i, 0, SZ(v))
sum += v[i].S;
__int128 pref = 0;
int j = -1;
FOR (i, 0, SZ(v))
{
pref += v[i].S;
if (pref * 2 >= sum)
{
j = i;
break;
}
}
st.upd(l, r, {v[j].F, 0});
cout << v[j].F << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 387ms
memory: 22396kb
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 999999999044265113 999999999044265113 1749348519 1203955356 873765076 999999999044265113 -893909271 449782566 449782566 1244771841 1244771841 998933504 998933504 998933504 998933504 998933504 449782566 746961328 746961328 746961328 -4043317 658443927 6584439...
result:
wrong answer 5th lines differ - expected: '874061694', found: '999999999044265113'