#include <bits/stdc++.h>
using namespace std;
void build(int node,int l,int r,vector<int>& vec,long long tree[])
{
if(l==r)
{
tree[node]=vec[l];
}
else
{
int m=(l+r)/2;
build(node*2+1,l,m,vec,tree);
build(node*2+2,m+1,r,vec,tree);
tree[node]=min(tree[node*2+1],tree[node*2+2]);
}
}
void upd(int node,int pos,int x,int l,int r,vector<int>& vec,long long tree[])
{
if(l==r)
{
tree[node]=x;
return;
}
else
{
int m=(l+r)/2;
if(pos<=m)
{
upd(node*2+1,pos,x,l,m,vec,tree);
}
else
{
upd(node*2+2,pos,x,m+1,r,vec,tree);
}
tree[node]=tree[node*2+1]+tree[node*2+2];
}
}
long long sum(int node,int l, int r,int L,int R,vector<int>& vec,long long tree[])
{
if(l>R || r<L)
{
return 0;
}
else if(l>=L && r<=R)
{
return tree[node];
}
else
{
int m=(l+r)/2;
return sum(node*2+1,l,m,L,R,vec,tree)+sum(node*2+2,m+1,r,L,R,vec,tree);
}
}
long long tree1[4*500000],tree2[4*500000];
int main()
{
int n,q;
cin>>n>>q;
vector<int> vec1,vec2;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
if(x%2==0)
vec1.push_back(x);
else
vec2.push_back(x);
}
build(0,0,vec1.size()-1,vec1,tree1);
build(0,0,vec2.size()-1,vec2,tree2);
for(;q>0;q--)
{
int x;
cin>>x;
if(x==1)
{
int a,b;
cin>>a>>b;
a--;
if(a%2==0)
{
upd(0,a/2,b,0,vec1.size(),vec1,tree1);
}
else
{
upd(0,a/2,b,0,vec2.size(),vec2,tree2);
}
}
else
{
int a,b;
cin>>a>>b;
if((b-a+1)%2==0)
{
cout<<0<<endl;
}
else
{
a--;
b--;
if(a%2==0)
{
cout<<sum(0,0,vec1.size(),a/2,b/2,vec1,tree1)<<endl;
}
else
{
cout<<sum(0,0,vec2.size(),a/2,b/2,vec2,tree2)<<endl;
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
361 ms |
13532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |