Submission #128704

# Submission time Handle Problem Language Result Execution time Memory
128704 2019-07-11T08:33:25 Z Utaha Dragon 2 (JOI17_dragon2) C++14
100 / 100
3486 ms 12384 KB
/*input
4 2
0 1 1
0 -1 1
1 2 2
-6 1 2
-2 0 2 0
2
1 2
2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

inline ll sgn(ll n){
	return (n>=0)?1:-1;
}
inline pll operator-(pll A,pll B){return MP(A.F-B.F,A.S-B.S);}
inline ll cross(pll A,pll B){return A.F*B.S-A.S*B.F;}
inline bool cmp(pll A,pll B){
	if(sgn(A.S)==sgn(B.F)){
		if(cross(A,B)==0){
			if(A.S==0&&B.S==0&&A.F>0&&B.F<0) return 1;
			return 0;
		}
		return cross(A,B)>0;
	}
	else return sgn(A.S)>sgn(B.S);
}

ll x[maxn],y[maxn],type[maxn];
pll P,Q;

int a[maxn],b[maxn];

vector<pll> _1,_2;
int opp1[maxn],opp2[maxn];

vector<int> idx[maxn];

int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) cin>>x[i]>>y[i]>>type[i];
	REP(i,n) type[i]--;
	REP(i,n) idx[type[i]].pb(i);
	cin>>P.F>>P.S>>Q.F>>Q.S;

	REP(i,n){
		_1.pb(MP(x[i],y[i])-P);
		_2.pb(MP(x[i],y[i])-Q);
	}
	sort(ALL(_1));
	sort(ALL(_2));

	REP(i,n){
		a[i]=lower_bound(ALL(_1),MP(x[i],y[i])-P,cmp)-_1.begin();
		b[i]=lower_bound(ALL(_2),MP(x[i],y[i])-P,cmp)-_2.begin();
	}
	REP(i,n) opp1[i]=lower_bound(ALL(_1),MP(-_1[i].F,-_1[i].S),cmp)-_1.begin();
	REP(i,n) opp2[i]=lower_bound(ALL(_2),MP(-_2[i].F,-_2[i].S),cmp)-_2.begin();

	int q;
	cin>>q;
	while(q--){
		int f,g;
		cin>>f>>g;
		f--;g--;
		int ans=0;
		for(int i:idx[f]) for(int j:idx[g]){
			if(cross(P-MP(x[i],y[i]),Q-MP(x[i],y[i]))>0){
				if(cross(MP(x[i],y[i])-P,MP(x[j],y[j])-P)<0&&cross(MP(x[i],y[i])-Q,MP(x[j],y[j])-Q)>0) ans++;
			}
			else{
				if(cross(MP(x[i],y[i])-P,MP(x[j],y[j])-P)>0&&cross(MP(x[i],y[i])-Q,MP(x[j],y[j])-Q)<0) ans++;
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 7800 KB Output is correct
2 Correct 29 ms 7800 KB Output is correct
3 Correct 40 ms 7928 KB Output is correct
4 Correct 51 ms 8824 KB Output is correct
5 Correct 44 ms 8952 KB Output is correct
6 Correct 11 ms 7928 KB Output is correct
7 Correct 11 ms 7928 KB Output is correct
8 Correct 17 ms 7800 KB Output is correct
9 Correct 16 ms 7800 KB Output is correct
10 Correct 17 ms 7928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1420 ms 10640 KB Output is correct
2 Correct 3271 ms 10684 KB Output is correct
3 Correct 86 ms 10732 KB Output is correct
4 Correct 35 ms 10704 KB Output is correct
5 Correct 39 ms 11000 KB Output is correct
6 Correct 1357 ms 10600 KB Output is correct
7 Correct 1351 ms 10600 KB Output is correct
8 Correct 699 ms 10568 KB Output is correct
9 Correct 636 ms 10304 KB Output is correct
10 Correct 654 ms 10344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 7800 KB Output is correct
2 Correct 29 ms 7800 KB Output is correct
3 Correct 40 ms 7928 KB Output is correct
4 Correct 51 ms 8824 KB Output is correct
5 Correct 44 ms 8952 KB Output is correct
6 Correct 11 ms 7928 KB Output is correct
7 Correct 11 ms 7928 KB Output is correct
8 Correct 17 ms 7800 KB Output is correct
9 Correct 16 ms 7800 KB Output is correct
10 Correct 17 ms 7928 KB Output is correct
11 Correct 1420 ms 10640 KB Output is correct
12 Correct 3271 ms 10684 KB Output is correct
13 Correct 86 ms 10732 KB Output is correct
14 Correct 35 ms 10704 KB Output is correct
15 Correct 39 ms 11000 KB Output is correct
16 Correct 1357 ms 10600 KB Output is correct
17 Correct 1351 ms 10600 KB Output is correct
18 Correct 699 ms 10568 KB Output is correct
19 Correct 636 ms 10304 KB Output is correct
20 Correct 654 ms 10344 KB Output is correct
21 Correct 1425 ms 10560 KB Output is correct
22 Correct 3252 ms 10644 KB Output is correct
23 Correct 2649 ms 10792 KB Output is correct
24 Correct 771 ms 12044 KB Output is correct
25 Correct 84 ms 11932 KB Output is correct
26 Correct 94 ms 12384 KB Output is correct
27 Correct 41 ms 11624 KB Output is correct
28 Correct 41 ms 11816 KB Output is correct
29 Correct 3486 ms 12192 KB Output is correct
30 Correct 114 ms 12028 KB Output is correct
31 Correct 73 ms 12276 KB Output is correct
32 Correct 103 ms 12052 KB Output is correct
33 Correct 722 ms 12112 KB Output is correct
34 Correct 77 ms 12156 KB Output is correct
35 Correct 73 ms 12188 KB Output is correct
36 Correct 79 ms 12316 KB Output is correct
37 Correct 77 ms 12308 KB Output is correct
38 Correct 1136 ms 12192 KB Output is correct
39 Correct 983 ms 12204 KB Output is correct
40 Correct 765 ms 12172 KB Output is correct
41 Correct 3248 ms 12348 KB Output is correct
42 Correct 2385 ms 12344 KB Output is correct
43 Correct 2216 ms 12156 KB Output is correct
44 Correct 2327 ms 11116 KB Output is correct
45 Correct 1184 ms 11032 KB Output is correct
46 Correct 785 ms 11112 KB Output is correct
47 Correct 1460 ms 11248 KB Output is correct
48 Correct 954 ms 10908 KB Output is correct
49 Correct 609 ms 11116 KB Output is correct