题解:P1001 A+B Problem
一道 ST 表板子题,但是弱化了很多。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n = 2, a[200], st[200][200];
void solve()
{
for (ll i = 1; i <= n; i++)
{
cin >> a[i];
st[i][0] = a[i];
}
for (ll j = 1; j <= n; j++)
{
for (ll i = 1; i <= n; i++)
{
if (i + (1 << j) - 1 > n)
{
break;
}
st[i][j] = st[i][j - 1] + st[i + (1 << j - 1)][j - 1];
}
}
cout << st[1][1];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// ll t; cin >> t; while (t--)
solve();
return 0;
}