#include<bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10, M = 2 << 17, K = 51, inf = 1'000'000'000;
int n, k, q, seg[M], a[N];
set<int> st[K];
void update(int x, int d, int s = 0, int e = n, int v = 1)
{
if(x < s || e <= x) return;
if(e - s == 1)
{
seg[v] = d;
return;
}
int mid = (s + e) / 2, lc = 2 * v, rc = lc + 1;
update(x, d, s, mid, lc);
update(x, d, mid, e, rc);
seg[v] = min(seg[lc], seg[rc]);
}
void process(int x) // idx is the
{
int ans = x;
for(int i = 1; i <= k; i ++)
if(i != a[x])
ans = max(ans, *st[i].upper_bound(x));
// cerr << x << ' ' << ans << endl;
update(x - 1, ans - x + 1);
}
int main()
{
cin >> n >> k >> q;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i ++)
st[a[i]].insert(i);
for(int i = 1; i <= k; i++)
st[i].insert(inf);
for(int i = 1; i <= n; i ++)
process(i);
while(q--)
{
int t;
cin >> t;
if(t == 2)
{
int ans = seg[1];
cout << (ans > n ? -1 : ans) << "\n";
}
else
{
int p, x;
cin >> p >> x;
st[a[p]].erase(p);
a[p] = x;
st[a[p]].insert(p);
for(int i = 1; i <= k; i ++)
{
auto it = st[i].upper_bound(p);
if(it != st[i].begin())
{
it--;
process(*it);
}
if(i == x && it != st[i].begin())
{
it--;
process(*it);
}
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
147 ms |
800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2089 ms |
1960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
4220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3031 ms |
3684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3056 ms |
4928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3066 ms |
4824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3031 ms |
7280 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
7252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |