树状数组WA QAQ
查看原帖
树状数组WA QAQ
785296
LVFUyang1楼主2024/11/23 17:11
#include<bits/stdc++.h>
using namespace std;
int n,m;
int c[1000005];
int k;
int lowbit(int x){
	return x&(-x);
}
void add(int x,int v){
	while(x<=n){
		c[x]+=v;
		x+=lowbit(x);
	}
}
int sum(int x){
	int ret=0;
	while(x>0){
		ret+=c[x];
		x-=lowbit(x);
	}
	return ret;
}
int main(){
	n==2;
	m==1;
	cin>>k;
	add(1,k);
	cin>>k;
	add(2,k);
	cout<<sum(2);
	return 0;
}
2024/11/23 17:11
加载中...