#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MAXK = 50;
vector<int> fen[50];
void update(int in, int val, int bt) {
in++;
while(in < MAXN) {
fen[bt][in]+=val;
in+=in&(-in);
}
}
long long query(int l, int bt) {
l++;
long long sum = 0;
while(l > 0) {
sum+=fen[bt][l];
l-=l&(-l);
}
return sum;
}
long long k;
bool check(int l, int r) {
bool c = true;
for(int i = 0;i<k;i++) {
if(!(query(r, i) - query(l-1, i)))c = false;
}
return c;
}
int main () {
srand(time(NULL));
long long n, m;
cin >> n >> k >> m;
for(int i = 0;i<50;i++) {
fen[i].resize(MAXN);
}
long long arr[n];
for(int i = 0;i<n;i++){
cin >> arr[i];
arr[i]--;
}
for(int i = 0;i<n;i++) {
update(i, 1, arr[i]);
}
while(m--) {
int type;
cin >> type;
if(type == 1) {
int p, v;
cin >> p >> v;
v--;p--;
update(p, -1, arr[p]);
arr[p] = v;
update(p, 1, arr[p]);
}
else {
int p1 = 0, p2 = 0;
int lo = k, hi = n;
long long ans = 1e9;
while(lo <= hi) {
int mid = (lo+hi)/2;
bool c = false;
for(int j = 0;j<20;j++) {
int l = rand()%(n-mid+1);
int r = l+mid-1;
if(check(l, r)){ans = min(ans, (long long)mid);c=true;}
}
if(c) {
hi = mid-1;
}
else {
lo = mid+1;
}
}
if(ans == 1e9)ans = -1;
cout << ans << "\n";
}
}
}
Compilation message
nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:57:8: warning: unused variable 'p1' [-Wunused-variable]
57 | int p1 = 0, p2 = 0;
| ^~
nekameleoni.cpp:57:16: warning: unused variable 'p2' [-Wunused-variable]
57 | int p1 = 0, p2 = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
147 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
385 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
2644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
3224 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
3012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
3412 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
3288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
3924 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
3976 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |