이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long tree[100000*4];
vector<long long> vec;
void build(long long node,long long l,long long r)
{
if(l==r)
{
tree[node]=vec[l-1];
}
else
{
long long m=(l+r)/2;
build(node*2,l,m);
build(node*2+1,m+1,r);
}
}
void upd(long long node,long long i,long long x,long long l ,long long r)
{
if(l==r)
{
tree[node]=x;
}
else
{
long long m=(l+r)/2;
if(i<=m)
{
upd(node*2,i,x,l,m);
}
else
upd(node*2+1,i,x,m+1,r);
}
}
long long sum(long long node,long long l,long long r,long long L,long long R)
{
if(l>R || r<L)
{
return 0;
}
else if(l>=L && r<=R)
{
return tree[node];
}
else
{
long long m=(l+r)/2;
return sum(node*2,l,m,L,R)+sum(node*2+1,m+1,r,L,R);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,k;
cin>>n>>k;
for(long long n1=n;n1>0;n1--)
{
long long x;
cin>>x;
vec.push_back(x);
}
build(1,1,vec.size());
pair<long long,long long> sqd[n]={},sqd2[n]={};
long long val=0,val2=0;
for(long long i=0;i<n;i++)
{
val=val+vec[i]*(i%317+1);
val2+=vec[i];
if(i%317==316)
{
sqd[i]={val,val2};
val=0;
val2=0;
}
}
val=0,val2=0;
for(long long i=n-1;i>=0;i--)
{
val=val+vec[i]*((vec.size()-i-1)%317+1);
val2+=vec[i];
if((vec.size()-i-1)%317==316)
{
sqd2[i]={val,val2};
val=0;
val2=0;
}
}
long long q;
cin>>q;
for(;q>0;q--)
{
long long x;
cin>>x;
if(x==1)
{
vector<long long> temp;
for(long long k1=k;k1>0;k1--)
{
long long br;
cin>>br;
temp.push_back(br-1);
}
long long tempp=vec[temp[0]];
for(long long i=0;i<temp.size();i++)
{
if(i==temp.size()-1)
{
long long br2=316-((temp[i]-1)%317);
if(temp[i]+br2<n)
{
sqd[temp[i]+br2].first-=(vec[temp[i]]*(temp[i]%317+1));
sqd[temp[i]+br2].second-=(vec[temp[i]]);
vec[temp[i]]=tempp;
sqd[temp[i]+br2].first+=(vec[temp[i]]*(temp[i]%317+1));
sqd[temp[i]+br2].second+=(vec[temp[i]]);
}
else
vec[temp[i]]=tempp;
br2=316-((vec.size()-temp[i]-2)%317);
if(temp[i]-br2>=0)
{
sqd2[temp[i]-br2].first-=(vec[temp[i]]*((vec.size()-temp[i]-1)%317+1));
sqd2[temp[i]-br2].second-=(vec[temp[i]]);
vec[temp[i]]=tempp;
sqd2[temp[i]-br2].first+=(vec[temp[i]]*((vec.size()-temp[i]-1)%317+1));
sqd2[temp[i]-br2].second+=(vec[temp[i]]);
}
else
vec[temp[i]]=tempp;
upd(1,temp[i]+1,tempp,1,vec.size());
}
else
{
long long br=temp[i+1];
long long br2=316-((temp[i]-1)%317);
if(temp[i]+br2<n)
{
sqd[temp[i]+br2].first-=(vec[temp[i]]*((temp[i])%317+1));
sqd[temp[i]+br2].second-=(vec[temp[i]]);
vec[temp[i]]=vec[br];
sqd[temp[i]+br2].first+=(vec[temp[i]]*((temp[i])%317+1));
sqd[temp[i]+br2].second+=(vec[temp[i]]);
}
else
vec[temp[i]]=vec[br];
br2=316-((vec.size()-temp[i]-2)%317);
if(temp[i]-br2>=0)
{
sqd2[temp[i]-br2].first-=(vec[temp[i]]*((vec.size()-temp[i]-1)%317+1));
sqd2[temp[i]-br2].second-=(vec[temp[i]]);
vec[temp[i]]=vec[br];
sqd2[temp[i]-br2].first+=(vec[temp[i]]*((vec.size()-temp[i]-1)%317+1));
sqd2[temp[i]-br2].second+=(vec[temp[i]]);
}
else
vec[temp[i]]=vec[br];
upd(1,temp[i]+1,vec[br],1,vec.size());
}
}
}
else
{
long long l,r,m;
cin>>l>>r>>m;
long long sz=r-l+1;
if(m>sz/2)
{
m=sz-m+1;
}
long long l1=l+m-1,r1=r-m+1;
long long res=0;
if(l1>r1)
swap(l1,r1);
if(l1<=r1)
{
res=res+sum(1,1,vec.size(),l1,r1)*m;
}
for(long long m1=m-1,l2=l1-2;l2>=l-1;l2--,m1--)
{
if(l2%317==316 && l2-316>=l-1)
{
res=res+sqd[l2].first+(sqd[l2].second*(m1-317));
m1-=316;
l2-=316;
}
else
{
res+=vec[l2]*m1;
}
}
l1=r1;
for(long long m1=m-1;l1<=r-1;l1++,m1--)
{
if((vec.size()-l1-1)%317==316 && l1+316<=r-1)
{
res=res+sqd2[l1].first+(sqd2[l1].second*(m1-317));
m1-=316;
l1+=316;
}
else
{
res+=vec[l1]*m1;
}
}
cout<<res<<"\n";
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:113:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(long long i=0;i<temp.size();i++)
| ~^~~~~~~~~~~~
Main.cpp:115:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | if(i==temp.size()-1)
| ~^~~~~~~~~~~~~~~
Main.cpp:128:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
128 | else
| ^~~~
Main.cpp:131:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
131 | br2=316-((vec.size()-temp[i]-2)%317);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |