世纪难题A+B problem的解法
2025-08-10 11:09:13
发布于:浙江
:1.A+B problem
注:本帖仅供娱乐
#include<bits/stdc++.h>
using namespace std;
int a[114514];
struct node{
int l,r,val;
}tree[314159];
void build(int l,int r,int p){
tree[p].l=l,tree[p].r=r;
if(l==r){
tree[p].val=a[l];
return;
}
int mid=(l+r)/2;
build(l,mid,p*2);
build(mid+1,r,p*2+1);
tree[p].val=tree[p*2].val+tree[p*2+1].val;
}
void update(int l,int r,int p,int x,int y){
if(l==r){
tree[p].val+=y;
return;
}
int mid=(l + r)>>1;
if(x<=mid)update(l,mid,p*2,x,y);
else update(mid+1,r,p*2+1,x,y);
tree[p].val=tree[p*2].val+tree[p*2+1].val;
}
int query(int l,int r,int p,int x,int y){
if(x<=l&&y>=r){
return tree[p].val;
}
int mid=(l+r)>>1;
int ans=0;
if(x<=mid)ans+=query(l,mid,p*2,x,y);
if(y>mid)ans+=query(mid+1,r,p*2+1,x,y);
return ans;
}
int main(){
build(1,2,1);
for(int i=1;i<=2;i++){
int x;
cin>>x;
update(1,2,1,i,x);
}
cout<<query(1,2,1,1,2)<<"\n";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[114514],f[114514];
int lowbit(int x){
return x&-x;
}
void add(int x,int k){
while(x<=2){
f[x]+=k;
x+=lowbit(x);
}
}
void add(int l,int r,int k){
add(l,k);
add(r+1,-k);
}
long long ask(int x){
long long ans=0;
while(x){
ans+=f[x];
x-=lowbit(x);
}
return ans;
}
int main(){
for(int i=1;i<=2;i++){
cin>>a[i];
add(i,a[i]-a[i-1]);
}
for(int i=1;i<=2;i++){
int x;
cin>>x;
add(1,1,x);
}
cout<<ask(1)+ask(2);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int A[114514],B[114514],C[114514];
int main(){
string a,b;
cin>>a>>b;
for(int i=a.size()-1,j=1;i>=0;i--,j++){
A[j]=a[i]-'0';
}
for(int i=b.size()-1,j=1;i>=0;i--,j++){
B[j]=b[i]-'0';
}
int len=max(a.size(),b.size());
for(int i=1;i<=len;i++){
C[i]+=A[i]+B[i];
C[i+1]+=C[i]/10;
C[i]=C[i]%10;
}
if(C[len+1]!=0){
len++;
}
for(int i=len;i>0;i--){
cout<<C[i];
}
return 0;
}
全部评论 3
#incloud<bits/stdc+.h> using namspace std; int mian(){ int a.b; cin<<a>>b. cour>>a+b: retunr 0; }
写了几个小时还是没写对,的确很难
2小时前 来自 上海
0a=input() b=input() print(a+b)
怎么一直报错
2小时前 来自 浙江
0C++太难了
2小时前 来自 浙江
0#include<bits/stdc++.h> using namespace st; ont mian(){ int a,b; cin>>a>>B; cout<<a+B return -' }
一直报错
2小时前 来自 浙江
0
#include<bits/stdc++.h> using namespace std; const int N=1e9+10; int a[5]; int main() { int n,m; cin>>n>>m; int x=n%6,y=m%6; vector<long long> v; if(x==1) { if(y<=1) while(1) cout<<1; if(y==5) while(1) v.push_back(114514); if(y>1 && y!=5) cout<<n+m; } if(x==2) { if(y<=2) cout<<" "<<n+m; else cout<<-1; } if(x==3) while(1) continue; if(x==4) cout<<a[114514]; }
7小时前 来自 浙江
0神秘小代码
7小时前 来自 浙江
0你的核心代码好像就是:
cin>>n>>m; cout<<n+m;
7小时前 来自 浙江
0《五 颜 六 色 的 测 试 点》,昨天不是给我发过了吗
7小时前 来自 浙江
0
666
7小时前 来自 浙江
0
有帮助,赞一个