結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー 👑 chro_96chro_96
提出日時 2023-05-19 22:48:07
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 2,553 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 32,328 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-05-10 06:16:03
合計ジャッジ時間 23,824 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,448 KB
testcase_01 AC 468 ms
8,448 KB
testcase_02 AC 562 ms
8,448 KB
testcase_03 AC 493 ms
8,448 KB
testcase_04 AC 512 ms
8,448 KB
testcase_05 AC 536 ms
8,448 KB
testcase_06 AC 565 ms
8,448 KB
testcase_07 AC 578 ms
8,576 KB
testcase_08 AC 592 ms
8,576 KB
testcase_09 AC 596 ms
8,448 KB
testcase_10 AC 534 ms
8,448 KB
testcase_11 AC 572 ms
8,576 KB
testcase_12 AC 566 ms
8,448 KB
testcase_13 AC 563 ms
8,448 KB
testcase_14 AC 555 ms
8,448 KB
testcase_15 AC 556 ms
8,576 KB
testcase_16 AC 574 ms
8,448 KB
testcase_17 AC 578 ms
8,448 KB
testcase_18 AC 563 ms
8,448 KB
testcase_19 AC 559 ms
8,448 KB
testcase_20 AC 553 ms
8,448 KB
testcase_21 AC 629 ms
8,576 KB
testcase_22 AC 650 ms
8,448 KB
testcase_23 AC 634 ms
8,448 KB
testcase_24 AC 641 ms
8,448 KB
testcase_25 AC 642 ms
8,448 KB
testcase_26 AC 628 ms
8,448 KB
testcase_27 AC 633 ms
8,448 KB
testcase_28 AC 626 ms
8,576 KB
testcase_29 AC 636 ms
8,448 KB
testcase_30 AC 649 ms
8,576 KB
testcase_31 AC 397 ms
8,576 KB
testcase_32 AC 401 ms
8,576 KB
testcase_33 AC 401 ms
8,448 KB
testcase_34 AC 407 ms
8,448 KB
testcase_35 AC 402 ms
8,448 KB
testcase_36 AC 407 ms
8,448 KB
testcase_37 AC 13 ms
8,448 KB
testcase_38 AC 572 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>

typedef struct tree {
  int v;
  struct tree *p;
} tree;

tree *get_root (tree *t) {
  if (t == NULL || t->p == NULL) {
    return t;
  }
  
  t->p = get_root(t->p);
  return t->p;
}

void add_segt (int *t, int idx, int val, int size) {
  idx = idx+size-1;
  t[idx] += val;
  
  while (idx > 0) {
    idx = (idx-1)/2;
    t[idx] += val;
  }
  
  return;
}

int sum_segt_rec (int *t, int a, int b, int k, int l, int r) {
  int ans = 0;
  
  if (r <= a || b <= l) {
    return 0;
  }
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2);
  ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r);
  
  return ans;
}

int sum_segt (int *t, int a, int b, int size) {
  return sum_segt_rec(t, a, b, 0, 0, size);
}

int main () {
  int t = 0;
  int n = 0;
  char x[6] = "";
  char y[199999][4] = {};
  int s[199999] = {};
  
  int res = 0;
  
  tree tr[200000] = {};
  int segt[524287] = {};
  
  res = scanf("%d", &t);
  while (t > 0) {
    int size = 1;
    tree *rt = NULL;
    res = scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      res = scanf("%s", x);
      if (x[0] == 'T') {
        tr[i].v = 1;
        tr[i].p = NULL;
      } else {
        tr[i].v = 0;
        tr[i].p = NULL;
      }
    }
    for (int i = 0; i < n-1; i++) {
      res = scanf("%s", y[i]);
    }
    for (int i = 0; i < n-1; i++) {
      res = scanf("%d", s+i);
    }
    while (size <= n) {
      size <<= 1;
    }
    for (int i = 0; i < 2*size-1; i++) {
      segt[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      add_segt(segt, i, 1, size);
    }
    for (int i = 0; i < n-1; i++) {
      int idx[2] = { 0, n };
      tree *rt1 = NULL;
      tree *rt2 = NULL;
      while (idx[1]-idx[0] > 1) {
        int nxt = (idx[0]+idx[1])/2;
        if (sum_segt(segt, 0, nxt, size) < s[i]) {
          idx[0] = nxt;
        } else {
          idx[1] = nxt;
        }
      }
      rt1 = get_root(tr+idx[0]);
      rt2 = get_root(tr+idx[1]);
      if (strcmp(y[idx[0]], "and") == 0) {
        rt1->v = rt1->v*rt2->v;
      } else if (strcmp(y[idx[0]], "or") == 0) {
        rt1->v = rt1->v*rt2->v+((rt1->v)^(rt2->v));
      } else if (strcmp(y[idx[0]], "imp") == 0) {
        rt1->v = (1-rt1->v)*rt2->v+((1-rt1->v)^(rt2->v));
      } else {
        rt1->v = (rt1->v)^(rt2->v);
      }
      rt2->p = rt1;
      add_segt(segt, idx[0], -1, size);
    }
    rt = get_root(tr);
    if (rt->v > 0) {
      printf("True\n");
    } else {
      printf("False\n");
    }
    t--;
  }
  
  return 0;
}
0