結果

問題 No.3134 二分探索木
コンテスト
ユーザー tnakao0123
提出日時 2025-05-03 17:53:05
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,206 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 163 ms
コンパイル使用メモリ 52,012 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2026-07-10 11:42:30
合計ジャッジ時間 4,640 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 8 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3134.cc:  No.3134 莠悟・謗「邏「譛ィ - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

struct Node {
  int a, b, c;
  Node *lpt, *rpt;
  Node(): a(), b(), c(), lpt(), rpt() {}
  Node(int _a): a(_a), b(), c(), lpt(), rpt() {}
  Node(int _a, int _b, int _c): a(_a), b(_b), c(_c), lpt(), rpt() {}
};

/* global variables */

int as[MAX_N];
Node *es[MAX_N];

/* subroutines */

void addnode(Node *u, int i) {
  for (;;) {
    u->c++;
    if (as[i] < u->a) {
      if (u->lpt == nullptr) {
	u->lpt = es[i] = new Node(as[i], u->b + 1, 0);
	break;
      }
      u = u->lpt;
    }
    else {
      if (u->rpt == nullptr) {
	u->rpt = es[i] = new Node(as[i], u->b + 1, 0);
	break;
      }
      u = u->rpt;
    }
  }
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  es[0] = new Node(as[0]);
  for (int i = 1; i < n; i++) addnode(es[0], i);

  for (int i = 0; i < n; i++)
    printf("%d%c", es[i]->b, (i + 1 < n) ? ' ' : '\n');
  for (int i = 0; i < n; i++)
    printf("%d%c", es[i]->c, (i + 1 < n) ? ' ' : '\n');
  
  return 0;
}
0