結果

問題 No.2292 Interval Union Find
ユーザー SSRSSSRS
提出日時 2023-05-05 21:55:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,122 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 177,464 KB
実行使用メモリ 22,272 KB
最終ジャッジ日時 2024-05-02 16:07:38
合計ジャッジ時間 27,819 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 431 ms
5,376 KB
testcase_06 AC 306 ms
5,376 KB
testcase_07 AC 414 ms
5,376 KB
testcase_08 AC 440 ms
5,376 KB
testcase_09 AC 448 ms
5,376 KB
testcase_10 AC 424 ms
5,376 KB
testcase_11 AC 399 ms
5,376 KB
testcase_12 AC 450 ms
5,376 KB
testcase_13 AC 356 ms
5,376 KB
testcase_14 AC 368 ms
5,376 KB
testcase_15 AC 387 ms
5,376 KB
testcase_16 AC 368 ms
5,376 KB
testcase_17 AC 418 ms
5,376 KB
testcase_18 AC 593 ms
22,144 KB
testcase_19 AC 673 ms
22,272 KB
testcase_20 AC 740 ms
22,144 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 626 ms
14,464 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 633 ms
14,336 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 631 ms
14,464 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  map<int, int> mp;
  mp[0] = 0;
  mp[N] = 0;
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    if (t == 1){
      int L, R;
      cin >> L >> R;
      for (int j : {L, R}){
        if (mp.count(j) == 0){
          auto itr = prev(mp.lower_bound(j));
          int x = (*itr).second;
          mp[j] = x;
        }
      }
      while (true){
        auto itr = mp.lower_bound(L);
        int p1 = (*itr).first;
        if (p1 == R){
          break;
        }
        mp.erase(itr);
      }
      mp[L] = 1;
      for (int j : {L, R}){
        auto itr = mp.lower_bound(j);
        if ((*itr).second == (*prev(itr)).second){
          mp.erase(itr);
        }
      }
    }
    if (t == 2){
      int L, R;
      cin >> L >> R;
      for (int j : {L, R}){
        if (mp.count(j) == 0){
          auto itr = prev(mp.lower_bound(j));
          int x = (*itr).second;
          mp[j] = x;
        }
      }
      while (true){
        auto itr = mp.lower_bound(L);
        int p1 = (*itr).first;
        if (p1 == R){
          break;
        }
        mp.erase(itr);
      }
      mp[L] = 0;
      for (int j : {L, R}){
        auto itr = mp.lower_bound(j);
        if ((*itr).second == (*prev(itr)).second){
          mp.erase(itr);
        }
      }
    }
    if (t == 3){
      int u, v;
      cin >> u >> v;
      if (u == v){
        cout << 1 << endl;
      } else {
        if (u > v){
          swap(u, v);
        }
        v--;
        auto itr = prev(mp.upper_bound(u));
        if ((*itr).second == 1 && (*next(itr)).first >= v){
          cout << 1 << endl;
        } else {
          cout << 0 << endl;
        }
      }
    }
    if (t == 4){
      int v;
      cin >> v;
      auto itr = prev(mp.lower_bound(v));
      if ((*itr).second == 0){
        if ((*next(itr)).first == v){
          cout << (*next(itr, 2)).first - (*next(itr)).first + 1 << endl;
        } else {
          cout << 1 << endl;
        }
      } else {
        cout << (*next(itr)).first - (*itr).first + 1 << endl;
      }
    }
  }
}
0