Submission #555579

# Submission time Handle Problem Language Result Execution time Memory
555579 2022-05-01T08:12:36 Z computerbox Nekameleoni (COCI15_nekameleoni) C++14
0 / 140
3000 ms 52996 KB
/*
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];
int n, k , m;
segment mergee(segment &one, segment &two)
{
  segment three;
  for(int i = 1; i <= k; 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 <= k; 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 <= k; 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 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;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 1876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3099 ms 2900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3099 ms 3540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3086 ms 13636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 26964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 26828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3099 ms 26732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3094 ms 26708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3096 ms 52996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3095 ms 52952 KB Time limit exceeded
2 Halted 0 ms 0 KB -