zwb15350226668 @ 2024-07-13 21:08:21
#include<iostream>
#include<cstring>
using namespace std;
int lowbit(int a) {
return a & (-a);
}
void update(int c[], int n, int x, int val) {
while (x <= n) {
c[x] += val;
x += lowbit(x);
}
}
int query(int c[], int x) {
int sum = 0;
while (x > 0) {
sum += c[x];
x -= lowbit(x);
}
return sum;
}
int main() {
int n = 2, m = 1;
int a[n + 1], c[n + 1];
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
cin >> a[i];
update(c, n, i, a[i]);
}
for (int i = 1; i <= m; i++) {
int x = 1, y = 2; // 求 a[1] + a[2] 的和
int s1 = query(c, x - 1);
int s2 = query(c, y);
cout << s2 - s1 << endl; // 输出
}
return 0;
}
by gdfz02sjy @ 2024-07-14 11:57:18
%%%
by Bicj @ 2024-07-15 10:26:19
#include<bits/stdc++.h>
#define URBBR int
#define GROUN main
#define GUN return 0;
#define not_if else
#define GenBenTingBuXiaLai while(true)
int A_PLUS_B(int a,int b){
if(!a) return b;
return A_PLUS_B((a & b) << 1,a ^ b);
}
void OP(int a,int b){
std::cout << A_PLUS_B(a,b);
}
struct ZDJD{
char NiDeMingZi=1;
int daan=0,Big_Study_Born=1;
int o(){
NiDeMingZi=1;
daan=0,Big_Study_Born=1;
GenBenTingBuXiaLai{
NiDeMingZi = getchar();
if(NiDeMingZi == '-'){
Big_Study_Born = -1;
continue;
}
if(NiDeMingZi >= '0' and NiDeMingZi <= '9'){
daan*=10;
daan+= (int)(NiDeMingZi-'0');
}
not_if{
break;
}
}
return Big_Study_Born * daan;
}
}O;
URBBR GROUN(){
URBBR aminuoc;
URBBR manbo;
aminuoc = O.o();
manbo = O.o();
OP(aminuoc,manbo);
GUN;
}
ok,帮你优化了一下,有点抽象,需要理解一下(doge