提出 #66600602
ソースコード 拡げる
#include <bits/stdc++.h>
//pair
#define int long long
#define PII pair <int, int>
#define PIII pair <int, PII>
//vector
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//other
#define gcd __gcd
#define x first
#define y second
using namespace std;
namespace lhz{
using T = int;
inline T read(){
T res = 0, f = 1;
char ch = getchar();
if(ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9')
res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return res * f;
}
inline void write(T n){
if (n < 0) putchar('-'), n *= -1;
if (n > 9) write(n / 10);
putchar(n % 10 + '0');
}
}
using ll = long long;
using db = double;
const int inf = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e8, N = 1e5 + 5;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono :: steady_clock :: now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
bool ep (const double a, const double b){
return fabs(a - b) > eps;
}
template <typename T>
void cmax (T &a, T b){
a = (a > b ? a : b);
}
template <typename T>
void cmin (T &a, T b){
a = (a < b ? a : b);
}
template <typename T>
void Swap (T &a, T &b){
a = a ^ b, b = a ^ b, a = a ^ b;
}
int qmi (int a, int n, int p){
int res = 1;
while (n){
if(n & 1) res = res * a % p;
a = a * a % p, n >>= 1;
}
return res;
}
int inv (int a, int p){
return qmi(a, p - 2, p);
}
int lcm (int a, int b){
return a * b / gcd(a, b);
}
int re (int a){
return (a ^ (-1)) + 1;
}
int sabs (int a){
return (a ^ (a >> 31)) - (a >> 31);
}
//#define int long long
int n, q;
int p[N], scc_cnt; // DSU
PII point[N];
priority_queue <PIII, vector <PIII> , greater <PIII>> heap; // distance
int dis (PII a, PII b){
return abs (a.x - b.x) + abs (a.y - b.y);
}
int find (int x){
return (p[x] == x ? x : (p[x] = find (p[x])));
}
void sovle (){
cin >> n >> q, scc_cnt = n;
for (int i = 1; i <= n; i ++ ) cin >> point[i].x >> point[i].y, p[i] = i;
for (int i = 1; i <= n; i ++ ) for (int j = i + 1; j <= n; j ++ ) heap.emplace (dis (point[i], point[j]), make_pair (i, j));
while (q -- ){
int op; cin >> op;
if (op == 1){
int a, b; cin >> a >> b;
point[ ++ n] = make_pair (a, b), scc_cnt ++ , p[n] = n;
for (int i = 1; i < n; i ++ ) heap.emplace (dis (point[i], point[n]), make_pair (i, n));
} else if (op == 2){
if (scc_cnt == 1){
cout << "-1\n";
continue;
}
int mn = inf;
// if (!q) cerr << heap.size () << '\n';
while (heap.size () && heap.top ().x <= mn) {
// if (!q) cerr << " --- " << mn << ' ' << heap.size () << ' ' << heap.top ().x << ' ';
PIII t = heap.top (); heap.pop ();
int fu = find (t.y.x), fv = find (t.y.y);
// cerr << fu << ' ' << fv << '\n';
if (fu != fv) mn = t.x, p[fv] = fu, scc_cnt -- ;
}
cout << mn << '\n';
} else {
int u, v; cin >> u >> v;
cout << (find (u) == find (v) ? "Yes\n" : "No\n");
}
// cout << " *** " << heap.size () << '\n';
}
}
#undef int
signed main (){
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
cin.tie(nullptr) -> sync_with_stdio(false);
int T = 1;
// cin >> T;
while(T -- ) sovle();
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
F - Connecting Points |
| ユーザ |
lhz_017 |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
0 |
| コード長 |
3638 Byte |
| 結果 |
WA |
| 実行時間 |
227 ms |
| メモリ |
199944 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3484 KiB |
| 01_test_00.txt |
AC |
49 ms |
52372 KiB |
| 01_test_01.txt |
AC |
51 ms |
52376 KiB |
| 01_test_02.txt |
AC |
207 ms |
199868 KiB |
| 01_test_03.txt |
AC |
54 ms |
52448 KiB |
| 01_test_04.txt |
AC |
110 ms |
101728 KiB |
| 01_test_05.txt |
AC |
118 ms |
101676 KiB |
| 01_test_06.txt |
AC |
74 ms |
52376 KiB |
| 01_test_07.txt |
AC |
50 ms |
52376 KiB |
| 01_test_08.txt |
AC |
76 ms |
52336 KiB |
| 01_test_09.txt |
AC |
70 ms |
52448 KiB |
| 01_test_10.txt |
AC |
69 ms |
52440 KiB |
| 01_test_11.txt |
AC |
110 ms |
101600 KiB |
| 01_test_12.txt |
AC |
49 ms |
52364 KiB |
| 01_test_13.txt |
AC |
50 ms |
52444 KiB |
| 01_test_14.txt |
AC |
206 ms |
199944 KiB |
| 01_test_15.txt |
AC |
52 ms |
52300 KiB |
| 01_test_16.txt |
AC |
110 ms |
101676 KiB |
| 01_test_17.txt |
AC |
113 ms |
101656 KiB |
| 01_test_18.txt |
AC |
75 ms |
52296 KiB |
| 01_test_19.txt |
AC |
51 ms |
52368 KiB |
| 01_test_20.txt |
AC |
76 ms |
52356 KiB |
| 01_test_21.txt |
AC |
66 ms |
52532 KiB |
| 01_test_22.txt |
AC |
70 ms |
52372 KiB |
| 01_test_23.txt |
AC |
111 ms |
101672 KiB |
| 01_test_24.txt |
AC |
227 ms |
52324 KiB |
| 01_test_25.txt |
AC |
138 ms |
52252 KiB |
| 01_test_26.txt |
AC |
101 ms |
52540 KiB |
| 01_test_27.txt |
AC |
83 ms |
52376 KiB |
| 01_test_28.txt |
AC |
136 ms |
52376 KiB |
| 01_test_29.txt |
AC |
106 ms |
52476 KiB |
| 01_test_30.txt |
AC |
107 ms |
52324 KiB |
| 01_test_31.txt |
AC |
74 ms |
52372 KiB |
| 01_test_32.txt |
AC |
96 ms |
52532 KiB |
| 01_test_33.txt |
AC |
93 ms |
52448 KiB |
| 01_test_34.txt |
AC |
78 ms |
52540 KiB |
| 01_test_35.txt |
AC |
76 ms |
52432 KiB |
| 01_test_36.txt |
AC |
84 ms |
52380 KiB |
| 01_test_37.txt |
AC |
76 ms |
52528 KiB |
| 01_test_38.txt |
AC |
75 ms |
52328 KiB |
| 01_test_39.txt |
AC |
73 ms |
52480 KiB |
| 01_test_40.txt |
AC |
111 ms |
101616 KiB |
| 01_test_41.txt |
AC |
73 ms |
52380 KiB |
| 01_test_42.txt |
AC |
126 ms |
101636 KiB |
| 01_test_43.txt |
WA |
1 ms |
3456 KiB |