QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#448580 | #6857. Easy problem II | kkkgjyismine4 | AC ✓ | 1784ms | 4668kb | C++23 | 1.3kb | 2024-06-19 19:53:17 | 2024-06-19 19:53:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100005];
int n,q;
void solve(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
while(q--){
int op;scanf("%d",&op);
if(op&1){
int l,r;ll x;
scanf("%d%d%lld",&l,&r,&x);
int p=r;while(p%8!=l%8)--p;
if(r-l+1<=20)for(int i=l;i<=r;++i)a[i]=((a[i]<x)?(x-a[i]):(x+a[i]));
else{
for(int i=l;i<p;i+=8){
a[i]=((a[i]<x)?(x-a[i]):(x+a[i]));
a[i+1]=((a[i+1]<x)?(x-a[i+1]):(x+a[i+1]));
a[i+2]=((a[i+2]<x)?(x-a[i+2]):(x+a[i+2]));
a[i+3]=((a[i+3]<x)?(x-a[i+3]):(x+a[i+3]));
a[i+4]=((a[i+4]<x)?(x-a[i+4]):(x+a[i+4]));
a[i+5]=((a[i+5]<x)?(x-a[i+5]):(x+a[i+5]));
a[i+6]=((a[i+6]<x)?(x-a[i+6]):(x+a[i+6]));
a[i+7]=((a[i+7]<x)?(x-a[i+7]):(x+a[i+7]));
}
for(int i=p;i<=r;++i)a[i]=((a[i]<x)?(x-a[i]):(x+a[i]));
}
}else{
int l,r,p;scanf("%d%d",&l,&r);ll s=0,s0=0,s1=0,s2=0,s3=0,s4=0,s5=0,s6=0,s7=0;
if(r-l+1<=20)for(int i=l;i<=r;++i)s+=a[i];
else{
p=r;while(p%8!=l%8)--p;
for(int i=l;i<p;i+=8)s0+=a[i],s1+=a[i+1],s2+=a[i+2],s3+=a[i+3],s4+=a[i+4],s5+=a[i+5],s6+=a[i+6],s7+=a[i+7];
for(int i=p;i<=r;++i)s+=a[i];
}
s+=s0+s1+s2+s3+s4+s5+s6+s7;
printf("%lld\n",s);
}
}
}
int main(){
int T;cin>>T;
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1784ms
memory: 4668kb
input:
1 100000 100000 9994250 1 9999152 1 9996205 1 9993920 1 9992936 1 9999312 1 9994863 1 9999950 1 9994702 1 9998302 1 9997460 1 9995584 1 9990858 1 9995764 1 9992400 1 9992970 1 9993486 1 9992200 1 9991250 1 9990336 1 9994212 1 9992704 1 9999400 1 9994826 1 9996272 1 9995920 1 9994960 1 9996400 1 9990...
output:
474104664177 469903014249 480933011291 483822399944 484396591822 485195157450 476873328231 500050522935 490495899612 455001143708 459350186600 463088605817 452789422852 457530804729 478921256445 483860248443 460953094343 461203887676 471567676461 499102979676 483610787357 490750641096 468023668995 4...
result:
ok 85563 lines