• LQDOJ
  • Trang chủ
  • Bài tập
  • Bài nộp
  • Thành viên
  • Kỳ thi
  • Nhóm
  • Giới thiệu
    • Máy chấm
    • Khóa học
    • Đề xuất ý tưởng
    • Đề xuất bài tập
    • Tools
    • Báo cáo tiêu cực
    • Báo cáo lỗi

Tiếng Việt

Tiếng Việt
English

Đăng nhập

Đăng ký

theson11072007

  • Giới thiệu
  • Bài tập
  • Bài nộp

Rating
-
Bài tập
6
Điểm
3324
Rating #
-
Điểm #
11994

Giới thiệu

include <bits/stdc++.h>

define fo(i,l,r) for(int i=l;i<=r;i++)

using namespace std;
int n,q;
int a[60000];
long long bit[60000];
long long getsum(int u)
{
int x = u;
long long res = 0 ;
while(x > 0)
{
res += bit[x];
x = x - (x&(-x)) ;
}
return res;
}
void update(int u, int v )
{
int x = u;
while(x <= n)
{
bit[x] += v ;
x =x +(x&(-x)) ;
}
}
int main()
{

cin >> n ;
cin>>q;
fo(i,1,n)
  {
      cin >> a[i] ;
      update(i,a[i]);
  }

while(q--)
{
    int s,u,v;
    cin >> s ;
    if(s == 1)
    {
        cin>> u >>v ;
        update(u,v);
    }
    else
    {
        cin >> u >> v ;
        cout<< getsum(v) - getsum(u-1) << endl ;
    }
}
return 0;

}


«    »
Thứ 2
Thứ 3
Thứ 4
Thứ 5
Thứ 6
Thứ 7
CN
Ít
Nhiều

proudly powered by DMOJ| developed by LQDJudge team