#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
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--;
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
3152 KB |
Output is correct |
2 |
Correct |
9 ms |
3124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3916 KB |
Output is correct |
2 |
Correct |
29 ms |
3916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
4532 KB |
Output is correct |
2 |
Correct |
54 ms |
4516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
531 ms |
17476 KB |
Output is correct |
2 |
Correct |
1406 ms |
59548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
783 ms |
45252 KB |
Output is correct |
2 |
Correct |
1430 ms |
78648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1122 ms |
35128 KB |
Output is correct |
2 |
Correct |
1500 ms |
68312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1298 ms |
54340 KB |
Output is correct |
2 |
Correct |
1512 ms |
71700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1281 ms |
50532 KB |
Output is correct |
2 |
Correct |
1536 ms |
75712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1603 ms |
83016 KB |
Output is correct |
2 |
Correct |
1527 ms |
83140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1602 ms |
83028 KB |
Output is correct |
2 |
Correct |
1540 ms |
83144 KB |
Output is correct |