# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205667 | Kastanda | Rope (JOI17_rope) | C++11 | 33 ms | 47352 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of The Queen
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 1000006;
int n, m, A[N], C[N], S[N * 2];
vector < int > V[N][2];
inline void Add(int i, int val)
{
S[i += N] = val;
for (; i; i >>= 1)
S[i >> 1] = max(S[i], S[i ^ 1]);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++)
{
scanf("%d", &A[i]);
C[A[i]] ++;
for (int j = 0; j <= 1; j ++)
{
int nxt = i + 1 - (i ^ j & 1) * 2;
if (A[nxt] && A[nxt] != A[i])
V[A[i]][j].push_back(A[nxt]);
}
Add(A[i], 1);
}
for (int c = 1; c <= m; c ++)
{
int Mn = n - C[c];
Add(c, -C[c]);
for (int j = 0; j <= 1; j ++)
{
for (int a : V[c][j])
Add(a, -1);
Mn = min(Mn, n - C[c] - S[1]);
for (int a : V[c][j])
Add(a, 1);
}
Add(c, C[c]);
printf("%d\n", Mn);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |