#include<bits/stdc++.h>
using namespace std;
const int N = 100'000 +10, K = 51, inf = 1'000'000'000;
int n, k, q, a[N], val[N];
set<int> st[K];
multiset<int> mi;
void update(int x, int ans)
{
auto it = mi.find(val[x]);
if(it != mi.end())
mi.erase(it);
val[x] = ans;
mi.insert(val[x]);
}
void process(int x)
{
int ans = x;
for(int i = 1; i <= k; i ++)
if(i != a[x])
ans = max(ans, *st[i].upper_bound(x));
if(ans < *st[a[x]].upper_bound(x))
ans = ans - x + 1;
else
ans = inf;
update(x, ans);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
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), st[i].insert(-inf);
for(int i = 1; i <= n; i ++)
process(i);
while(q--)
{
int t;
cin >> t;
if(t == 2)
{
int ans = *mi.begin();
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);
vector<pair<int, int> > vec(k + 1);
for(int i = 1; i <= k; i ++)
{
auto it = st[i].upper_bound(p);
it--;
vec[i].first = *it;
it++;
vec[i].second = *it;
}
for(int i = 1; i <= k; i ++)
{
if(vec[i].first == -inf) continue;
int ans = vec[i].first;
for(int j = 1; j <= k; j++)
{
if(vec[j].first >= vec[i].first)
ans = max(vec[j].first, ans);
else
ans = max(vec[j].second, ans);
}
if(ans < vec[i].second)
ans = 1 + ans - vec[i].first;
else
ans = inf;
update(vec[i].first, ans);
}
auto it = st[x].find(p);
it--;
if(*it > 0)
process(*it);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
588 ms |
2780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
855 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1138 ms |
5460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1366 ms |
8016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1449 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1716 ms |
11596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1805 ms |
11640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |