QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#570028 | #7992. 【模板】线段树 | liaoyanxu | TL | 1ms | 5740kb | C++14 | 2.3kb | 2024-09-17 13:19:51 | 2024-09-17 13:19:51 |
Judging History
answer
// Problem: P10045 [CCPC 2023 北京市赛] 线段树
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P10045
// Memory Limit: 1 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
const int N=200005,M=1145,K=21,len=314;
int mod=1048575;
int n,q,a[N],mul[N][K],tag[N];
namespace lyx{
inline int bl(int x){
return (x+len-1)/len;
}
inline int L(int id){
return len*(id-1)+1;
}
inline int R(int id){
return len*id;
}
inline void rebuild(int id){
for(int i=1;i<=20;i++){
mul[id][i]=0;
}
mul[id][1]=1;
for(int i=L(id);i<=R(id);i++){
for(int j=20;j>=1;j--){
mul[id][j]=mul[id][j]*a[i]+mul[id][j-1];
}
}
return ;
}
inline void build(){
for(int i=1;i<=n;i++){
if(bl(i)!=bl(i-1)){
rebuild(bl(i));
}
}
return ;
}
inline void pushdown(int id){
if(!tag[id]){
return ;
}
for(int i=L(id);i<=R(id);i++){
a[i]+=tag[id];
}
tag[id]=0;
rebuild(id);
return ;
}
inline void add(int l,int r,int k){
if(bl(l)==bl(r)){
pushdown(bl(l));
for(int i=l;i<=r;i++){
a[i]+=k;
}
rebuild(bl(l));
return ;
}
pushdown(bl(l));
for(int i=l;i<=R(bl(r));i++){
a[i]+=k;
}
rebuild(bl(l));
pushdown(bl(r));
for(int i=L(bl(r));i<=r;i++){
a[i]+=k;
}
rebuild(bl(r));
for(int i=bl(l)+1;i<=bl(r)-1;i++){
tag[i]+=k;
}
return ;
}
inline int query(int l,int r){
if(bl(l)==bl(r)){
pushdown(bl(l));
int ans=1;
for(int i=l;i<=r;i++){
ans*=a[i];
}
return ans;
}
int ans=1;
for(int i=l;i<=R(bl(l));i++){
ans*=a[i];
}
for(int i=L(bl(r));i<=r;i++){
ans*=a[i];
}
for(int i=bl(l)+1;i<=bl(r)-1;i++){
int tmp=1;
int ml=0,cnt=1;
while(tmp%mod){
ml=ml+tmp*mul[i][cnt];
tmp*=tag[i];
cnt++;
}
ans*=ml;
}
return ans;
}
}
using namespace lyx;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build();
while(q--){
int op,l,r,x;
cin>>op>>l>>r;
if(op==1){
cin>>x;
add(l,r,x);
}
else{
cout<<((int)(query(l,r))&(int)(mod))<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5740kb
input:
10 10 969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323 1 5 6 3034 2 1 10 2 1 9 2 1 4 1 3 6 126904 2 5 5 2 9 9 1 7 7 853094 1 4 9 1025178 2 5 8
output:
1045541 1012343 558151 580413 810659 527353
result:
ok 6 lines
Test #2:
score: -100
Time Limit Exceeded
input:
200000 200000 496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...
output:
746709 314063 659903 808669 503473 21677 927775 100755 280085 881717 342407 297901 971535 235199 974337 299843 272239 557231 778879 568799 735011 585811 209677 723243 808997 693855 907581 852603 562049 39577 365199 251803 541549 246033 936745 789879 147367 600219 518081 93965 224083 681381 582301 24...