QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#21160. כיסוח השדה

Statistics

Farmer John אמין בכל ניהול החווה חוץ מכיסוח בזמן. הוא מזיז את המכסחת רק פעם ביום. ביום1 מתחיל ב־$(x_1, y_1)$ וביום $d$ מכסח לאורך קטע ישר עד $(x_d, y_d)$, אופקית או אנכית במפה הדו־ממדית: $x_d = x_{d-1}$ או $y_d = y_{d-1}$. הכיוונים מתחלפים בימים עוקבים.

הוא איטי כל כך שהדשא עשוי לצמוח מחדש לפני הסיום. דשא שנכסח ביום $d$ חוזר ביום $d + T$. אם המסלול חוצה מסלול שכוסח לפחות $T$ ימים קודם, הוא מכסח שוב אותה נקודה. כדי לשפר את האסטרטגיה הגרועה רוצה לספור זאת.

ספרו חציות עם קטע קודם שבו הדשא כבר צמח. ספרו רק חציות „מאונכות”: נקודה משותפת לקטע אופקי ואנכי שאינה קצה של אף אחד מהם.

קלט

השורה הראשונה מכילה $N$ ($2 \leq N \leq 100,000$) ו־$T$ ($1 \leq T \leq N$, $T$ זוגי).

$N$ השורות הבאות מתארות מיקומים בימים $1 \ldots N$. שורה $i$ מכילה שלמים $x_i$ ו־$y_i$, לא שליליים ולכל היותר $1,000,000,000$.

פלט

הדפיסו את מספר נקודות החציה המתוארות, שבהן FJ מכסח שוב דשא שכוסח וצמח מחדש.

דוגמאות

קלט 1

7 4
0 10
10 10
10 5
3 5
3 12
6 12
6 3

פלט 1

1

הערה

ביום7 חוצה קטע שכוסח ביום2, וזה נספר. יתר החציות אינן נספרות.

הערה: מגבלות מורחבות של5 שניות למקרה (10 ל־Python ו־Java) ו־512 MB זיכרון.

מחברי הבעיה: Chad Waters ו־Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.