#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, K, Q;
const ll INF = 1e18;
struct Node{
ll ans;
vector<pair<ll, ll>> L, R;
Node(){}
Node(ll _ans, ll _k, ll _p){ans = _ans; L.push_back({1LL << _k, _p}); R.push_back({1LL << _k, _p});}
};
Node f(Node &p, Node &q){
Node ret; ret.ans = min(p.ans, q.ans);
for(ll i = p.R.size() - 1, j = 0; i >= 0 && j < q.L.size(); i--){
while(j < q.L.size() && (p.R[i].first | q.L[j].first) != (1LL << K) - 1) j++;
if(j < q.L.size()) ret.ans = min(ret.ans, q.L[j].second - p.R[i].second + 1);
}
ret.L = p.L, ret.R = q.R;
for(ll i = 0; i < q.L.size(); i++){
if((ret.L.back().first | q.L[i].first) > ret.L.back().first){
ret.L.push_back({ret.L.back().first | q.L[i].first, q.L[i].second});
}
}
for(ll i = 0; i < p.R.size(); i++){
if((ret.R.back().first | p.R[i].first) > ret.R.back().first){
ret.R.push_back({ret.R.back().first | p.R[i].first, p.R[i].second});
}
}
return ret;
}
Node T[400005];
void init(ll n, ll s, ll e){
if(s == e){
T[n] = Node(K == 1 ? 1 : INF, 0, s);
return;
}
ll m = (s + e) / 2;
init(n * 2, s, m); init(n * 2 + 1, m + 1, e);
T[n] = f(T[n * 2], T[n * 2 + 1]);
}
void update(ll n, ll s, ll e, ll k, ll v){
if(s == e){
T[n] = Node(K == 1 ? 1 : INF, v, s);
return;
}
ll m = (s + e) / 2;
if(k <= m) update(n * 2, s, m, k, v);
else update(n * 2 + 1, m + 1, e, k, v);
T[n] = f(T[n * 2], T[n * 2 + 1]);
}
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> K >> Q;
init(1, 1, N);
for(ll i = 1; i <= N; i++){
ll v; cin >> v; v--;
update(1, 1, N, i, v);
}
while(Q--){
ll op; cin >> op;
if(op == 1){
ll k, v; cin >> k >> v; v--;
update(1, 1, N, k, v);
} else {
cout << (T[1].ans > N ? -1 : T[1].ans) << '\n';
}
}
}
Compilation message
nekameleoni.cpp: In function 'Node f(Node&, Node&)':
nekameleoni.cpp:15:51: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(ll i = p.R.size() - 1, j = 0; i >= 0 && j < q.L.size(); i--){
| ~~^~~~~~~~~~~~
nekameleoni.cpp:16:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | while(j < q.L.size() && (p.R[i].first | q.L[j].first) != (1LL << K) - 1) j++;
| ~~^~~~~~~~~~~~
nekameleoni.cpp:17:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(j < q.L.size()) ret.ans = min(ret.ans, q.L[j].second - p.R[i].second + 1);
| ~~^~~~~~~~~~~~
nekameleoni.cpp:20:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(ll i = 0; i < q.L.size(); i++){
| ~~^~~~~~~~~~~~
nekameleoni.cpp:25:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(ll i = 0; i < p.R.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
23252 KB |
Output is correct |
2 |
Correct |
28 ms |
22980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
23724 KB |
Output is correct |
2 |
Correct |
44 ms |
23608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
24112 KB |
Output is correct |
2 |
Correct |
76 ms |
24140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
29640 KB |
Output is correct |
2 |
Correct |
1545 ms |
46188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1030 ms |
40732 KB |
Output is correct |
2 |
Correct |
1969 ms |
54648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1229 ms |
36596 KB |
Output is correct |
2 |
Correct |
2075 ms |
50368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1591 ms |
43520 KB |
Output is correct |
2 |
Correct |
1804 ms |
51840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1360 ms |
42428 KB |
Output is correct |
2 |
Correct |
1918 ms |
53632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1947 ms |
56588 KB |
Output is correct |
2 |
Correct |
1979 ms |
56396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1926 ms |
56572 KB |
Output is correct |
2 |
Correct |
1957 ms |
56376 KB |
Output is correct |