#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
struct Hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 100005;
const int LG = 21;
int n,m;
vector<ii> p;
vector<ll> x, y, c;
ii s[2];
int Q;
int sign(ll x)
{
if (x < 0) return -1;
if (x == 0) return 0;
return 1;
}
ll cross(ll x1, ll y1, ll x2, ll y2)
{
return x1 * y2 - x2 * y1;
}
ll cross(const ii& p1, const ii& p2)
{
return cross(p1.F, p1.S, p2.F, p2.S);
}
ii operator-(ii& p1, ii& p2)
{
return {p1.F - p2.F, p1.S - p2.S};
}
int sideOf(ii& p1, ii& p2, ii& p3) // 1=right, 0 = on line, -1 = left
{
return sign(cross(p1 - p2, p3 - p2));
}
bool isect(int i, int j)
{
int side1 = sideOf(s[0], p[i], p[j]);
int side2 = sideOf(p[i], s[1], p[j]);
int sidet = sideOf(s[0], p[i], s[1]);
return side1 == side2 && side2 == sidet;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
p.resize(n);
x.resize(n);
y.resize(n);
c.resize(n);
forn(i, 0, n)
{
cin >> x[i] >> y[i] >> c[i];
p[i] = {x[i], y[i]};
c[i]--;
}
forn(i, 0, 2) cin >> s[i].F >> s[i].S;
int ans[m][m]{};
forn(i, 0, n) forn(j, 0, n)
{
if (c[i] == c[j]) continue;
if (isect(i, j)) ans[c[i]][c[j]]++;
}
cin>>Q;
forn(z,0,Q)
{
int u,v; cin>>u>>v; u--; v--;
cout << ans[u][v] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
600 KB |
Output is correct |
2 |
Correct |
89 ms |
600 KB |
Output is correct |
3 |
Correct |
97 ms |
684 KB |
Output is correct |
4 |
Correct |
103 ms |
5456 KB |
Output is correct |
5 |
Correct |
140 ms |
36948 KB |
Output is correct |
6 |
Correct |
73 ms |
35676 KB |
Output is correct |
7 |
Correct |
71 ms |
35676 KB |
Output is correct |
8 |
Correct |
31 ms |
604 KB |
Output is correct |
9 |
Correct |
25 ms |
604 KB |
Output is correct |
10 |
Correct |
25 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4042 ms |
2136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
600 KB |
Output is correct |
2 |
Correct |
89 ms |
600 KB |
Output is correct |
3 |
Correct |
97 ms |
684 KB |
Output is correct |
4 |
Correct |
103 ms |
5456 KB |
Output is correct |
5 |
Correct |
140 ms |
36948 KB |
Output is correct |
6 |
Correct |
73 ms |
35676 KB |
Output is correct |
7 |
Correct |
71 ms |
35676 KB |
Output is correct |
8 |
Correct |
31 ms |
604 KB |
Output is correct |
9 |
Correct |
25 ms |
604 KB |
Output is correct |
10 |
Correct |
25 ms |
604 KB |
Output is correct |
11 |
Execution timed out |
4042 ms |
2136 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |