提出 #16923085


ソースコード 拡げる

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N;
vector<tuple<int, int, int>> points;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) {
		int x, y; cin >> x >> y;
		points.push_back(make_tuple( x, y, i ));
	}
	sort(all(points));

	set<pair<int, int>> rest;
	dsu uf(N);
	rep(i, 0, N) {
		int x, y, id;
		tie(x, y, id) = points[i];
		while (0 < rest.size()) {
			auto ite = rest.lower_bound({ y, -1 });
			if (ite != rest.begin()) {
				ite--;
				uf.merge(ite->second, id);
				y = ite->first;
				rest.erase(ite);
			}
			else {
				break;
			}
		}
		rest.insert({ y, id });
	}

	rep(i, 0, N) printf("%d\n", uf.size(i));
}





提出情報

提出日時
問題 A - Reachable Towns
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1 with AC Library)
得点 300
コード長 2044 Byte
結果 AC
実行時間 94 ms
メモリ 11056 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 24
セット名 テストケース
Sample example_00, example_01
All example_00, example_01, manyperm_00, manyperm_01, manyperm_02, manyperm_03, max_random_00, max_random_01, random_00, random_01, small_00, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09, special1_00, special1_01, special1_02, special1_03
ケース名 結果 実行時間 メモリ
example_00 AC 8 ms 3644 KiB
example_01 AC 2 ms 3680 KiB
manyperm_00 AC 90 ms 6528 KiB
manyperm_01 AC 90 ms 6500 KiB
manyperm_02 AC 89 ms 6596 KiB
manyperm_03 AC 88 ms 6576 KiB
max_random_00 AC 80 ms 6284 KiB
max_random_01 AC 80 ms 6312 KiB
random_00 AC 54 ms 5292 KiB
random_01 AC 63 ms 6260 KiB
small_00 AC 6 ms 3720 KiB
small_01 AC 2 ms 3616 KiB
small_02 AC 2 ms 3660 KiB
small_03 AC 3 ms 3672 KiB
small_04 AC 2 ms 3788 KiB
small_05 AC 2 ms 3680 KiB
small_06 AC 3 ms 3664 KiB
small_07 AC 1 ms 3672 KiB
small_08 AC 3 ms 3616 KiB
small_09 AC 2 ms 3684 KiB
special1_00 AC 94 ms 11056 KiB
special1_01 AC 64 ms 6228 KiB
special1_02 AC 27 ms 4220 KiB
special1_03 AC 71 ms 6284 KiB