QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#631192 | #8286. Stacks | wangjunrui | WA | 11ms | 15768kb | C++14 | 4.0kb | 2024-10-11 22:44:51 | 2024-10-11 22:44:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e5 + 5;
int n, m;
struct Tree
{
int lc, rc;
int x, y;
ll sumx, sumy;
} tree[34000005];
#define lc(rt) tree[rt].lc
#define rc(rt) tree[rt].rc
int cnt;
mt19937 rnd(114514);
inline int newnode(int x, int y)
{
int rt = ++cnt;
lc(rt) = rc(rt) = 0;
tree[rt].x = x;
tree[rt].y = y;
tree[rt].sumx = tree[rt].x;
tree[rt].sumy = (ll)tree[rt].x * tree[rt].y;
return rt;
}
inline void pushup(int rt)
{
tree[rt].sumx = tree[rt].x + tree[lc(rt)].sumx + tree[rc(rt)].sumx;
tree[rt].sumy = (ll)tree[rt].x * tree[rt].y + tree[lc(rt)].sumy + tree[rc(rt)].sumy;
}
inline int split(int rt, ll k)
{
tree[++cnt] = tree[rt];
rt = cnt;
if (tree[rc(rt)].sumx > k)
{
rc(rt) = split(rc(rt), k);
pushup(rt);
return rt;
}
else if (tree[rc(rt)].sumx + tree[rt].x > k)
{
tree[rt].x -= (int)(k - tree[rc(rt)].sumx);
rc(rt) = 0;
pushup(rt);
return rt;
}
else
{
--cnt;
return split(lc(rt), k - tree[rc(rt)].sumx - tree[rt].x);
}
}
inline int merge(int x, int y)
{
if (!x || !y)
return x | y;
int rt = ++cnt;
if (rnd() & 1)
{
tree[rt] = tree[x];
rc(rt) = merge(rc(rt), y);
}
else
{
tree[rt] = tree[y];
lc(rt) = merge(x, lc(y));
}
pushup(rt);
return rt;
}
inline ll query(int rt, ll k_th)
{
ll res = 0;
while (rt)
{
if (k_th < tree[lc(rt)].sumx)
rt = lc(rt);
else if (k_th <= tree[lc(rt)].sumx + tree[rt].x)
return res + tree[lc(rt)].sumy + (k_th - tree[lc(rt)].sumx) * tree[rt].y;
else
{
res += tree[lc(rt)].sumy + (ll)tree[rt].x * tree[rt].y;
k_th -= tree[lc(rt)].sumx + tree[rt].x;
rt = rc(rt);
}
}
return res;
}
inline void print(int rt)
{
if (!rt)
return;
print(lc(rt));
printf("(%d,%d)\n",tree[rt].x, tree[rt].y);
print(rc(rt));
}
#undef lc
#undef rc
struct
{
int root;
ll del;
inline void update(ll val)
{
if (tree[root].sumx > val)
split(root, val);
else
{
val -= tree[root].sumx;
del += val;
root = 0;
}
}
inline void add(int x, int y)
{
root = ::merge(root, newnode(x, y));
}
inline void merge(int x)
{
root = ::merge(root, x);
}
inline ll query(ll x, ll y)
{
ll res = ::query(root, y);
if (x > 1)
res -= ::query(root, x - 1);
return res;
}
inline void print()
{
::print(root);
putchar('\n');
}
} seg[N * 4];
#define lc (rt << 1)
#define rc (rt << 1 | 1)
inline void pushdown(int rt)
{
if (seg[rt].del)
{
seg[lc].update(seg[rt].del);
seg[rc].update(seg[rt].del);
seg[rt].del = 0;
}
if (seg[rt].root)
{
seg[lc].merge(seg[rt].root);
seg[rc].merge(seg[rt].root);
seg[rt].root = 0;
}
}
inline void update(int rt, int l, int r, int x, int y, int v1, int v2)
{
if (r < x || l > y)
return;
if (x <= l && r <= y)
{
seg[rt].add(v1, v2);
return;
}
int mid = (l + r) >> 1;
pushdown(rt);
update(lc, l, mid, x, y, v1, v2);
update(rc, mid + 1, r, x, y, v1, v2);
}
inline void update(int rt, int l, int r, int x, int y, ll w)
{
if (r < x || l > y)
return;
if (x <= l && r <= y)
{
seg[rt].update(w);
return;
}
int mid = (l + r) >> 1;
pushdown(rt);
update(lc, l, mid, x, y, w);
update(rc, mid + 1, r, x, y, w);
}
inline ll query(int rt, int l, int r, int pos, ll p, ll q)
{
if (l == r)
return seg[rt].query(p, q);
int mid = (l + r) >> 1;
pushdown(rt);
if (pos <= mid)
return query(lc, l, mid, pos, p, q);
else
return query(rc, mid + 1, r, pos, p, q);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int opt;
cin >> opt;
if (opt == 1)
{
int l, r, x, y;
cin >> l >> r >> x >> y;
update(1, 1, n, l, r, x, y);
}
else if (opt == 2)
{
int l, r;
ll w;
cin >> l >> r >> w;
update(1, 1, n, l, r, w);
}
else
{
int k;
ll p, q;
cin >> k >> p >> q;
cout << query(1, 1, n, k, p, q) << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 15768kb
input:
4907 4910 2 763 3330 1 3 307 1 1 1 2262 3430 22699 89397 1 1915 4000 51541 67587 2 212 2990 9763 2 1086 2162 1 2 1813 4496 16760 1 51 2796 68005 99390 1 1267 1519 74236 66178 3 1768 23808 54314 2 900 4122 27758 3 3287 17350 28989 2 3277 4024 3633 2 444 4866 1 2 353 4219 1061 1 987 3141 99906 17320 2...
output:
0 3032090730 903396180 471569175 200648623 98486697 2242691487 123945 50793012 61782451 0 0 0 762429740 33465150 646227215 1157755425 8289071627 0 1792521566 6640518748 2415375780 145073491 283261500 5250788038 1937313768 612473394 0 118545795 2879949344 5978740326 18162074 1232466642 3339759123 822...
result:
wrong answer 7th numbers differ - expected: '647114751', found: '2242691487'