Task: | Järjestys |
Sender: | Kuha |
Submission time: | 2016-07-28 14:35:52 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.06 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.07 s | details |
#7 | ACCEPTED | 0.07 s | details |
#8 | ACCEPTED | 0.10 s | details |
#9 | ACCEPTED | 0.09 s | details |
#10 | ACCEPTED | 0.09 s | details |
Code
#include <bits/stdc++.h> #define ll long long #define INF 999999999 #define N (1<<17) #define M 1000000007 using namespace std; int v[2*N]; void ch (int n, int k) { k += N; v[k] = n; for (k /= 2; k >= 1; k /= 2) v[k] = max(v[2 * k], v[2 * k + 1]); } int sum (int n, int k) { k += N; n += N; int s = 0; while (n <= k) { if (n % 2 == 1) s = max(v[n++], s); if (k % 2 == 0) s = max(v[k--], s); n /= 2; k /= 2; } return s; } int main () { int n; cin>>n; int ans = 0; for (int i = 1; i <= n; i++) { int x; cin>>x; int q = sum(1, x - 1) + 1; ans = max(ans, q); ch(q, x); } cout<<n - ans<<endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
20 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: ACCEPTED
input |
---|
20 20 19 18 17 16 15 14 13 12 11 ... |
correct output |
---|
19 |
user output |
---|
19 |
Test 3
Verdict: ACCEPTED
input |
---|
20 12 2 14 4 5 6 7 8 9 10 11 1 13... |
correct output |
---|
4 |
user output |
---|
4 |
Test 4
Verdict: ACCEPTED
input |
---|
20 17 19 9 20 16 15 14 13 12 11 1... |
correct output |
---|
17 |
user output |
---|
17 |
Test 5
Verdict: ACCEPTED
input |
---|
20 14 17 6 2 1 18 3 10 15 5 7 8 4... |
correct output |
---|
11 |
user output |
---|
11 |
Test 6
Verdict: ACCEPTED
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 7
Verdict: ACCEPTED
input |
---|
100000 100000 99999 99998 99997 99996... |
correct output |
---|
99999 |
user output |
---|
99999 |
Test 8
Verdict: ACCEPTED
input |
---|
100000 1 31396 3 4 5 6 7 8 9 10 11 12... |
correct output |
---|
18136 |
user output |
---|
18136 |
Test 9
Verdict: ACCEPTED
input |
---|
100000 100000 99999 99998 99997 99996... |
correct output |
---|
99739 |
user output |
---|
99739 |
Test 10
Verdict: ACCEPTED
input |
---|
100000 64356 85816 57765 61431 4519 7... |
correct output |
---|
99377 |
user output |
---|
99377 |