标签:个数 图片 long oid include iostream 暴力 print char
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define mo 998244353 5 #define LL long long 6 #define N 100007 7 using namespace std; 8 struct tree{ 9 LL s,sum1,sum2; 10 int l,r; 11 }e[N*4]; 12 int n,q,a[N]; 13 LL ans,sum; 14 15 int read(){ 16 int s=0; 17 char ch=getchar(); 18 for(;ch<‘0‘||ch>‘9‘;ch=getchar()); 19 for(;ch>=‘0‘&&ch<=‘9‘;s=s*10+ch-‘0‘,ch=getchar()); 20 return s; 21 } 22 23 inline void Build(int p,int l,int r){ 24 if (l==r){ 25 e[p].l=l,e[p].r=r; 26 e[p].s=a[l]; 27 e[p].sum1=a[l]; 28 e[p].sum2=e[p].s*e[p].s%mo; 29 return; 30 } 31 int mid=(l+r)>>1; 32 Build(p<<1,l,mid); 33 Build(p<<1|1,mid+1,r); 34 e[p].l=l; 35 e[p].r=r; 36 e[p].s=e[p<<1].s|e[p<<1|1].s; 37 e[p].sum1=e[p<<1].sum1+e[p<<1|1].sum1; 38 e[p].sum2=(e[p<<1].sum2+e[p<<1|1].sum2)%mo; 39 } 40 41 void Init(){ 42 n=read(); 43 for(int i=1;i<=n;i++) a[i]=read(); 44 Build(1,1,n); 45 q=read(); 46 } 47 48 void query(int p,int l,int r){ 49 if (e[p].l>=l&&e[p].r<=r){ 50 ans+=e[p].sum1; 51 return; 52 } 53 int mid=(e[p].l+e[p].r)>>1; 54 if (mid>=r) query(p<<1,l,r); 55 else if(mid<l) query(p<<1|1,l,r); 56 else query(p<<1,l,r),query(p<<1|1,l,r); 57 } 58 59 void update(int p,int l,int r,int x){ 60 if ((e[p].s&x)==e[p].s) return; 61 if (e[p].l==e[p].r){ 62 e[p].s&=x; 63 e[p].sum1=e[p].s; 64 e[p].sum2=e[p].s*e[p].s%mo; 65 return; 66 } 67 int mid=(e[p].l+e[p].r)>>1; 68 if (mid>=r) update(p<<1,l,r,x); 69 else if(mid<l) update(p<<1|1,l,r,x); 70 else update(p<<1,l,r,x),update(p<<1|1,l,r,x); 71 e[p].s=e[p<<1].s|e[p<<1|1].s; 72 e[p].sum1=e[p<<1].sum1+e[p<<1|1].sum1; 73 e[p].sum2=(e[p<<1].sum2+e[p<<1|1].sum2)%mo; 74 } 75 76 void chaxun(int p,int l,int r){ 77 if (e[p].l>=l&&e[p].r<=r){ 78 sum=(sum+e[p].sum2)%mo; 79 return; 80 } 81 int mid=(e[p].l+e[p].r)>>1; 82 if (mid>=r) chaxun(p<<1,l,r); 83 else if(mid<l) chaxun(p<<1|1,l,r); 84 else chaxun(p<<1,l,r),chaxun(p<<1|1,l,r); 85 } 86 87 int main(){ 88 freopen("seg.in","r",stdin); 89 freopen("seg.out","w",stdout); 90 Init(); 91 while(q--){ 92 int x,y,l,r; 93 x=read(); 94 if (x==1){ 95 l=read(),r=read(),y=read(); 96 update(1,l,r,y); 97 } 98 if (x==2){ 99 l=read(),r=read(); 100 ans=0; 101 query(1,l,r); 102 printf("%lld\n",ans); 103 } 104 if (x==3){ 105 l=read(),r=read(); 106 sum=0; 107 ans=0; 108 query(1,l,r); 109 chaxun(1,l,r); 110 ans%=mo; 111 sum%=mo; 112 printf("%lld\n",(sum*(r-l+1)%mo*2%mo+(ans*ans)%mo*2)%mo); 113 } 114 } 115 }
标签:个数 图片 long oid include iostream 暴力 print char
原文地址:https://www.cnblogs.com/traveller-ly/p/9892594.html