本文整理汇总了C++中SegmentTree::update方法的典型用法代码示例。如果您正苦于以下问题:C++ SegmentTree::update方法的具体用法?C++ SegmentTree::update怎么用?C++ SegmentTree::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentTree
的用法示例。
在下文中一共展示了SegmentTree::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int T;
scanf("%d", &T);
for(int ck=1; ck<=T; ck++)
{
scanf("%d", &N);
scanf("%*s%*s");
scanf("%d", &Q);
tree.build(1,1,N);
for(int i=1; i<=Q; i++)
{
int opt,a,b;
scanf("%d%d%d", &opt, &a, &b);
if(opt)
{
printf("%d\n", tree.query(1,a,b));
}
else
{
tree.update(1,a,a,b);
}
}
scanf("%*s%*s");
scanf("%d", &Q);
tree.build(1,1,N);
for(int i=1; i<=Q; i++)
{
int opt,a,b,c;
scanf("%d", &opt);
if(opt)
{
scanf("%d", &a);
printf("%d\n", tree.query(1,a,a));
}
else
{
scanf("%d%d%d", &a, &b, &c);
tree.update(1,a,b,c);
}
}
}
return 0;
}
示例2: main
int main(void) {
T = in();
int kind;
SegmentTree tree;
for ( ; T--; ) {
N = in();
C = in();
tree.clear();
for ( ; C--; ) {
kind = in();
if (kind == 0) {
P = in();
Q = in();
V = in();
tree.update(1, 1, N, P, Q, V);
} else {
P = in();
Q = in();
printf("%lld\n", tree.query(1, 1, N, P, Q));
}
}
}
return 0;
}
示例3: main
int main() {
int b, p, l, n, n_input;
while(scanf("%d %d %d %d", &b, &p, &l, &n) == 4) {
if(b == 0 and p == 0 and l == 0 and n == 0) break;
B = b;
mod = p;
n_input = n;
SegmentTree tree;
tree.initialize((int)l + 1);
char cm;
int i, v;
while(n_input--) {
assert(scanf(" %c %d %d", &cm, &i, &v) == 3);
//D(cm); D(i); D(v);
// responder al comando cm, i, v
if (cm == 'E') {
tree.update(i, v);
} else if (cm == 'H'){
int ans = tree.query(i, v) % mod;
printf("%d\n", ans);
}
}
puts("-");
}
return 0;
}
示例4: updateEdgeChain
void updateEdgeChain(int u, int anc, int val) {
while (u != anc) {
int fe = rev[u];
if (top[u] != u) {
int p = top[u];
if (dep[p] < dep[anc]) p = anc;
int l = stIdx[heavyChild(p)];
int r = stIdx[u];
st.update(val, l, r);
u = p;
} else {
int r = stIdx[u];
st.update(val, r, r);
u = g.E[fe].to;
}
}
}
示例5: check_update_correctness
void check_update_correctness(int where, int what){
vector<int> old = t.arr;
t.update(where, what);
old[where] = what;
printf("Update [%d] = %d\n", where, what);
assert(t.arr == old);
printf(" SUCCESS\n");
}
示例6: expend
void expend(int np)
{
if(str[np] != chr[3]) return;
int lm = startE(np);
if(!lm) return;
printf("ex-lm: %d %d\n", lm, np);
tree.clear(1,lm,np);
tree.update(1,np);
}
示例7: main
int main() {
int x[] = {4, 2, 19, 24, 11, -1, 100, 32};
int size = sizeof(x) / sizeof(x[0]);
SegmentTree seg;
seg.init(size);
rep(i, size) {
seg.update(i, x[i]);
}
示例8: main
int main()
{
ios::sync_with_stdio(false);
SegmentTree T;
int n = SN;
srand(time(0));
int Q = 1000000;
vector<int> v(n);
char c;
int a,b,x;
// while(cin >> c >> a >> b){
// if(c == 'u'){
// cin >> x;
// T.update(x,a,b);
// FORA(i,a,b) v[i] += x;
// }
// else {
// int sum = 0;
// FORA(i,a,b) sum += v[i];
// cout << T.query(a,b) << ' ' << sum << endl;
// }
// FOR(i,n) cout << v[i] << ' '; cout << endl;
// }
// return 0;
while(Q--){
a = (rand() % n) + 1, b = (rand() % n) + 1;
if(a > b) swap(a,b);
x = rand() % (n*n);
printf("update : [%d,%d) +%d\n", a,b,x);
T.update(x,a,b);
FORA(i,a,b) v[i] += x;
a = (rand() % n) + 1, b = (rand() % n) + 1;
if(a > b) swap(a,b);
printf("query : [%d,%d) \n",a,b);
int sum = 0;
FORA(i,a,b) sum += v[i];
FOR1(i,n) cout << v[i] << ' '; cout << endl;
cout << T.query(a,b) << ' ' << sum << endl;
assert(T.query(a,b) == sum);
}
return 0;
}
示例9: DP
int DP(int u, int f)
{
// printf("u=%d\n", u);
for(int e=G.last[u]; ~e; e=G.nxt[e])
{
int v=G.v[e];
if(v==f) continue;
DP(v,u);
// printf("u=%d\n", u);
sum[u] += dp[v];
}
dp[u]=sum[u];
// printf("%d %d %d\n", hld.dfsn[u], sum[u], dp[u]);
tree.update(1,hld.dfsn[u],sum[u],dp[u]);
for(int i=0; i<(int)chain[u].size(); i++)
{
int x=chain[u][i].x, y=chain[u][i].y, w=chain[u][i].w;
dp[u] = max( dp[u], hld.Get(x,y)+w);
}
tree.update(1,hld.dfsn[u],sum[u],dp[u]);
return 0;
}
示例10: main
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d %d %I64d", &rings[i].a, &rings[i].b, &rings[i].h);
}
sort(rings, rings + n);
n = merge();
tree.build(1, 0, n - 1);
for(int i = 0; i < n; i++) {
int update_idx = lower_bound(ranks.begin(), ranks.end(), rings[i].a) - ranks.begin();
int idx = lower_bound(ranks.begin(), ranks.end(), rings[i].b) - ranks.begin();
long long val = rings[i].h;
if(idx) {
val += tree.query(1, 0, idx - 1);
}
tree.update(1, update_idx, val);
}
printf("%I64d\n", tree.query(1, 0, n - 1));
return 0;
}
示例11: main
int main(){
redirect();
while(cin>>N>>K){
for(int i=0;i<N;i++)
cin>>v[i];
st.buildTree();
for(int i=0;i<K;i++){
cin>>ch>>a>>b;
if(ch=='C'){
v[a-1]=b;
st.update(1,0,N-1,a-1);
}
else{
cout<<st.query(a-1,b-1);
}
}
cout<<endl;
}
return 0;
}
示例12: main
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d %d", &v[i].r, &v[i].h);
ranks[i] = i;
}
sort(ranks, ranks+n, cmp);
for(int i = 0; i < n; i++)
v[ranks[i]].i = i;
SegmentTree tree;
tree.build(1, 0, n-1);
long long ans = 0;
for(int i = 0; i < n ; i++) {
int r = v[i].i;
long long now = tree.query(1, 0, r) + v[i].r * 1LL * v[i].r * v[i].h;
ans = max(ans, now);
tree.update(1, r, now);
}
printf("%.9lf\n", pi * ans);
return 0;
}
示例13: Scan
void Scan(int flr)
{
tree.build(1,0,ais[flr].siz);
for(int i=0; i<isiz[flr]; i++)
{
// if(debug)
// {
// Object &now=inpt[flr][i];
// puts((inpt[flr][i].flag==WALL)?"wall":"bird");
// printf("%d: %d %d %d\n", now.id, now.u, now.v, now.h);
// }
if(inpt[flr][i].flag == WALL)
{
tree.update(1, ais[flr].id(inpt[flr][i].u), ais[flr].id(inpt[flr][i].v), inpt[flr][i].id, inpt[flr][i].h);
}
else
{
// if(debug)
// {
// printf("%d\n", ais[flr].siz);
// for(int i=0; i<ais[flr].siz; i++) printf("%d ", tree.query(1,i).first);puts("");
// for(int i=0; i<ais[flr].siz; i++) printf("%d ", tree.query(1,i).second);puts("");
// }
Pii info=tree.query(1, ais[flr].id(inpt[flr][i].u));
if(info.first==-1) continue;
// if(debug) printf("wid=%d\n", info.first);
int res, id;
id=inpt[flr][i].id;
res=abs(inpt[flr][i].h - info.second);
if(res < bird[0][id])
{
bird[0][id] = res;
bird[1][id] = info.first;
}
}
}
}
示例14: countRangeSum
int countRangeSum(vector<int>& nums, int lower, int upper) {
if(nums.empty()) return 0;
int n = (int)nums.size();
vector<long> sums;
set<long> values;
long sum = 0L;
for(int i = 0; i < (int)nums.size(); ++i) {
sum += nums[i];
values.insert(sum);
}
for(auto it = values.begin(); it != values.end(); ++it) {
sums.push_back(*it);
}
int result = 0;
SegmentTree segmentTree;
segmentTree.init(sums);
for(int i = n - 1; i >= 0; --i) {
segmentTree.update(sum);
sum -= nums[i];
result += segmentTree.query(lower + sum, upper + sum);
}
return result;
}
示例15: main
int main()
{
ifstream fin("sum.in");
ofstream fout("sum.out");
int n = 0, k = 0;
fin >> n >> k;
int *values = new int[n];
for (int i = 0; i < n; i++)
{
values[i] = 0;
}
SegmentTree rsq = SegmentTree(n, values);
for (int i = 0; i < k; i++)
{
char c;
int a, b;
fin >> c >> a >> b;
if (c == 'A')
rsq.update(a - 1, b);
else
fout << rsq.sum(a - 1, b - 1) << "\n";
}
return 0;
}