Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.5 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓
Estadísticas

נגדיר את $\operatorname{mex}(S)$ כמספר השלם האי-שלילי הקטן ביותר שאינו מוכל ב-$S$.

למאיוי האצ'יקוג'י יש מערך $a$ המורכב מ-$n$ איברים שהיא רוצה למיין בסדר לא יורד. לשם כך, היא יכולה לבצע את הפעולה הבאה כל מספר של פעמים (אולי אפס):

  • לבחור מספר שלם $i \in [1, \operatorname{length}(a) - 2]$ ולהחליף את $a_i, a_{i+1}, a_{i+2}$ ב-$\operatorname{mex}$ שלהם. שימו לב שלאחר הפעלת פעולה זו, אורך המערך קטן ב-$2$.

מצאו את מספר הפעולות המינימלי שמאיוי צריכה לבצע כדי להפוך את המערך לממוין בסדר לא יורד. במקרה שהדבר בלתי אפשרי, הדפיסו $-1$.

קלט

השורה הראשונה של הקלט מכילה מספר שלם $n$ ($2 \le n \le 5 \cdot 10^5$) — אורך המערך $a$.

השורה הבאה מכילה $n$ מספרים שלמים $a_i$ ($0 \le a_i \le 10^9$) — איברי המערך $a$.

פלט

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

דוגמאות

קלט לדוגמה 1

3
4 1 3

פלט לדוגמה 1

1

קלט לדוגמה 2

9
3 0 2 2 3 0 4 7 8

פלט לדוגמה 2

2

קלט לדוגמה 3

2
4 3

פלט לדוגמה 3

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1662EditorialOpenNew Editorial for Problem #14434louyuxuanView
#372EditorialOpen题解jianglyView

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.