Submission #1038833

# Submission time Handle Problem Language Result Execution time Memory
1038833 2024-07-30T08:09:07 Z vjudge1 Nekameleoni (COCI15_nekameleoni) C++17
42 / 140
3000 ms 7284 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 100'000 + 10, M = 2 << 17, K = 51, inf = 1'000'000'000;
int n, k, q, seg[M], a[N];
set<int> st[K];

void update(int x, int d, int s = 0, int e = n, int v = 1)
{
  if(x < s || e <= x) return;
  if(e - s == 1)
    {
      seg[v] = d;
      return;
    }
  int mid = (s + e) / 2, lc = 2 * v, rc = lc + 1;
  update(x, d, s, mid, lc);
  update(x, d, mid, e, rc);
  seg[v] = min(seg[lc], seg[rc]);
}

void process(int x) // idx is the
{
  int ans = x;
  for(int i = 1; i <= k; i ++)
    if(i != a[x])
      ans = max(ans, *st[i].upper_bound(x));
  // cerr << x << ' ' << ans << endl;
  if(ans < *st[a[x]].upper_bound(x))
    update(x - 1, ans - x + 1);
  else
    update(x - 1, inf);
}


int main()
{
  cin >> n >> k >> q;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  
  for(int i = 1; i <= n; i ++)
    st[a[i]].insert(i);
  
  for(int i = 1; i <= k; i++)
    st[i].insert(inf);

  for(int i = 1; i <= n; i ++)
    process(i);
  
		    
  while(q--)
    {
      int t;
      cin >> t;
      if(t == 2)
	{
	  int ans = seg[1];
	  cout << (ans > n ? -1 : ans) << "\n";
	}
      else
	{
	  int p, x;
	  cin >> p >> x;

	  st[a[p]].erase(p);
	   a[p] = x;
	  st[a[p]].insert(p);
	  
	  for(int i = 1; i <= k; i ++)
	    {
	      auto it = st[i].upper_bound(p);
	      if(it != st[i].begin())
		{
		  it--;
		  process(*it);
		}
	      if(i == x && it != st[i].begin())
		{
		  it--;
		  process(*it);
		}
	    }
	}
    }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 600 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 600 KB Output is correct
2 Correct 51 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 604 KB Output is correct
2 Correct 150 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1980 ms 2148 KB Output is correct
2 Execution timed out 3035 ms 5784 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3044 ms 4176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3033 ms 3828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 4896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 4692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 7284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3040 ms 7252 KB Time limit exceeded
2 Halted 0 ms 0 KB -