Submission #27324

# Submission time Handle Problem Language Result Execution time Memory
27324 2017-07-12T08:41:33 Z 윤교준(#1144) Dragon 2 (JOI17_dragon2) C++11
15 / 100
4000 ms 5788 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)im='-'==*p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define rb(x) ((x)&(-(x)))
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MAXN (30005)
#define MAXQ (100005)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }

vector<int> V[MAXN];
vector<int> VQ;
pll P[MAXN]; int Z[MAXN];
int A[MAXQ], B[MAXQ], C[MAXQ];
int Ans[MAXQ];
pll PB, PC;
int N, M, Q;

bool f(int a, int b) {
	ll l = ccw(P[a], PB, P[b]), r = ccw(P[a], PC, P[b]);
	ll tl = ccw(P[a], PB, PC);
	if(0 <= tl) return 0 <= l && r <= 0;
	return 0 <= r && l <= 0;
}
int main() {
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%lld%lld%d", &P[i].first, &P[i].second, &Z[i]);
	for(int i = 1; i <= N; i++) V[Z[i]].pb(i);
	scanf("%lld%lld%lld%lld", &PB.first, &PB.second, &PC.first, &PC.second);
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++) scanf("%d%d", &A[i], &B[i]);
	for(int i = 1; i <= Q; i++) VQ.pb(A[i]*MAXN + B[i]);
	sorv(VQ); univ(VQ);
	for(int i = 1; i <= Q; i++) {
		int t = A[i]*MAXN + B[i];
		C[i] = (int)(lower_bound(allv(VQ), t) - VQ.begin());
	}
	for(int qi = 0; qi < sz(VQ); qi++) {
		int q = VQ[qi];
		int a = q/MAXN, b = q%MAXN;
		for(int i : V[a]) for(int j : V[b]) {
			Ans[qi] += f(i, j);
		}
	}
	for(int i = 1; i <= Q; i++) printf("%d\n", Ans[C[i]]);
	return 0;
}

Compilation message

dragon2.cpp: In function 'int main()':
dragon2.cpp:40:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
dragon2.cpp:41:83: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%lld%lld%d", &P[i].first, &P[i].second, &Z[i]);
                                                                                   ^
dragon2.cpp:43:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld%lld", &PB.first, &PB.second, &PC.first, &PC.second);
                                                                         ^
dragon2.cpp:44:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
                 ^
dragon2.cpp:45:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= Q; i++) scanf("%d%d", &A[i], &B[i]);
                                                         ^
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4876 KB Output is correct
2 Correct 36 ms 4876 KB Output is correct
3 Correct 43 ms 5008 KB Output is correct
4 Correct 66 ms 5764 KB Output is correct
5 Correct 69 ms 5788 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 19 ms 4876 KB Output is correct
9 Correct 19 ms 4876 KB Output is correct
10 Correct 19 ms 4876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1969 ms 5192 KB Output is correct
2 Execution timed out 4000 ms 5156 KB Execution timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4876 KB Output is correct
2 Correct 36 ms 4876 KB Output is correct
3 Correct 43 ms 5008 KB Output is correct
4 Correct 66 ms 5764 KB Output is correct
5 Correct 69 ms 5788 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 19 ms 4876 KB Output is correct
9 Correct 19 ms 4876 KB Output is correct
10 Correct 19 ms 4876 KB Output is correct
11 Correct 1969 ms 5192 KB Output is correct
12 Execution timed out 4000 ms 5156 KB Execution timed out
13 Halted 0 ms 0 KB -