| Task: | Line Segment Intersection |
| Sender: | aalto26jh_027 |
| Submission time: | 2026-11-11 15:50:29 +0200 |
| Language: | C++ (C++23) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.08 s | details |
| #2 | ACCEPTED | 0.08 s | details |
| #3 | ACCEPTED | 0.10 s | details |
| #4 | ACCEPTED | 0.12 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.00 s | details |
Code
// #ifdef ONLINE_JUDGE
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #endif
#include "bits/stdc++.h"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i, a, b) for(__typeof(b) i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for(__typeof(a) i = a, _b = b; i >= _b; --i)
#define ALL(a) (a).begin(), (a).end()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define dq deque<int>
#define nend '\n'
using namespace std;
const ll inf = 1e18;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int MOD = 1e9 + 7;
const ll hashi = 2e9 + 11;
void init_code() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int side(ll ax, ll ay, ll bx, ll by, ll px, ll py) {
ll c=(bx-ax)*(py-ay)-(by-ay)*(px-ax);
return (c>0)-(c<0);
}
bool inBox(ll ax, ll ay, ll bx, ll by, ll px, ll py) {
return min(ax,bx)<=px && px<=max(ax,bx) && min(ay,by)<=py && py<=max(ay,by);
}
void solve() {
int t; cin >> t;
while (t--) {
ll x1,y1,x2,y2,x3,y3,x4,y4;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
int d1=side(x1,y1,x2,y2,x3,y3), d2=side(x1,y1,x2,y2,x4,y4);
int d3=side(x3,y3,x4,y4,x1,y1), d4=side(x3,y3,x4,y4,x2,y2);
bool ok=false;
if (d1*d2<0 && d3*d4<0) ok=true;
if (d1==0 && inBox(x1,y1,x2,y2,x3,y3)) ok=true;
if (d2==0 && inBox(x1,y1,x2,y2,x4,y4)) ok=true;
if (d3==0 && inBox(x3,y3,x4,y4,x1,y1)) ok=true;
if (d4==0 && inBox(x3,y3,x4,y4,x2,y2)) ok=true;
if (ok) YES; else NO;
}
}
int main() {
init_code();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 100000 9 7 1 8 8 -5 0 2 10 1 -1 2 -4 1 -7 3 10 2 -8 6 1 2 2 -1 -10 1 9 -7 4 -3 -5 0 ... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 100000 81 745 -967 768 -451 -490 -454... |
| correct output |
|---|
| NO NO YES NO YES ... |
| user output |
|---|
| NO NO YES NO YES ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 100000 492853 -452834 -657156 -282543... |
| correct output |
|---|
| YES YES NO YES YES ... |
| user output |
|---|
| YES YES NO YES YES ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100000 788522666 939776556 -831492125... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 1 1 6 6 6 4 4 1000000000 1000000... |
| correct output |
|---|
| YES |
| user output |
|---|
| YES |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1 -1000000000 1000000000 9999999... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
