#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define ppi pair<pii, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=2005;
const ll maxm=1e5+5;
const double PI=acos(-1);
ll pw(ll x, ll p, ll m=mod){
if (p < 0) return 0;
ll ret=1;
while (p>0){
if (p&1){
ret*=x;
ret%=m;
}
x*=x;
x%=m;
p>>=1;
}
return ret;
}
ll inv(ll a, ll m=mod){
return pw(a,m-2,m);
}
vector<bool> ex(16);
struct Point{
int x, y;
};
int dis2(Point a, Point b){
return SQ(a.x-b.x)+SQ(a.y-b.y);
}
struct Circ{
Point a;
int r, typ, id;
};
bool cmpc(Circ a, Circ b){
return a.r<b.r;
}
struct Pair{
int a, b;
int r; // when it will overlap
};
bool cmpp(Pair a, Pair b){
return a.r<b.r;
}
struct Quer{
int r;
int pos, id;
};
bool cmpq(Quer a, Quer b){
return a.r<b.r;
}
vector<int> par(maxn), msk(maxn);
int fin(int a){
if (a == par[a]) return a;
return par[a] = fin(par[a]);
}
void merg(int a, int b){
a = fin(a); b = fin(b);
par[a] = b;
msk[b] |= msk[a];
ex[msk[b]] = 1;
}
int n, q, mx, my;
vector<Circ> vc, tmp;
vector<Pair> pr;
vector<Quer> quer;
vector<string> ans(maxm);
bool ex2(int a, int b){
if (a == 1 && b == 3){
REP(i, 16){
if (ex[i] && __builtin_popcount(i) >= 2 && (i != 9 && i != 6)) return 0;
}
}
else {
REP(i, 16){
if (ex[i] && __builtin_popcount(i) >= 2 && (i != 12 && i != 3)) return 0;
}
}
return 1;
}
bool ex1(int a, int b){
// a < b; a and b share an edge
if (b-a == 2) return ex2(a, b);
int typ;
if (a == 1 && b == 2) typ = 2;
if (a == 2 && b == 3) typ = 1;
if (a == 3 && b == 4) typ = 0;
if (a == 1 && b == 4) typ = 3;
REP(i, 16){
if (!ex[i]) continue;
if (i&(1<<typ)){
if (i != (1<<typ)) return 0;
}
}
return 1;
}
signed main(){
IOS();
ex[0] = 1;
cin>>n>>q>>mx>>my;
REP(i, n){
par[i] = i;
}
tmp = vector<Circ> (n);
REP(i, n){
cin>>tmp[i].a.x>>tmp[i].a.y>>tmp[i].r;
tmp[i].id = i;
}
REP(i, n){
vc.pb({tmp[i].a, (my-tmp[i].a.y-tmp[i].r)/2+1, 1, tmp[i].id});
vc.pb({tmp[i].a, (mx-tmp[i].a.x-tmp[i].r)/2+1, 2, tmp[i].id});
vc.pb({tmp[i].a, (tmp[i].a.y-tmp[i].r)/2+1, 4, tmp[i].id});
vc.pb({tmp[i].a, (tmp[i].a.x-tmp[i].r)/2+1, 8, tmp[i].id});
}
REP(i, n){
FOR(j, i+1, n){
int tt = dis2(tmp[i].a, tmp[j].a);
int l = 1, r = 1000000000,mid;
while(l < r){
mid = (l+r)>>1;
if (tmp[i].r+tmp[j].r+2*mid > 2000000000 || SQ(tmp[i].r+tmp[j].r+2*mid) > tt){
r = mid;
}
else {
l = mid+1;
}
}
pr.pb({i, j, l});
}
}
quer = vector<Quer> (q);
REP(i, q){
cin>>quer[i].r>>quer[i].pos;
quer[i].id = i;
}
sort(ALL(vc), cmpc); sort(ALL(pr), cmpp); sort(ALL(quer), cmpq);
/*
// woo
REP(i, SZ(vc)){
if (vc[i].r <= quer[0].r){
msk[vc[i].id] |= vc[i].typ;
ex[msk[vc[i].id]] = 1;
}
}
REP(i, SZ(pr)){
if (pr[i].r <= quer[0].r){
merg(pr[i].a, pr[i].b);
}
}
string ret;
REP1(i, quer[0].pos-1){
if (ex1(i, quer[0].pos)) ret += (char)(i+'0');
}
ret += (char)(quer[0].pos+'0');
FOR(i, quer[0].pos+1, 5){
if (ex1(quer[0].pos, i)) ret += (char)(i+'0');
}
cout<<ret<<endl;
// woo
*/
int pa = 0, pb = 0;
REP(i, q){
while(pa < SZ(vc) && vc[pa].r <= quer[i].r){
msk[fin(vc[pa].id)] |= vc[pa].typ;
ex[msk[fin(vc[pa].id)]] = 1;
pa++;
}
while(pb < SZ(pr) && pr[pb].r <= quer[i].r){
merg(pr[pb].a, pr[pb].b);
pb++;
}
string ou;
REP1(j, quer[i].pos-1){
if (ex1(j, quer[i].pos)) ou += (char)(j+'0');
}
ou += (char)(quer[i].pos + '0');
FOR(j, quer[i].pos+1, 5){
if (ex1(quer[i].pos, j)) ou += (char)(j+'0');
}
ans[quer[i].id] = ou;
}
REP(i, q) cout<<ans[i]<<endl;
}
/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
5 1
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
2 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
602 ms |
54236 KB |
Output is correct |
2 |
Correct |
616 ms |
54056 KB |
Output is correct |
3 |
Correct |
607 ms |
54824 KB |
Output is correct |
4 |
Correct |
604 ms |
55592 KB |
Output is correct |
5 |
Correct |
617 ms |
55012 KB |
Output is correct |
6 |
Correct |
624 ms |
54312 KB |
Output is correct |
7 |
Correct |
576 ms |
54056 KB |
Output is correct |
8 |
Correct |
567 ms |
53388 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
6884 KB |
Output is correct |
2 |
Correct |
53 ms |
7908 KB |
Output is correct |
3 |
Correct |
41 ms |
7904 KB |
Output is correct |
4 |
Correct |
47 ms |
7904 KB |
Output is correct |
5 |
Correct |
46 ms |
7908 KB |
Output is correct |
6 |
Correct |
40 ms |
7924 KB |
Output is correct |
7 |
Correct |
39 ms |
7252 KB |
Output is correct |
8 |
Correct |
46 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
602 ms |
54236 KB |
Output is correct |
2 |
Correct |
616 ms |
54056 KB |
Output is correct |
3 |
Correct |
607 ms |
54824 KB |
Output is correct |
4 |
Correct |
604 ms |
55592 KB |
Output is correct |
5 |
Correct |
617 ms |
55012 KB |
Output is correct |
6 |
Correct |
624 ms |
54312 KB |
Output is correct |
7 |
Correct |
576 ms |
54056 KB |
Output is correct |
8 |
Correct |
567 ms |
53388 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
41 ms |
6884 KB |
Output is correct |
12 |
Correct |
53 ms |
7908 KB |
Output is correct |
13 |
Correct |
41 ms |
7904 KB |
Output is correct |
14 |
Correct |
47 ms |
7904 KB |
Output is correct |
15 |
Correct |
46 ms |
7908 KB |
Output is correct |
16 |
Correct |
40 ms |
7924 KB |
Output is correct |
17 |
Correct |
39 ms |
7252 KB |
Output is correct |
18 |
Correct |
46 ms |
7252 KB |
Output is correct |
19 |
Correct |
648 ms |
55560 KB |
Output is correct |
20 |
Correct |
645 ms |
54976 KB |
Output is correct |
21 |
Correct |
656 ms |
55792 KB |
Output is correct |
22 |
Correct |
646 ms |
56396 KB |
Output is correct |
23 |
Correct |
676 ms |
56332 KB |
Output is correct |
24 |
Correct |
647 ms |
55152 KB |
Output is correct |