Submission #75208562
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>struct monsutaa_s {int id, X, Y;};/*角度が違う → ±2角度は同じなのでID順 → ±1*/int cmp(const void* x, const void* y) {struct monsutaa_s a = *(const struct monsutaa_s*)x, b = *(const struct monsutaa_s*)y;long long judge;if (a.Y <= 0 && b.Y > 0) return -2;if (a.Y > 0 && b.Y <= 0) return 2;if (a.Y == 0 && b.Y == 0) {if (a.X > 0 && b.X < 0) return -2;if (a.X < 0 && b.X > 0) return 2;}judge = (long long)a.X * b.Y - (long long)b.X * a.Y;if (judge != 0) return ((judge > 0) - (judge < 0)) * 2;return (a.id > b.id) - (a.id < b.id);}int N, Q;struct monsutaa_s ms[212345];int A[212345], B[212345];int same_left[212345], same_right[212345];int id_to_pos[212345];int main(void) {int i;if (scanf("%d%d", &N, &Q) != 2) return 1;for (i = 0; i < N; i++) {if (scanf("%d%d", &ms[i].X, &ms[i].Y) != 2) return 1;ms[i].id = i + 1;}for (i = 0; i < Q; i++) {
#include <stdio.h>
#include <stdlib.h>
struct monsutaa_s {
int id, X, Y;
};
/*
角度が違う → ±2
角度は同じなのでID順 → ±1
*/
int cmp(const void* x, const void* y) {
struct monsutaa_s a = *(const struct monsutaa_s*)x, b = *(const struct monsutaa_s*)y;
long long judge;
if (a.Y <= 0 && b.Y > 0) return -2;
if (a.Y > 0 && b.Y <= 0) return 2;
if (a.Y == 0 && b.Y == 0) {
if (a.X > 0 && b.X < 0) return -2;
if (a.X < 0 && b.X > 0) return 2;
}
judge = (long long)a.X * b.Y - (long long)b.X * a.Y;
if (judge != 0) return ((judge > 0) - (judge < 0)) * 2;
return (a.id > b.id) - (a.id < b.id);
}
int N, Q;
struct monsutaa_s ms[212345];
int A[212345], B[212345];
int same_left[212345], same_right[212345];
int id_to_pos[212345];
int main(void) {
int i;
if (scanf("%d%d", &N, &Q) != 2) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d%d", &ms[i].X, &ms[i].Y) != 2) return 1;
ms[i].id = i + 1;
}
for (i = 0; i < Q; i++) {
if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
}
qsort(ms, N, sizeof(*ms), cmp);
for (i = 0; i < N; i++) {
id_to_pos[ms[i].id] = i;
}
same_left[0] = 0;
for (i = 1; i < N; i++) {
same_left[i] = cmp(&ms[i - 1], &ms[i]) / 2 == 0 ? same_left[i - 1] : i;
}
same_right[N - 1] = N - 1;
for (i = N - 2; i >= 0; i--) {
same_right[i] = cmp(&ms[i], &ms[i + 1]) / 2 == 0 ? same_right[i + 1] : i;
}
for (i = 0; i < Q; i++) {
int apos = id_to_pos[A[i]], bpos = id_to_pos[B[i]];
int aid = same_left[apos], bid = same_right[bpos];
if (cmp(&ms[apos], &ms[bpos]) / 2 <= 0) {
printf("%d\n", bid - aid + 1);
} else {
printf("%d\n", (N - aid) + (bid + 1));
}
}
return 0;
}
/*
とりあえず原点からX軸の正の方向に向かう線を基準とし、ソート
外積っぽい何かで大小関係を判定できるはず
o--> (x1, y1) = (1, 0)
|
v (x2, y2) = (0, -1)
x1*y2 - x2*y1 = -1 - 0 = -1
このとき、(x1, y1) のほうが前
*/
Submission Info
| Submission Time | |
|---|---|
| Task | E - Laser Takahashi |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 450 |
| Code Size | 2004 Byte |
| Status | AC |
| Exec Time | 105 ms |
| Memory | 8064 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 05_killer_00.txt, 05_killer_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 1740 KiB |
| 00_sample_01.txt | AC | 0 ms | 1576 KiB |
| 00_sample_02.txt | AC | 0 ms | 1664 KiB |
| 01_random_00.txt | AC | 38 ms | 4160 KiB |
| 01_random_01.txt | AC | 84 ms | 7124 KiB |
| 01_random_02.txt | AC | 87 ms | 7084 KiB |
| 01_random_03.txt | AC | 4 ms | 2080 KiB |
| 01_random_04.txt | AC | 89 ms | 7472 KiB |
| 01_random_05.txt | AC | 103 ms | 7952 KiB |
| 01_random_06.txt | AC | 104 ms | 8064 KiB |
| 01_random_07.txt | AC | 103 ms | 8032 KiB |
| 01_random_08.txt | AC | 104 ms | 8032 KiB |
| 01_random_09.txt | AC | 104 ms | 8032 KiB |
| 02_random2_00.txt | AC | 104 ms | 7972 KiB |
| 02_random2_01.txt | AC | 104 ms | 7984 KiB |
| 02_random2_02.txt | AC | 104 ms | 7980 KiB |
| 02_random2_03.txt | AC | 105 ms | 7896 KiB |
| 02_random2_04.txt | AC | 105 ms | 7988 KiB |
| 02_random2_05.txt | AC | 103 ms | 8024 KiB |
| 02_random2_06.txt | AC | 103 ms | 7952 KiB |
| 02_random2_07.txt | AC | 104 ms | 7972 KiB |
| 02_random2_08.txt | AC | 103 ms | 8016 KiB |
| 02_random2_09.txt | AC | 103 ms | 7904 KiB |
| 03_random3_00.txt | AC | 101 ms | 7960 KiB |
| 03_random3_01.txt | AC | 97 ms | 7956 KiB |
| 03_random3_02.txt | AC | 95 ms | 8056 KiB |
| 03_random3_03.txt | AC | 92 ms | 7956 KiB |
| 03_random3_04.txt | AC | 83 ms | 8012 KiB |
| 04_handmade_00.txt | AC | 52 ms | 8024 KiB |
| 04_handmade_01.txt | AC | 53 ms | 8028 KiB |
| 04_handmade_02.txt | AC | 22 ms | 3232 KiB |
| 05_killer_00.txt | AC | 98 ms | 7952 KiB |
| 05_killer_01.txt | AC | 99 ms | 7948 KiB |