Submission #379950

#TimeUsernameProblemLanguageResultExecution timeMemory
379950AriaHPark (BOI16_park)C++11
0 / 100
349 ms89020 KiB
/** I can do this all day **/ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(),(x).end() #define F first #define S second #define Mp make_pair #define SZ(x) (int)x.size() #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout); const int N = 1e6 + 10; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 8e18; const int LOG = 22; ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); } ll n, m, w, h, X[N], Y[N], R[N], par[N], sz[N]; int get(int x) { return (x == par[x]? x : par[x] = get(par[x])); } void unify(int v, int u) { v = get(v), u = get(u); if(v == u) return; if(sz[u] > sz[v]) swap(u, v); par[u] = v; sz[v] += sz[u]; } pair < pll, int > Q[N]; vector < pair < ll, pll > > E; vector < int > Ans[N]; bool cmp(pair < pll, ll > a, pair < pll, ll > b) { return a.F < b.F; } int ok(int a, int b) { a += n; b += n; return (get(a) == get(b)); } int can(int a, int b) { if(a == b) return 1; if(a > b) swap(a, b); if(a == 1 && b == 2) { return (!(ok(1, 2) || ok(2, 4) || ok(2, 3))); } if(a == 1 && b == 3) { return (!(ok(1, 2) || ok(1, 3) || ok(2, 4) || ok(3, 4))); } if(a == 1 && b == 4) { return (!(ok(1, 2) || ok(1, 3) || ok(1, 4))); } if(a == 2 && b == 3) { return (!(ok(1, 3) || ok(2, 3) || ok(4, 3))); } if(a == 2 && b == 4) { return (!(ok(1, 3) || ok(1, 4) || ok(2, 3) || ok(2, 4))); } else { return (!(ok(1, 4) || ok(2, 4) || ok(3, 4))); } } int main() { for(int i = 0; i < N; i ++) sz[i] = 1, par[i] = i; scanf("%lld%lld%lld%lld", &n, &m, &w, &h); for(int i = 1; i <= n; i ++) { scanf("%lld%lld%lld", &X[i], &Y[i], &R[i]); E.push_back(Mp(X[i] - R[i], Mp(n + 1, i))); E.push_back(Mp(Y[i] - R[i], Mp(n + 2, i))); E.push_back(Mp(w - X[i] - R[i], Mp(n + 3, i))); E.push_back(Mp(h - Y[i] - R[i], Mp(n + 4, i))); for(int j = 1; j < i; j ++) { ll dx = abs(X[i] - X[j]), dy = abs(Y[i] - Y[j]); ll dist = ceil(sqrt(dx * dx + dy * dy)); E.push_back(Mp(dist - R[i] - R[j], Mp(i, j))); } } sort(all(E)); /*for(auto x : E) { printf("dist : %lld fir = %lld sec = %lld\n", x.F, x.S.F, x.S.S); } */ for(int i = 1; i <= m; i ++) { scanf("%lld%lld", &Q[i].F.F, &Q[i].F.S); Q[i].F.F *= 2; Q[i].S = i; } sort(Q + 1, Q + m + 1, cmp); int last = 0; for(int i = 1; i <= m; i ++) { ///printf("i = %d Q.F : %lld Q.S : %lld\n", i, Q[i].F.F, Q[i].F.S); while(last < SZ(E) && E[last].F <= Q[i].F.F) { unify(E[last].S.F, E[last].S.S); last ++; } for(int j = 1; j <= 4; j ++) { if(can(Q[i].F.S, j)) { Ans[Q[i].S].push_back(j); } } } for(int i = 1; i <= m; i ++) { for(auto x : Ans[i]) { printf("%d", x); } printf("\n"); } return 0; } /** test corner cases(n = 1?) watch for overflow or minus indices **/

Compilation message (stderr)

park.cpp: In function 'int main()':
park.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   95 |  scanf("%lld%lld%lld%lld", &n, &m, &w, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   98 |   scanf("%lld%lld%lld", &X[i], &Y[i], &R[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:118:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  118 |   scanf("%lld%lld", &Q[i].F.F, &Q[i].F.S);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...