题解:P14175 【MX-X23-T5】向死存魏
P14175 【MX-X23-T5】向死存魏
好题!但是代码太难写了。
令 3 x 的答案。考虑怎么求出
首先这个在询问前显然可以预处理出来。具体的,令 3 x,如果
接下来只需要考虑操作
我的代码写了
for(int i = n, cnt = 0; i >= 1; i--)
{
if(!LCR[a[i]])
cnt++;
LCR[a[i]] = i, S1.modify(1, 1, V, a[i], a[i], i);
if(cnt != V)
S2.modify(1, 1, n, i, i, INT_MAX);
else
{
int mx = S1.mx[1];
// std::cout << mx << ' ';
S2.modify(1, 1, n, i, i, mx);
}
}
// /*
for(int i = 1; i <= m; i++)
{
int op = qy[i].op, l = qy[i].l, r = qy[i].r, x = qy[i].x;
if(op == 2)
{
N++;
continue;
}
if(op == 1)
{
// /*
auto L = s[x].lower_bound(l), R = s[x].upper_bound(r);
S2.modify(1, 1, n, *prev(L) + 1, (*R) - 1, *R);
// /*
std::vector<int> vec;
for(auto it = L; it != R; it++)
vec.pb(*it);
for(auto it : vec)
s[x].erase(it);
// */
}
else
{
// /*
int ans = S2.query(1, 1, n, l, l);
// std::cout << ans << ' ' << N << ' ';
if(ans > N) ans = -1;
printf("%d\n", ans);
// */
}
}
::::