显而易见的,这是一道线段树模板题
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
int l, r;
int v;
}tr[4 * 500005];
int w[500005];
void pushup(node& curr, node& left, node& right)
{
curr.v = left.v + right.v;
}
void pushup(int u)
{
node left = tr[u << 1];
node right = tr[u << 1 | 1];
pushup(tr[u], left, right);
}
void build(int u, int l, int r)
{
tr[u] = { l,r };
if (l == r)
{
tr[u] = { l, r, w[r] };
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
node query(int u, int l, int r)
{
if (l <= tr[u].l && r >= tr[u].r)return tr[u];
int mid = tr[u].l + tr[u].r >> 1;
if (r <= mid)return query(u << 1, l, r);
else if (l > mid)return query(u << 1 | 1, l, r);
else
{
node left = query(u << 1, l, r);
node right = query(u << 1 | 1, l, r);
node res;
pushup(res, left, right);
return res;
}
}
void solve()
{
for (int i = 1; i <= 2; i++)cin >> w[i];
build(1, 1, 2);
cout << query(1, 1, 2).v << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}
用主席树感觉更优雅(bushi
还没学(
主要是发现大家竟然都不用线段树做,线段树会难过的(bushi
好活hhhh
A+B,最好的解法是splay吧
不会splayQ^Q
不会splay 。゚・ (⁄ ⁄>⁄ ︿ ⁄<⁄ ⁄) ・゚。