/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 400010
using namespace std;
struct segment{
int cnt[51];
};
segment t[4 * 100010];
int massiv[100010];
int next[100010];
segment mergee(segment &one, segment &two)
{
segment three;
for(int i = 1; i <= 50; i++)
{
three.cnt[i] = max(one.cnt[i], two.cnt[i]);
}
return three;
}
void build(int v, int l, int r)
{
if(l == r)
{
for(int i = 0; i <= 50; i++)t[v].cnt[i] = 0;
t[v].cnt[massiv[l]] = 1;
return ;
}
int mid = l + (r - l) / 2;
build(v * 2, l, mid);
build(v * 2 + 1, mid + 1, r);
t[v] = mergee(t[v * 2], t[v * 2 + 1]);
}
void update(int v, int l, int r, int pos, int x)
{
if(l == r)
{
t[v].cnt[massiv[l]] = 0;
massiv[l] = x;
t[v].cnt[massiv[l]] = 1;
return ;
}
int mid = l + (r - l) / 2;
if(pos <= mid) update(v * 2, l, mid, pos, x);
else update(v * 2 + 1, mid + 1, r, pos, x);
t[v] = mergee(t[v * 2], t[v * 2 + 1]);
}
segment query(int v, int l, int r, int nac, int konec)
{
if(l > konec || r < nac)
{
segment tmp;
for(int i = 0; i <= 50; i++)tmp.cnt[i] = 0;
return tmp;
}
if(l >= nac && r <= konec)return t[v];
int mid = l + (r - l) / 2;
segment one = query(v * 2, l, mid, nac, konec);
segment two = query(v * 2 + 1, mid + 1, r, nac, konec);
return mergee(one, two);
}
int n, k , m;
int main(){
FAST_READ;
cin.tie(0);
cout.tie(0);
cin >> n >> k >> m;
for(int i = 1; i <= n; i++)
{
cin >> massiv[i];
}
build(1, 1, n);
while(m--)
{
int t;
cin >> t;
if(t == 2)
{
int ans = INT_MAX;;
for(int i = 1; i <= n; i++)
{
int l = i;
int r = n;
while(l <= r)
{
int mid = l + (r - l) / 2;
segment res = query(1, 1, n, i, mid);
int cnt = 0;
for(int i = 1; i <= k; i++)
{
cnt += res.cnt[i];
}
if(cnt != k)
{
l = mid + 1;
}
else
{
ans = min(ans, mid - i + 1);
r = mid - 1;
}
}
}
cout << (ans == INT_MAX ? -1 : ans) << endl;
}
else
{
int x, y;
cin >> x >> y;
update(1, 1, n, x, y);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3063 ms |
1876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3049 ms |
2900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
3540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3074 ms |
13396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3077 ms |
26692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3077 ms |
26520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3084 ms |
26688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
26708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3079 ms |
53000 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3076 ms |
52980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |