답안 #1041592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041592 2024-08-02T06:02:11 Z vjudge1 Tenis (COI19_tenis) C++17
30 / 100
500 ms 12004 KB
#include<bits/stdc++.h>

using namespace std;

#define INF INT_MAX
const int N = 100'000 + 100, M = (2 << 17) + 10;
int n, q, p[3][N];
int R[N][3], seg[M][3][3];

void modify(int p, int Ra[3], int idx, int s = 1, int e = n + 1, int v = 1)
{
  if(p < s || e <= p) return;
  if(e - s == 1)
    {
      for(int i = 0; i < 3; i++)
	seg[v][idx][i] = Ra[i];
      return;
    }
  int mid = (s + e) / 2, lc = 2 * v, rc = lc + 1;
  modify(p, Ra, idx, s, mid, lc);
  modify(p, Ra, idx, mid, e, rc);
  
  for(int i = 0; i < 3; i++)
    seg[v][idx][i] = min(seg[lc][idx][i], seg[rc][idx][i]);
}

void get(int l, int idx, int out[], int r = n + 1, int s = 1, int e = n + 1, int v = 1)
{
  if(r <= s || e <= l) return;
  if(l <= s && e <= r) {
    for(int i = 0; i < 3; i++)
      out[i] = min(out[i], seg[v][idx][i]);
    return;
  }
  int mid = (s + e) / 2, lc = 2 * v, rc = lc + 1;
  get(l, idx, out, r, s, mid, lc), get(l, idx, out, r, mid, e, rc);
}

int BEST(int X) {
  return min(R[X][0], min(R[X][1], R[X][2]));
}

void update(int X)
{
  for(int i = 0; i < 3; i ++)
    modify(R[X][i], R[X], i);
}

int query(int X)
{
  int BR[3] = {};
  for(int i = 0; i < 3; i++)
    BR[i] = R[X][i];

  while(true)
    {
      int prv[] = {BR[0], BR[1], BR[2]};

      for(int i = 0; i < 3; i ++)
	{
	  int bc[3] = {INF, INF, INF};
	  get(prv[i], 0, bc);
	  for(int j = 0; j < 3; j++)
	    BR[j] = min(BR[j], bc[j]);
	}
      
      bool same = true;
      for(int i = 0; i < 3; i ++)
	same &= (prv[i] == BR[i]);
      
      if(same) break;
    }
  
  return min(BR[0], min(BR[1], BR[2]));
}

int main()
{
  cin >> n >> q;

  for(int j = 0; j < 3; j++)
    for(int i = 1; i <= n; i ++) {
      cin >> p[j][i];
      R[p[j][i]][j] = i;
    }

  for(int i = 1; i <= n; i ++)
    update(i);

  while(q--)
    {
      int t;
      cin >> t;
      if(t == 1)
	{
	  int X;
	  cin >> X;
	  int bestposs = query(X);
	  cout << (bestposs == 1 ? "DA" : "NE") << '\n';
	}
      else
	{
	  int P, A, B;
	  cin >> P >> A >> B;
	  P--;
	  int ra = R[A][P], rb = R[B][P]; 
	  swap(p[P][ra], p[P][rb]);
	  swap(R[A][P], R[B][P]);
	  update(A);
	  update(B);
	}
    }
  
  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2500 KB Output is correct
13 Correct 99 ms 11884 KB Output is correct
14 Correct 115 ms 11972 KB Output is correct
15 Correct 107 ms 11860 KB Output is correct
16 Correct 117 ms 11856 KB Output is correct
17 Correct 124 ms 11936 KB Output is correct
18 Correct 104 ms 11856 KB Output is correct
19 Correct 141 ms 11860 KB Output is correct
20 Correct 87 ms 11856 KB Output is correct
21 Correct 138 ms 11992 KB Output is correct
22 Correct 114 ms 11860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2500 KB Output is correct
13 Correct 99 ms 11884 KB Output is correct
14 Correct 115 ms 11972 KB Output is correct
15 Correct 107 ms 11860 KB Output is correct
16 Correct 117 ms 11856 KB Output is correct
17 Correct 124 ms 11936 KB Output is correct
18 Correct 104 ms 11856 KB Output is correct
19 Correct 141 ms 11860 KB Output is correct
20 Correct 87 ms 11856 KB Output is correct
21 Correct 138 ms 11992 KB Output is correct
22 Correct 114 ms 11860 KB Output is correct
23 Execution timed out 1064 ms 12004 KB Time limit exceeded
24 Halted 0 ms 0 KB -