QOJ.ac

QOJ

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

#22490. Fotografie di mucche

Statistics

Farmer John vuole foto dell'intera mandria di $N$ mucche, $1 \le N \le 100,000$, numeri $1..N$, per vantarsi con gli amici.

Il giorno della foto corrono per formare una fila arbitraria, posizione $i$ con $c_{i}$, $1 \le c_{i} \le N$. Lui ha idee sull'ordine.

FJ ritiene che Mucca $i$ solo a sinistra di $i+1$ per ogni $i$, $1 \le i \le N-1$, e $N$ solo a sinistra di $1$. Ovviamente nessuna a sinistra della prima, più a sinistra.

Affamate per la cena promessa dopo foto, lui vuole velocità. Seguono male istruzioni: sceglie coppia adiacente e scambia una volta al minuto. Quanto per ordine accettabile?

Cinque mucche iniziali:

     Sinistra           Destra
        3  5  4  2  1

Prima scambia seconda coppia:

        3  4  5  2 1

Poi la più a destra:

        3  4  5  1  2

Ordine accettabile in due minuti soltanto.

Input

  • Riga $1$: un intero $N$.

  • Righe $2..N+1$: riga $i+1$, numero $c_{i}$ della mucca $i$.

Output

  • Riga $1$: tempo minimo in minuti per ordine adeguato.

Esempi

Input 1

5
3
5
4
2
1

Output 1

2

Nota

Autore del problema: Travis, 2010

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.