ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199496 | #3465. 溢出 | LDM0116 | 100 | 2491ms | 28848kb | C++ | 2.6kb | 2023-12-17 09:20:14 | 2023-12-17 12:08:17 |
answer
#include<bits/stdc++.h>
#define ll long long
#define gc() (p1==p2&&(p2=(p1=b)+fread(b,1,n,stdin),p1==p2)?EOF:*p1++)
using namespace std;
namespace r{
const int n=1000000;
char *p1,*p2,b[n];
inline int read(){
int x=0,f=1;
char c=gc();
while(!isdigit(c)){
if(c==45) f=-1;
c=gc();
}
while(isdigit(c)){
x=(x<<1)+(x<<3)+c-'0';
c=gc();
}
return x*f;
}
}
using namespace r;
namespace w{
const int s=1000000;
char b[s];
int cnt=0;
inline void write(ll x){
if(x<0){
x=-x;
b[cnt++]=45;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
if(x>9) write(x/10);
b[cnt++]=(x%10)|48;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void space(){
b[cnt++]=' ';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void endl(){
b[cnt++]='\n';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void show(){
if(cnt) fwrite(b,1,cnt,stdout),cnt=0;
}
}
using namespace w;
namespace ldm{
int n,q,v[300001];
ll ans;
struct node{
ll v,maxx,lt;
}a[1200001];
inline void pushup(int x){
a[x].v=a[x<<1].v+a[x<<1|1].v;
a[x].maxx=max(a[x<<1].maxx,a[x<<1|1].maxx);
}
inline void pushdown(int x,int l,int r){
int mid=(l+r)>>1;
if(a[x].lt){
a[x<<1].lt+=a[x].lt;
a[x<<1|1].lt+=a[x].lt;
a[x<<1].maxx+=a[x].lt;
a[x<<1|1].maxx+=a[x].lt;
a[x<<1].v+=1ll*(mid-l+1)*a[x].lt;
a[x<<1|1].v+=1ll*(r-mid)*a[x].lt;
a[x].lt=0;
}
}
inline void build(int x,int l,int r){
if(l==r){
a[x].v=a[x].maxx=v[l];
return;
}
int mid=(l+r)>>1;
build(x<<1,l,mid);
build(x<<1|1,mid+1,r);
pushup(x);
}
inline void modify(int x,int l,int r,int L,int R){
if(r<L||l>R) return;
if(l==r){
a[x].v=(a[x].v+1)%65536;
a[x].maxx=a[x].v;
return;
}
if(l>=L&&r<=R){
if(a[x].maxx<65535){
a[x].maxx++;
a[x].v+=1ll*(r-l+1);
a[x].lt++;
return;
}
}
pushdown(x,l,r);
int mid=(l+r)>>1;
modify(x<<1,l,mid,L,R);
modify(x<<1|1,mid+1,r,L,R);
pushup(x);
}
inline void query(int x,int l,int r,int L,int R){
if(r<L||l>R) return;
if(l>=L&&r<=R){
ans+=a[x].v;
return;
}
pushdown(x,l,r);
int mid=(l+r)>>1;
query(x<<1,l,mid,L,R);
query(x<<1|1,mid+1,r,L,R);
pushup(x);
}
int main(){
n=read(),q=read();
for(int i=1;i<=n;i++){
v[i]=read();
}
build(1,1,n);
while(q--){
int c=read(),l=read(),r=read();
if(c==1){
modify(1,1,n,l,r);
}else{
ans=0;
query(1,1,n,l,r);
write(ans);
endl();
}
}
show();
return 0;
}
}
int main(){
ldm::main();
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1228kb
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: 1ms
memory: 1224kb
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: 1224kb
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: 240ms
memory: 28844kb
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: 252ms
memory: 28848kb
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: 240ms
memory: 28844kb
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: 460ms
memory: 28268kb
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: 433ms
memory: 28264kb
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: 424ms
memory: 28268kb
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: 441ms
memory: 28268kb
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