#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define vi vector<ll>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ld long double
#define pii pair<ll, ll>
#define mt make_tuple
#define mn(a, b) a = min(a, b)
#define mx(a, b) a = max(a, b)
using namespace std;
const ll INF = (ll)2e9;
const ll inf = (ll)2e18;
const ld eps = (ld)1e-8;
const ll mod = (ll)10007;
const ll MAXN = (ll)1e4 + 1;
const ll MAXC = (ll)1e6 + 1;
const ll MAXE = (ll)1000;
const ll MAXLOG = 21;
const ll maxlen = (ll)1e5;
const ll asci = (ll)256;
const ll block = 480;
const ld PI = acos(-1);
const ld e = 2.7182818284;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
template <class T>
istream& operator >>(istream &in, vector<T> &arr){
for (T &cnt : arr) {
in >> cnt;
}
return in;
};
ll k;
struct nums{
vector<pii> p, s;
ll ans = INF;
nums() {}
nums(ll pos, ll x) {
p.push_back(mp(x, pos));
s.push_back(mp(x, pos));
}
nums(vector<pii> p, vector<pii> s, ll ans): p(p), s(s), ans(ans) {}
};
nums merge(nums a, nums b) {
vector<pii> p = a.p;
vi used(k);
for (ll i = 0; i < p.size(); ++i) {
used[p[i].first] = 1;
}
for (ll i = 0; i < b.p.size(); ++i) {
if (!used[b.p[i].first]) p.push_back(b.p[i]);
used[b.p[i].first] = 1;
}
vector<pii> s = b.s;
used.assign(k, 0);
for (ll i = 0; i < s.size(); ++i) {
used[s[i].first] = 1;
}
for (ll i = 0; i < a.s.size(); ++i) {
if (!used[a.s[i].first]) s.push_back(a.s[i]);
used[a.s[i].first] = 1;
}
vi cnt(k, 0);
ll ost = k;
ll ans = INF;
for (ll i = 0; i < b.p.size(); ++i) cnt[b.p[i].first]++, ost--;
ll l = 0, r = b.p.size() - 1;
for (; l < a.s.size() && r > -1; ++l) {
cnt[a.s[l].first]++;
if (cnt[a.s[l].first] == 1) ost--;
while (r > -1 && cnt[b.p[r].first] > 1) {
r--; cnt[b.p[r].first]--;
}
if (!ost) ans = mn(ans, b.p[r].second - a.s[l].second + 1);
}
return nums(p, s, ans);
}
struct stree{
vector<nums> t; ll n;
void build(ll v, ll tl, ll tr, vi &a) {
if (tl + 1 == tr) {
t[v] = nums(tl, a[tl]);
return;
}
ll tm = (tl + tr) / 2;
build(2 * v, tl, tm, a);
build(2 * v + 1, tm, tr, a);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
stree(vi &a): n(a.size()) {
t.resize(4 * n);
build(1, 0, n, a);
}
void upd(ll v, ll tl, ll tr, ll pos, ll x) {
if (tl + 1 == tr) {
t[v] = nums(pos, x);
return;
}
ll tm = (tl + tr) / 2;
if (pos < tm) upd(2 * v, tl, tm, pos, x);
else upd(2 * v + 1, tm, tr, pos, x);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
ll ans() {
return t[1].ans;
}
};
void solve() {
ll n, q; cin >> n >> k >> q;
vi a(n); cin >> a;
for (ll i = 0; i < n; ++i) a[i]--;
stree t(a);
while (q--) {
ll type; cin >> type;
if (type == 1) {
ll p, v; cin >> p >> v;
p--, v--;
t.upd(1, 0, n, p, v);
} else {
ll otv = t.ans();
if (otv == INF) cout << "-1\n";
else cout << otv << "\n";
}
}
}
signed main() {
srand(time(0));
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif
cout.precision(30);
solve();
return 0;
}
Compilation message
nekameleoni.cpp: In function 'nums merge(nums, nums)':
nekameleoni.cpp:68:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < p.size(); ++i) {
~~^~~~~~~~~~
nekameleoni.cpp:71:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < b.p.size(); ++i) {
~~^~~~~~~~~~~~
nekameleoni.cpp:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < s.size(); ++i) {
~~^~~~~~~~~~
nekameleoni.cpp:80:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < a.s.size(); ++i) {
~~^~~~~~~~~~~~
nekameleoni.cpp:87:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < b.p.size(); ++i) cnt[b.p[i].first]++, ost--;
~~^~~~~~~~~~~~
nekameleoni.cpp:89:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; l < a.s.size() && r > -1; ++l) {
~~^~~~~~~~~~~~
nekameleoni.cpp:95:23: warning: operation on 'ans' may be undefined [-Wsequence-point]
if (!ost) ans = mn(ans, b.p[r].second - a.s[l].second + 1);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
3328 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
3456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
5880 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
14336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
28 ms |
25728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
21376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
33144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
111 ms |
66168 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
57 ms |
48504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |