本文整理汇总了C++中seg::build方法的典型用法代码示例。如果您正苦于以下问题:C++ seg::build方法的具体用法?C++ seg::build怎么用?C++ seg::build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seg
的用法示例。
在下文中一共展示了seg::build方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main () {
scanf("%d", &n);
tree.build(1, 0, n);
while (scanf("%d %d %d", &k, &a, &b) != EOF) {
if (k == 1) {
scanf("%d", &v);
tree.add(1, a-1, b, v);
} else {
printf("%d\n", tree.getVal(1, a-1, b));
}
}
}
示例2: main
int main () {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
tree.criaAcc(n);
tree.build(1, 0, n);
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &a, &b);
tree.res = tree.getQuery(1, a-1, b);
printf("%d %d\n", tree.acc[tree.res.fm] - tree.acc[tree.res.im], tree.res.fm - tree.res.im);
}
}
}
示例3: main
int main () {
scanf("%d %d", &n, &m);
tree.build(1, 0, n);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &a, &b, &x);
if (a == x) {
tree.update(1, a, b, x);
} else if (b == x) {
tree.update(1, a-1, b-1, x);
} else {
tree.update(1, a-1, x-1, x);
tree.update(1, x, b, x);
}
}
tree.printit(1, 0);
printf("\n");
}
示例4: main
int main () {
scanf("%d", &tc);
for (int t = 1; t <= tc; t++) {
scanf("%d %d", &n, &q);
printf("Scenario #%d:\n", t);
for (int i = 0; i < n; i++)
scanf("%d", inp+i);
tree.build(1, 0, n);
int lo, hi;
for (int i = 0; i < q; i++) {
scanf("%d %d", &lo, &hi);
printf("%d\n", tree.query(lo-1, hi).v);
}
}
}
示例5: main
int main()
{
ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
ifstream F("p.in");
#endif
F>>n>>m;
for (int i=1,x,y;i<=n;++i)
{
F>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
try
{
find_cycle(1);
}
catch (pair<int,int> p)
{
int x = p.first;
int y = p.second;
cyc.push_back(y);
while ( x != y )
{
cyc.push_back(x);
x = dd[x];
}
}
for (int i=0;i<int(cyc.size());++i)
ord[cyc[i]] = i+1;
//for (int i=0;i<int(cyc.size());++i) cerr<<cyc[i]<<' '; cerr<<'\n';
memset(mk,0,sizeof(mk));
memset(dd,0,sizeof(dd));
for (int i=0;i<int(cyc.size());++i)
mk[cyc[i]] = 1;
for (int i=0;i<int(cyc.size());++i)
{
act_tree = i;
find_chains(cyc[i]);
}
for (int i=0;i<int(chains.size());++i)
for (int j=0;j<int(chains[i].size());++j)
{
int x = chains[i][j];
my[x] = i;
pl[x] = j+1;
}
//for (int i=0;i<int(chains.size());++i,cerr<<'\n') { cerr<<i<<':'; for (int j=0;j<int(chains[i].size());++j) cerr<<chains[i][j]<<' '; }
for (int i=0;i<int(chains.size());++i)
{
s[i] = seg(chains[i].size());
s[i].build(1,1,chains[i].size());
}
c = seg(cyc.size());
c.build(1,1,cyc.size());
ans = n;
//for (int i=1;i<=n;++i) cerr<<dd[i]<<' '; cerr<<'\n';
//for (int i=1;i<=n;++i) cerr<<my[i]<<' '; cerr<<'\n';
//for (int i=1;i<=n;++i) cerr<<pl[i]<<' '; cerr<<'\n';
for (int q=1,x,y;q<=m;++q)
{
F>>x>>y;
//cerr<<x<<' '<<y<<'\n';
vector<int> ax,ay;
for (int i=x;;i=dd[i])
{
i = chains[my[i]].back();
ax.push_back(my[i]);
if ( !dd[i] ) break;
}
for (int i=y;;i=dd[i])
{
i = chains[my[i]].back();
//cerr<<i<<'\n';
ay.push_back(my[i]);
if ( !dd[i] ) break;
}
reverse(ax.begin(),ax.end());
reverse(ay.begin(),ay.end());
ax.resize(ax.size()+1);
ax[ax.size()-1] = -1;
ay.resize(ay.size()+1);
ay[ay.size()-1] = -2;
int mx = max(ax.size(),ay.size());
ax.resize(mx);
ay.resize(mx);
//for (int i=0;i<int(ax.size());++i) cerr<<ax[i]<<' '; cerr<<'\n';
//for (int i=0;i<int(ay.size());++i) cerr<<ay[i]<<' '; cerr<<'\n';
if ( tree[x] == tree[y] )
//.........这里部分代码省略.........