Submission #128704

#TimeUsernameProblemLanguageResultExecution timeMemory
128704UtahaDragon 2 (JOI17_dragon2)C++14
100 / 100
3486 ms12384 KiB
/*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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...