QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340136 | #8229. 栈 | le0n | 0 | 632ms | 338168kb | C++20 | 3.6kb | 2024-02-28 16:03:48 | 2024-02-28 16:03:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
mt19937_64 rng(114514);
const int maxn = 7e6;
struct node
{
ll cnt, sum;
node(ll cnt0 = 0, ll sum0 = 0)
{
cnt = cnt0;
sum = sum0;
}
node operator + (node n1)
{
return node(cnt + n1.cnt, sum + n1.sum);
}
};
ull rd[maxn];
int ls[maxn], rs[maxn], tot;
node val[maxn], sub[maxn];
int nd(ll x, ll y) // x 个 y
{
++tot;
ls[tot] = rs[tot] = 0;
rd[tot] = rng();
val[tot] = sub[tot] = node(x, (ll)x * y);
return tot;
}
void push_up(int p)
{
sub[p] = sub[ls[p]] + sub[rs[p]] + val[p];
}
int pre(int p, ll len)
{
if(!p || len <= 0)
return 0;
if(sub[p].cnt <= len)
return p;
assert(0);
if(len <= sub[ls[p]].cnt)
return pre(ls[p], len);
int q = ++tot;
val[q] = val[p];
rd[q] = rd[p];
if(len <= sub[ls[p]].cnt + val[p].cnt)
{
val[q].cnt = len - sub[ls[p]].cnt;
val[q].sum = val[p].sum / val[p].cnt * (len - sub[ls[p]].cnt);
}
ls[q] = ls[p];
rs[q] = pre(rs[p], len - sub[ls[p]].cnt - val[p].cnt);
push_up(q);
return q;
}
int merge(int p, int q)
{
if(!p || !q)
return p + q;
int o = ++tot;
if(rd[p] > rd[q])
{
val[o] = val[p];
rd[o] = rd[p];
ls[o] = ls[p];
rs[o] = merge(rs[p], q);
}
else
{
val[o] = val[q];
rd[o] = rd[q];
rs[o] = rs[q];
ls[o] = merge(p, ls[q]);
}
push_up(o);
return o;
}
ll qsum(int p, ll len)
{
if(!p || len <= 0)
return 0;
if(sub[p].cnt <= len)
return sub[p].sum;
if(len <= sub[ls[p]].cnt)
return qsum(ls[p], len);
if(len <= sub[ls[p]].cnt + val[p].cnt)
return sub[ls[p]].sum + val[p].sum / val[p].cnt * (len - sub[ls[p]].cnt);
return sub[ls[p]].sum + val[p].sum + qsum(rs[p], len - sub[ls[p]].cnt - val[p].cnt);
}
void print(int p)
{
if(!p)
return ;
print(ls[p]);
printf("(%lld,%lld) ", val[p].cnt, val[p].sum / val[p].cnt);
print(rs[p]);
}
struct tag
{
ll w;
int rt;
tag(ll w0 = 0, int rt0 = 0)
{
w = w0;
rt = rt0;
}
tag operator + (tag t1)
{
if(t1.w >= sub[rt].cnt)
return tag(w + t1.w - sub[rt].cnt, t1.rt);
return tag(w, merge(pre(rt, sub[rt].cnt - t1.w), t1.rt));
}
};
tag T[400005];
void f(int p, tag t)
{
T[p] = T[p] + t;
}
void push_down(int p)
{
f(p << 1, T[p]);
f(p << 1 | 1, T[p]);
T[p] = tag();
}
void upd(int p, int l, int r, int ql, int qr, tag t)
{
int mid = (l + r) >> 1;
if(ql <= l && r <= qr)
{
f(p, t);
return ;
}
push_down(p);
if(ql <= mid)
upd(p << 1, l, mid, ql, qr, t);
if(qr > mid)
upd(p << 1 | 1, mid + 1, r, ql, qr, t);
}
ll qry(int p, int l, int r, int q, ll L, ll R)
{
int mid = (l + r) >> 1;
if(l == r)
return qsum(T[p].rt, R) - qsum(T[p].rt, L - 1);
push_down(p);
if(q <= mid)
return qry(p << 1, l, mid, q, L, R);
else
return qry(p << 1 | 1, mid + 1, r, q, L, R);
}
void dfs(int p, int l, int r)
{
int mid = (l + r) >> 1;
if(l == r)
{
printf("#%d: ", l);
print(T[p].rt);
printf("\n");
return ;
}
push_down(p);
dfs(p << 1, l, mid);
dfs(p << 1 | 1, mid + 1, r);
}
int main()
{
// freopen("stack.in", "r", stdin);
// freopen("stac.out", "w", stdout);
int n, m, o, l, r;
ll x, y;
scanf("%d%d", &n, &m);
while(m--)
{
scanf("%d", &o);
if(o == 1)
{
scanf("%d%d%lld%lld", &l, &r, &x, &y);
upd(1, 1, n, l, r, tag(0, nd(x, y)));
}
if(o == 2)
{
scanf("%d%d%lld", &l, &r, &x);
upd(1, 1, n, l, r, tag(x, 0));
}
if(o == 3)
{
scanf("%d%lld%lld", &l, &x, &y);
printf("%lld\n", qry(1, 1, n, l, x, y));
}
// dfs(1, 1, n);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 632ms
memory: 338168kb
input:
99999 99998 1 5026 18575 27178 90423 3 30623 1 1 3 76936 1 1 1 77021 95683 84664 24734 1 46085 74886 40512 11266 3 5048 8594 22468 1 53318 77721 97151 70784 1 70645 91192 37556 13013 1 56752 56940 91812 62887 1 7928 34576 87339 69404 3 74875 32807 100970 3 22338 17221 25771 3 21421 20602 57957 3 717...
output:
0 0 1254619125 4366274868 593473604 2592655824 3657975552 5652513833 110091352 1226646296 1989326852 763582808 8205318671 1659086055 3012598941 20085582585 3242801176 17381308704 24555397019 4722824224 20308857160 899316516 38935050954 988382364 13341823621 11397759491 2449683584 5875277101 80572355...
result:
wrong answer 23462nd numbers differ - expected: '7801685901393', found: '7810803399182'
Subtask #3:
score: 0
Runtime Error
Test #12:
score: 0
Runtime Error
input:
100000 99993 1 47773 70467 16065 1 2 52349 78446 2304 3 40821 1 1 1 40216 93069 78144 1 1 41089 43671 76025 1 2 35263 68629 31066 3 79881 13534 57327 3 5556 1 1 2 21962 38192 1 1 664 58116 9417 1 3 28089 6039 7989 2 88500 90302 9946 3 63215 49410 60770 2 11069 89527 57581 2 70303 97603 12363 1 3420 ...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #17:
score: 0
Runtime Error
input:
99999 99996 3 77889 1 10000000000 1 6316 86327 89644 386 3 9260 1 10000000000 2 2603 47234 69717 2 20260 73011 19290 2 62477 81233 26127 1 50140 68508 37004 98794 2 14449 22788 16063 1 43860 84932 50375 21777 1 67345 94584 28202 66610 2 661 68654 1 1 14411 94422 82738 61196 1 16563 94416 4920 38408 ...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%