This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 100000
#define N_ (1 << 17)
#define M 50
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int aa[N], n, m;
int st[N_ * 2], iil[N_ * 2][M], iir[N_ * 2][M], kkl[N_ * 2], kkr[N_ * 2], n_;
void pul(int i) {
static int kk[M];
static char used[M];
int l = i << 1, r = l | 1, hl, hr, il, ir, m_;
st[i] = min(st[l], st[r]);
memset(kk, 0, m * sizeof *kk);
for (hr = 0; hr < kkr[l]; hr++) {
ir = iir[l][hr];
kk[aa[ir]]++;
}
m_ = m - kkr[l];
for (hl = 0, hr = kkr[l]; hl < kkl[r]; hl++) {
il = iil[r][hl];
if (kk[aa[il]]++ == 0)
m_--;
while (hr > 0 && m_ == 0)
if (--kk[aa[iir[l][--hr]]] == 0)
m_++;
if (hr < kkr[l])
st[i] = min(st[i], il - iir[l][hr] + 1);
}
memset(used, 0, m * sizeof *used), kkl[i] = 0;
for (hl = 0; hl < kkl[l]; hl++) {
il = iil[l][hl];
used[aa[il]] = 1, iil[i][kkl[i]++] = il;
}
for (hl = 0; hl < kkl[r]; hl++) {
il = iil[r][hl];
if (!used[aa[il]])
used[aa[il]] = 1, iil[i][kkl[i]++] = il;
}
memset(used, 0, m * sizeof *used), kkr[i] = 0;
for (hr = 0; hr < kkr[r]; hr++) {
ir = iir[r][hr];
used[aa[ir]] = 1, iir[i][kkr[i]++] = ir;
}
for (hr = 0; hr < kkr[l]; hr++) {
ir = iir[l][hr];
if (!used[aa[ir]])
used[aa[ir]] = 1, iir[i][kkr[i]++] = ir;
}
}
void build() {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 0; i < n_; i++) {
if (i < n)
iil[n_ + i][kkl[n_ + i]++] = iir[n_ + i][kkr[n_ + i]++] = i;
st[n_ + i] = i >= n || m != 1 ? INF : 1;
}
for (i = n_ - 1; i > 0; i--)
pul(i);
}
void update(int i, int a) {
aa[i] = a;
i += n_;
while (i > 1)
pul(i >>= 1);
}
int main() {
int q, i;
scanf("%d%d%d", &n, &m, &q);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]), aa[i]--;
build();
while (q--) {
int t;
scanf("%d", &t);
if (t == 2)
printf("%d\n", st[1] == INF ? -1 : st[1]);
else {
int a;
scanf("%d%d", &i, &a), i--, a--;
update(i, a);
}
}
return 0;
}
Compilation message (stderr)
nekameleoni.c: In function 'main':
nekameleoni.c:83:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | scanf("%d%d%d", &n, &m, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
nekameleoni.c:85:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf("%d", &aa[i]), aa[i]--;
| ^~~~~~~~~~~~~~~~~~~
nekameleoni.c:90:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
nekameleoni.c:96:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | scanf("%d%d", &i, &a), i--, a--;
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | 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... |