ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199583 | #3465. 溢出 | Williamtank | 100 | 4134ms | 22320kb | C++ | 2.3kb | 2023-12-17 10:32:09 | 2023-12-17 12:31:05 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
const int mod = 65536;
struct Segment_tree
{
long long a[300005];
int cnt;
struct node
{
long long sum,lazy,mx;
int lson,rson;
}tree[600005];
void push_up(int k1)
{
tree[k1].mx = max(tree[tree[k1].lson].mx,tree[tree[k1].rson].mx);
tree[k1].sum = tree[tree[k1].lson].sum + tree[tree[k1].rson].sum;
}
void build_tree(int &k1,int l,int r)
{
k1 = ++cnt;
if(l == r)
{
tree[k1].sum = a[l];
tree[k1].mx = a[l];
return;
}
int mid = (l + r) / 2;
build_tree(tree[k1].lson,l,mid);
build_tree(tree[k1].rson,mid + 1,r);
push_up(k1);
}
void pushdown(int k1,int l,int r)
{
int mid = (l + r) >> 1;
tree[tree[k1].lson].lazy += tree[k1].lazy;
tree[tree[k1].rson].lazy += tree[k1].lazy;
tree[tree[k1].lson].sum += (mid - l + 1) * tree[k1].lazy;
tree[tree[k1].rson].sum += (r - mid) * tree[k1].lazy;
tree[tree[k1].lson].mx += tree[k1].lazy;
tree[tree[k1].rson].mx += tree[k1].lazy;
tree[k1].lazy = 0;
}
void update(int k1,int l,int r,int x,int y)
{
if(l == r)
{
tree[k1].sum = (tree[k1].sum + 1) % mod;
tree[k1].mx = tree[k1].sum;
tree[k1].lazy++;
return;
}
if(x <= l && r <= y && tree[k1].mx < mod - 1)
{
tree[k1].sum += (r - l + 1);
tree[k1].mx++;
tree[k1].lazy++;
return;
}
pushdown(k1,l,r);
int mid = (l + r) >> 1;
if(x <= mid) update(tree[k1].lson,l,mid,x,y);
if(y > mid) update(tree[k1].rson,mid + 1,r,x,y);
push_up(k1);
}
long long query(int k1,int l,int r,int x,int y)
{
if(l == r)
{
tree[k1].sum %= mod;
tree[k1].mx = tree[k1].sum;
return tree[k1].sum;
}
if(x <= l && r <= y && tree[k1].mx < mod) return tree[k1].sum;
pushdown(k1,l,r);
int mid = (l + r) >> 1;
long long ans = 0;
if(x <= mid) ans += query(tree[k1].lson,l,mid,x,y);
if(y > mid) ans += query(tree[k1].rson,mid + 1,r,x,y);
push_up(k1);
return ans;
}
}t;
signed main()
{
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++) scanf("%lld",&t.a[i]);
t.build_tree(t.tree[0].lson,1,n);
for(int i = 1;i <= m;i++)
{
int opt;
scanf("%d",&opt);
if(opt == 1)
{
int x,y;
scanf("%d%d",&x,&y);
t.update(1,1,n,x,y);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
printf("%lld\n",t.query(1,1,n,x,y));
}
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1296kb
input:
1000 1000 61576 59819 63827 52493 63291 60915 65358 62268 65008 63164 45814 58894 55671 56825 55222 ...
output:
47391593 34359271 29992831 48733353 53858504 15167240 14652013 20486602 10677918 6960200 23980435 20...
result:
ok 538 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
1000 1000 58743 55361 56832 62554 56874 53925 57237 62848 44882 59390 62089 60721 60979 57789 63083 ...
output:
24936138 51869537 16598172 34942973 5025581 47216015 4485417 5307792 36942213 19468763 17248829 2320...
result:
ok 500 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
1000 1000 62264 62899 63939 59973 61635 64264 63889 63950 64346 61465 60818 64246 62135 65156 65436 ...
output:
42257680 56802301 14037524 1196438 33516278 15882551 36593268 28623755 9133780 4545864 5854607 10110...
result:
ok 480 lines
Test #4:
score: 10
Accepted
time: 479ms
memory: 22320kb
input:
300000 300000 2 0 0 2 2 1 1 2 0 1 1 0 0 1 2 1 1 1 1 1 1 1 3 2 0 2 0 0 1 3 3 3 3 0 3 3 2 3 3 1 0 2 0 ...
output:
77770 6872 76328 61289 334908 73097 90045 57319 193720 271754 69798 264955 292541 103338 226353 1603...
result:
ok 299844 lines
Test #5:
score: 10
Accepted
time: 496ms
memory: 22320kb
input:
300000 300000 2 0 2 0 0 1 0 2 0 3 1 0 3 2 1 2 3 3 3 1 1 3 0 2 1 2 1 1 2 1 1 2 3 1 0 3 0 2 1 0 1 0 1 ...
output:
80361 244935 150097 185766 185499 132215 37494 699 197579 89432 64053 40361 62357 165316 409428 7235...
result:
ok 299850 lines
Test #6:
score: 10
Accepted
time: 471ms
memory: 22316kb
input:
300000 300000 2 1 3 1 1 2 3 2 3 1 0 0 1 3 0 3 2 1 1 2 2 1 1 1 2 2 2 2 2 3 3 0 2 1 1 3 1 0 2 2 1 3 2 ...
output:
147459 59401 287994 221547 178450 22559 85012 18675 171371 51521 84236 81989 82857 24046 173366 2095...
result:
ok 299870 lines
Test #7:
score: 10
Accepted
time: 681ms
memory: 22316kb
input:
300000 300000 64800 53910 64302 57829 64374 63424 61356 56786 40619 60635 56460 63399 64701 53037 64...
output:
14248019041 3882040700 3103625760 4943694162 9399085294 1164026020 9930712611 1468776070 2088235010 ...
result:
ok 37621 lines
Test #8:
score: 10
Accepted
time: 689ms
memory: 22316kb
input:
300000 300000 58778 62563 63573 56832 64984 60371 59791 52946 56711 62979 65085 60603 60388 65194 60...
output:
5901553012 8284973183 4444109287 3337554830 4630377224 10185546517 4654491227 887988717 15369908102 ...
result:
ok 37244 lines
Test #9:
score: 10
Accepted
time: 675ms
memory: 22312kb
input:
300000 300000 59813 52406 63572 58696 59295 63928 63792 60345 64593 62744 63812 61102 62928 61215 57...
output:
2526542608 1074980588 277083967 1661587715 5819569552 2707082816 785032093 7475197732 7155000134 127...
result:
ok 37421 lines
Test #10:
score: 10
Accepted
time: 642ms
memory: 22316kb
input:
300000 300000 61277 62385 54945 62893 62499 62140 57402 55684 62976 56944 64529 60761 59051 61069 62...
output:
5579176474 2662273121 3896601691 5736018020 556922562 4457659512 11621493902 10897401191 12703761686...
result:
ok 37527 lines
Extra Test:
score: 0
Extra Test Passed