提出 #30817031


ソースコード 拡げる

#line 1 "sol.cpp"
#include <bits/stdc++.h>

int main() {
  int n, q, x;
  scanf("%d%d%d", &n, &q, &x);
  std::map<int, int> segments;
  segments[n] = -1;
  for (int i = 0, p; i < n; ++i) {
    scanf("%d", &p);
    int c;
    if (p < x) {
      c = 0;
    } else if (p == x) {
      c = 1;
    } else {
      c = 2;
    }
    segments[i] = c;
  }
  auto cut = [&](int l) {
    auto iterator = segments.lower_bound(l);
    if (l < iterator->first) {
      segments.emplace(l, std::prev(iterator)->second);
    }
  };
  while (q--) {
    int op, l, r;
    scanf("%d%d%d", &op, &l, &r);
    l--;
    cut(l);
    cut(r);
    std::array<std::pair<int, int>, 3> count{};
    for (int i = 0; i < 3; ++i) {
      count[i].first = i;
    }
    // sweep
    {
      auto iterator = segments.lower_bound(l);
      while (iterator->first < r) {
        auto backup = iterator;
        iterator++;
        count[backup->second].second += iterator->first - backup->first;
        segments.erase(backup);
      }
    }
    if (op == 2) {
      std::reverse(count.begin(), count.end());
    }
    int offset = l;
    for (auto [c, s] : count) {
      if (s > 0) {
        segments.emplace(offset, c);
      }
      offset += s;
    }
  }
  int index = -1;
  for (auto [k, c] : segments) {
    if (c == 1) {
      index = k;
    }
  }
  printf("%d\n", index + 1);
}

提出情報

提出日時
問題 G - Range Sort Query
ユーザ ftiasch
言語 C++ (GCC 9.2.1)
得点 600
コード長 1348 Byte
結果 AC
実行時間 276 ms
メモリ 13164 KiB

コンパイルエラー

sol.cpp: In function ‘int main()’:
sol.cpp:5:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sol.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sol.cpp:28:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 37
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 7 ms 3788 KiB
example_01.txt AC 3 ms 3744 KiB
hand_00.txt AC 2 ms 3660 KiB
hand_01.txt AC 53 ms 3664 KiB
hand_02.txt AC 73 ms 13028 KiB
hand_03.txt AC 152 ms 13040 KiB
hand_04.txt AC 147 ms 13044 KiB
hand_05.txt AC 246 ms 13040 KiB
hand_06.txt AC 126 ms 13120 KiB
hand_07.txt AC 88 ms 13164 KiB
hand_08.txt AC 91 ms 12984 KiB
hand_09.txt AC 76 ms 13076 KiB
hand_10.txt AC 74 ms 13096 KiB
hand_11.txt AC 72 ms 13020 KiB
hand_12.txt AC 73 ms 13044 KiB
hand_13.txt AC 71 ms 12976 KiB
hand_14.txt AC 73 ms 13032 KiB
random_00.txt AC 75 ms 13124 KiB
random_01.txt AC 73 ms 13112 KiB
random_02.txt AC 75 ms 13028 KiB
random_03.txt AC 75 ms 13036 KiB
random_04.txt AC 71 ms 13068 KiB
random_05.txt AC 95 ms 12976 KiB
random_06.txt AC 81 ms 12980 KiB
random_07.txt AC 82 ms 13076 KiB
random_08.txt AC 80 ms 13112 KiB
random_09.txt AC 75 ms 13112 KiB
random_10.txt AC 276 ms 12976 KiB
random_11.txt AC 222 ms 13120 KiB
random_12.txt AC 200 ms 13072 KiB
random_13.txt AC 192 ms 13160 KiB
random_14.txt AC 148 ms 12984 KiB
random_15.txt AC 131 ms 13112 KiB
random_16.txt AC 99 ms 13116 KiB
random_17.txt AC 190 ms 13092 KiB
random_18.txt AC 159 ms 13112 KiB
random_19.txt AC 133 ms 12972 KiB