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<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;
if(ans < *st[a[x]].upper_bound(x))
update(x - 1, ans - x + 1);
else
update(x - 1, inf);
}
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 |
---|
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... |