QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20767. הפרות המאוחדות של Farmer John

Statistics

הפרות המאוחדות של Farmer John (UCFJ) שולחות משלחת ל-International bOvine olympIad (IOI).

$N$ פרות משתתפות בבחירת המשלחת ($1 \leq N \leq 2 \cdot 10^5$). הן עומדות בשורה, והגזע של פרה $i$ הוא $b_i$.

המשלחת תהיה קטע רציף של לפחות שתי פרות: הפרות $l\ldots r$ עבור שלמים $l$ ו-$r$ המקיימים $1\le l<r\le N$. שתי הפרות בקצוות יוגדרו „מנהיגות”. כדי למנוע סכסוך בתוך גזע, כל מנהיגה חייבת להיות מגזע שונה משל כל שאר חברי המשלחת, מנהיגים או לא.

עזרו ל-UCFJ למצוא, מטעמי מס, את מספר הדרכים לבחור משלחת ל-IOI.

קלט

השורה הראשונה מכילה את $N$.

השורה השנייה מכילה $N$ שלמים $b_1,b_2,\ldots,b_N$, כל אחד בטווח $[1,N]$.

פלט

מספר המשלחות האפשריות בשורה אחת.

המספרים הגדולים עשויים לחייב טיפוסי שלמים של 64 סיביות (למשל long long ב-C/C++).

דוגמאות

קלט 1

7
1 2 3 4 3 2 5

פלט 1

13

הערה

כל משלחת מתאימה לאחד מזוגות המנהיגות הבאים:

$$(1,2),(1,3),(1,4),(1,7),(2,3),(2,4),(3,4),(4,5),(4,6),(4,7),(5,6),(5,7),(6,7).$$

תתי משימות

  • מקרי הבדיקה 1–3 מקיימים $N\le 100$.
  • מקרי הבדיקה 4–8 מקיימים $N\le 5000$.
  • למקרי הבדיקה 9–20 אין מגבלות נוספות.

קרדיט לבעיה: Benjamin Qi

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.