#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;
auto itt = st[a[p]].insert(p).first;
int y = *(--itt);
if(y > 0)
process(y);
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(j == x && y >= vec[i].first)
ans = max(ans, y);
else 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);
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
620 ms |
2744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
911 ms |
6604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1161 ms |
5456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1422 ms |
8252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1319 ms |
7536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1669 ms |
11600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1840 ms |
11860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |