Submission #66983579


Source Code Expand

// 綺麗に解きなおし

#include <bits/stdc++.h>
using namespace std;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int n, q;
  cin >> n >> q;

  vector<int> a(q);
  for (int i=0; i<q; i++) {
    cin >> a.at(i);
  }

  //////////////// 出力変数定義 ////////////////

  vector<int> result(q);

  //////////////////// 処理 ////////////////////

  // 0マス目やn+1マス目もあると思って、
  // このマスと右隣りは色が違います、という場所の一覧
  set<int> borders;

  // 前から順に処理
  for (int i=0; i<q; i++) {

    // コードの書きやすさのため、取り出しておく
    int num = a.at(i);

    // 左隣りとの色関係
    // もともと同じ色だったなら違う色に、もともと違う色だったなら同じ色に
    if (borders.count(num-1)) {
      borders.erase(num-1);
    } else {
      borders.emplace(num-1);
    }

    // 右隣りとの色関係
    // もともと同じ色だったなら違う色に、もともと違う色だったなら同じ色に
    if (borders.count(num)) {
      borders.erase(num);
    } else {
      borders.emplace(num);
    }

    // 連続黒エリアの倍だけ、色の境界があるはず
    // つまり答えはbordersの要素数の半分
    result.at(i) = borders.size()/2;

  }

  //////////////////// 出力 ////////////////////

  for (size_t i=0; i<result.size(); i++) {
    cout << result.at(i) << endl;
  }

  //////////////////// 終了 ////////////////////

  return 0;

}

Submission Info

Submission Time
Task C - Black Intervals
User wightou
Language C++ 23 (gcc 12.2)
Score 350
Code Size 1659 Byte
Status AC
Exec Time 820 ms
Memory 31088 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 29
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.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
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3492 KiB
example_01.txt AC 1 ms 3484 KiB
example_02.txt AC 1 ms 3460 KiB
hand_00.txt AC 558 ms 7012 KiB
hand_01.txt AC 554 ms 6984 KiB
hand_02.txt AC 746 ms 31088 KiB
hand_03.txt AC 516 ms 7072 KiB
hand_04.txt AC 1 ms 3460 KiB
hand_05.txt AC 523 ms 7056 KiB
random_00.txt AC 701 ms 7320 KiB
random_01.txt AC 559 ms 7116 KiB
random_02.txt AC 820 ms 13156 KiB
random_03.txt AC 673 ms 7016 KiB
random_04.txt AC 663 ms 7016 KiB
random_05.txt AC 659 ms 7056 KiB
random_06.txt AC 727 ms 7800 KiB
random_07.txt AC 687 ms 7300 KiB
random_08.txt AC 695 ms 12824 KiB
random_09.txt AC 628 ms 13620 KiB
random_10.txt AC 723 ms 8948 KiB
random_11.txt AC 659 ms 7104 KiB
random_12.txt AC 810 ms 12656 KiB
random_13.txt AC 720 ms 7768 KiB
random_14.txt AC 729 ms 8292 KiB
random_15.txt AC 683 ms 7376 KiB
random_16.txt AC 655 ms 6976 KiB
random_17.txt AC 818 ms 13244 KiB
random_18.txt AC 625 ms 7052 KiB
random_19.txt AC 709 ms 7644 KiB