コード例 #1
0
ファイル: 18_22_36_15_17bI_5885.CPP プロジェクト: hrnn/olymp
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
0
ファイル: test_querying.cpp プロジェクト: rix0rrr/libbruce
#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 );
}