#include <iostream>
#include <vector>
using namespace std;
int n, m;
long long tree[500005]; // 树状数组
// lowbit 函数:找到二进制最后一位 1
int lowbit(int x) {
return x & -x;
}
// 单点修改:将第 x 个数加上 k
void add(int x, int k) {
for (; x <= n; x += lowbit(x)) {
tree[x] += k;
}
}
// 前缀和查询:求出 [1, x] 的和
long long query(int x) {
long long res = 0;
for (; x > 0; x -= lowbit(x)) {
res += tree[x];
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
// 初始化:读入初始值并建树
for (int i = 1; i <= n; ++i) {
int val;
cin >> val;
add(i, val); // 初始值视作在位置 i 加上 val
}
while (m--) {
int type, x, y;
cin >> type >> x >> y;
if (type == 1) {
add(x, y); // type 1: 将第 x 个数加上 y
} else {
// type 2: 查询区间 [x, y] 的和
cout << query(y) - query(x - 1) << "\n";
}
}
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int n, m;
long long tree[500005]; // 树状数组
// lowbit 函数:找到二进制最后一位 1
int lowbit(int x) {
return x & -x;
}
// 单点修改:将第 x 个数加上 k
void add(int x, int k) {
for (; x <= n; x += lowbit(x)) {
tree[x] += k;
}
}
// 前缀和查询:求出 [1, x] 的和
long long query(int x) {
long long res = 0;
for (; x > 0; x -= lowbit(x)) {
res += tree[x];
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
// 初始化:读入初始值并建树
for (int i = 1; i <= n; ++i) {
int val;
cin >> val;
add(i, val); // 初始值视作在位置 i 加上 val
}
while (m--) {
int type, x, y;
cin >> type >> x >> y;
if (type == 1) {
add(x, y); // type 1: 将第 x 个数加上 y
} else {
// type 2: 查询区间 [x, y] 的和
cout << query(y) - query(x - 1) << "\n";
}
}
return 0;
}
#include <iostream>
using namespace std;
long long n,m,z = 1,k = 0;
long long a[27][27];
long long b[407];
int main() {
cin >> n >> m;
for(long long i=1;i<=n;i++){
for(long long j=1;j<=m;j++){
a[i][j]=z;
z++;
}
}
long long top=1,left=1,right=m,bottom=n;
while(left<=right&&top<=bottom){
for(long long i=top;i<=bottom;i++){
k++;
b[k]=a[i][left];
}
left++;
for(long long i=left;i<=right;i++){
k++;
b[k]=a[bottom][i];
}
bottom--;
for(long long i=bottom;i>=top;i--){
k++;
b[k]=a[i][right];
}
right--;
for(long long i=right;i>=left;i--){
k++;
b[k]=a[top][i];
}
top++;
}
for(long long i=1;i<=k;i++){
if(i!=k)cout << b[i] << ",";
else cout << b[i];
}
return 0;
}