結果

問題 No.2292 Interval Union Find
ユーザー SSRSSSRS
提出日時 2023-05-05 22:20:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 741 ms / 5,000 ms
コード長 2,057 bytes
コンパイル時間 4,837 ms
コンパイル使用メモリ 174,948 KB
実行使用メモリ 22,300 KB
最終ジャッジ日時 2023-08-15 04:46:40
合計ジャッジ時間 30,518 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 300 ms
4,380 KB
testcase_05 AC 425 ms
4,380 KB
testcase_06 AC 296 ms
4,380 KB
testcase_07 AC 413 ms
4,384 KB
testcase_08 AC 428 ms
4,380 KB
testcase_09 AC 428 ms
4,380 KB
testcase_10 AC 396 ms
4,384 KB
testcase_11 AC 381 ms
4,380 KB
testcase_12 AC 439 ms
4,380 KB
testcase_13 AC 339 ms
4,384 KB
testcase_14 AC 354 ms
4,380 KB
testcase_15 AC 367 ms
4,384 KB
testcase_16 AC 351 ms
4,384 KB
testcase_17 AC 400 ms
4,380 KB
testcase_18 AC 576 ms
22,300 KB
testcase_19 AC 670 ms
22,232 KB
testcase_20 AC 741 ms
22,064 KB
testcase_21 AC 621 ms
14,328 KB
testcase_22 AC 628 ms
14,308 KB
testcase_23 AC 622 ms
14,276 KB
testcase_24 AC 629 ms
14,388 KB
testcase_25 AC 627 ms
14,380 KB
testcase_26 AC 626 ms
14,368 KB
testcase_27 AC 629 ms
14,484 KB
testcase_28 AC 629 ms
14,288 KB
testcase_29 AC 625 ms
14,292 KB
testcase_30 AC 628 ms
14,424 KB
testcase_31 AC 632 ms
14,620 KB
testcase_32 AC 623 ms
14,356 KB
testcase_33 AC 631 ms
14,392 KB
testcase_34 AC 629 ms
14,648 KB
testcase_35 AC 629 ms
14,284 KB
testcase_36 AC 624 ms
14,448 KB
testcase_37 AC 625 ms
14,572 KB
testcase_38 AC 625 ms
14,348 KB
testcase_39 AC 626 ms
14,312 KB
testcase_40 AC 628 ms
14,400 KB
testcase_41 AC 228 ms
4,380 KB
testcase_42 AC 235 ms
4,380 KB
testcase_43 AC 243 ms
4,384 KB
testcase_44 AC 276 ms
4,380 KB
testcase_45 AC 271 ms
4,384 KB
testcase_46 AC 287 ms
4,380 KB
testcase_47 AC 327 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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);
        }
        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;
      int ans = 1;
      auto itr = prev(mp.upper_bound(v));
      if ((*itr).second == 1){
        ans += (*next(itr)).first - v;
      }
      itr = prev(mp.lower_bound(v));
      if ((*itr).second == 1){
        ans += v - (*itr).first;
      }
      cout << ans << endl;
    }
  }
}
0