本文整理汇总了C++中tree::get方法的典型用法代码示例。如果您正苦于以下问题:C++ tree::get方法的具体用法?C++ tree::get怎么用?C++ tree::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ()
{
freopen ("subseq.in", "rt", stdin);
freopen ("subseq.out", "wt", stdout);
scanf ("%d", &n);
for (int i = 0; i < n; i++)
{
scanf ("%d", &seq[i]);
ps[i] = make_pair (-seq[i], -i);
}
sort (ps, ps + n);
for (int i = 0; i < n; i++)
tg[-ps[i].second] = i;
t.build ();
for (int i = 0; i < n; i++)
{
int r = t.get (0, tg[i]);
if (r < 0)
t.set (tg[i], 1), prev[i] = -1;
else
t.set (tg[i], t.v[r] + 1), prev[i] = -ps[r].second;
}
int mv = 0, mi = -1;
for (int i = 0; i < n; i++)
if (t.v[tg[i]] > mv)
mv = t.v[tg[i]], mi = i;
int ml = 0;
int cur = mi;
while (cur >= 0)
seq[ml++] = cur, cur = prev[cur];
sort (seq, seq + ml);
printf ("%d\n", ml);
for (int i = 0; i < ml; i++)
printf ("%d ", seq[i] + 1);
return 0;
}
示例2: mem
#include "testhelpers.h"
#include <stdio.h>
using namespace libbruce;
TEST_CASE("reading from a tree", "[query]")
{
be::mem mem(1024);
tree<int, int> t(maybe_nodeid(), mem);
t.insert(1, 1);
t.insert(2, 2);
mutation mut = t.write();
tree<int, int> q(*mut.newRootID(), mem);
REQUIRE( *q.get(1) == 1 );
REQUIRE( *q.get(2) == 2 );
REQUIRE( !q.get(3) );
}
TEST_CASE("reading from a tree with queued insert", "[query]")
{
be::mem mem(1024);
tree<int, int> t(maybe_nodeid(), mem);
t.insert(0, 0);
mutation mut = t.write();
tree<int, int> q(*mut.newRootID(), mem);
q.insert(1, 1);
REQUIRE( *q.get(1) == 1 );
}