Submission #16923085
Source Code Expand
Copy
#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));
}
Submission Info
Submission Time |
|
Task |
A - Reachable Towns |
User |
hamayanhamayan |
Language |
C++ (GCC 9.2.1 with AC Library) |
Score |
300 |
Code Size |
2044 Byte |
Status |
AC |
Exec Time |
94 ms |
Memory |
11056 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
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 |
Case Name |
Status |
Exec Time |
Memory |
example_00 |
AC |
8 ms |
3644 KB |
example_01 |
AC |
2 ms |
3680 KB |
manyperm_00 |
AC |
90 ms |
6528 KB |
manyperm_01 |
AC |
90 ms |
6500 KB |
manyperm_02 |
AC |
89 ms |
6596 KB |
manyperm_03 |
AC |
88 ms |
6576 KB |
max_random_00 |
AC |
80 ms |
6284 KB |
max_random_01 |
AC |
80 ms |
6312 KB |
random_00 |
AC |
54 ms |
5292 KB |
random_01 |
AC |
63 ms |
6260 KB |
small_00 |
AC |
6 ms |
3720 KB |
small_01 |
AC |
2 ms |
3616 KB |
small_02 |
AC |
2 ms |
3660 KB |
small_03 |
AC |
3 ms |
3672 KB |
small_04 |
AC |
2 ms |
3788 KB |
small_05 |
AC |
2 ms |
3680 KB |
small_06 |
AC |
3 ms |
3664 KB |
small_07 |
AC |
1 ms |
3672 KB |
small_08 |
AC |
3 ms |
3616 KB |
small_09 |
AC |
2 ms |
3684 KB |
special1_00 |
AC |
94 ms |
11056 KB |
special1_01 |
AC |
64 ms |
6228 KB |
special1_02 |
AC |
27 ms |
4220 KB |
special1_03 |
AC |
71 ms |
6284 KB |