답안 #586672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586672 2022-06-30T14:22:52 Z MilosMilutinovic Tenis (COI19_tenis) C++14
51 / 100
500 ms 15152 KB
/**
 *    author:  wxhtzdy
 *    created: 30.06.2022 15:33:08
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, q;
  cin >> n >> q;
  vector<vector<int>> a(n, vector<int>(3));
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      --x;  
      a[x][j] = i;
    }
  }    
  vector<int> lzy(8 * n);
  vector<int> mn(8 * n);
  function<void(int)> push = [&](int node) {
    mn[node + node] += lzy[node];
    mn[node + node + 1] += lzy[node];
    lzy[node + node] += lzy[node];
    lzy[node + node + 1] += lzy[node];
    lzy[node] = 0;
  };                
  function<void(int, int, int, int, int, int)> modify = [&](int node, int l, int r, int ll, int rr, int v) {
    push(node);
    if (l > r || l > rr || r < ll) {
      return;
    }          
    if (ll <= l && r <= rr) {
      mn[node] += v;
      lzy[node] += v;
      push(node);
      return;
    }
    push(node);
    int mid = l + r >> 1;
    modify(node + node, l, mid, ll, rr, v);
    modify(node + node + 1, mid + 1, r, ll, rr, v);
    mn[node] = min(mn[node + node], mn[node + node + 1]);
  };                                
  function<int(int, int, int)> walk = [&](int node, int l, int r) {
    if (l == r) {
      return l;
    }
    push(node);
    int mid = l + r >> 1;
    if (mn[node + node] == 0) {
      return walk(node + node, l, mid);
    } else {
      return walk(node + node + 1, mid + 1, r);
    }
  };
  for (int i = 0; i < n; i++) {
    modify(1, 0, n - 1, i, i, i + 1);
  }
  function<void(int)> Add = [&](int i) {
    int mx = 0;
    for (int j = 0; j < 3; j++) {
      mx = max(mx, a[i][j]);
    }
    modify(1, 0, n - 1, mx, n - 1, -1);
  };
  function<void(int)> Rem = [&](int i) {
    int mx = 0;
    for (int j = 0; j < 3; j++) {
      mx = max(mx, a[i][j]);
    }
    modify(1, 0, n - 1, mx, n - 1, +1);
  };
  for (int i = 0; i < n; i++) {
    Add(i);
  }
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int i;
      cin >> i;               
      --i;       
      cout << (walk(1, 0, n - 1) >= max({a[i][0], a[i][1], a[i][2]}) ? "DA" : "NE") << '\n';
    } else {
      int p, i, j;
      cin >> p >> i >> j;
      --p; --i; --j;
      Rem(i);
      Rem(j);
      swap(a[i][p], a[j][p]);
      Add(i);
      Add(j);
    }
  }
  return 0;
}

Compilation message

tenis.cpp: In lambda function:
tenis.cpp:44:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     int mid = l + r >> 1;
      |               ~~^~~
tenis.cpp: In lambda function:
tenis.cpp:54:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 198 ms 13816 KB Output is correct
14 Correct 210 ms 13828 KB Output is correct
15 Correct 188 ms 13644 KB Output is correct
16 Correct 196 ms 13664 KB Output is correct
17 Correct 262 ms 13720 KB Output is correct
18 Correct 265 ms 13716 KB Output is correct
19 Correct 213 ms 13792 KB Output is correct
20 Correct 193 ms 13788 KB Output is correct
21 Correct 245 ms 13692 KB Output is correct
22 Correct 219 ms 13792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 14828 KB Output is correct
2 Correct 256 ms 14736 KB Output is correct
3 Correct 275 ms 14796 KB Output is correct
4 Correct 250 ms 14740 KB Output is correct
5 Correct 323 ms 14740 KB Output is correct
6 Correct 293 ms 14880 KB Output is correct
7 Correct 284 ms 14820 KB Output is correct
8 Correct 289 ms 14864 KB Output is correct
9 Correct 277 ms 14832 KB Output is correct
10 Correct 275 ms 14668 KB Output is correct
11 Correct 249 ms 14724 KB Output is correct
12 Correct 240 ms 14612 KB Output is correct
13 Correct 262 ms 14732 KB Output is correct
14 Correct 234 ms 14732 KB Output is correct
15 Correct 238 ms 14984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 198 ms 13816 KB Output is correct
14 Correct 210 ms 13828 KB Output is correct
15 Correct 188 ms 13644 KB Output is correct
16 Correct 196 ms 13664 KB Output is correct
17 Correct 262 ms 13720 KB Output is correct
18 Correct 265 ms 13716 KB Output is correct
19 Correct 213 ms 13792 KB Output is correct
20 Correct 193 ms 13788 KB Output is correct
21 Correct 245 ms 13692 KB Output is correct
22 Correct 219 ms 13792 KB Output is correct
23 Correct 243 ms 14828 KB Output is correct
24 Correct 256 ms 14736 KB Output is correct
25 Correct 275 ms 14796 KB Output is correct
26 Correct 250 ms 14740 KB Output is correct
27 Correct 323 ms 14740 KB Output is correct
28 Correct 293 ms 14880 KB Output is correct
29 Correct 284 ms 14820 KB Output is correct
30 Correct 289 ms 14864 KB Output is correct
31 Correct 277 ms 14832 KB Output is correct
32 Correct 275 ms 14668 KB Output is correct
33 Correct 249 ms 14724 KB Output is correct
34 Correct 240 ms 14612 KB Output is correct
35 Correct 262 ms 14732 KB Output is correct
36 Correct 234 ms 14732 KB Output is correct
37 Correct 238 ms 14984 KB Output is correct
38 Correct 451 ms 15000 KB Output is correct
39 Correct 325 ms 14680 KB Output is correct
40 Correct 428 ms 15136 KB Output is correct
41 Correct 383 ms 14860 KB Output is correct
42 Correct 349 ms 14992 KB Output is correct
43 Correct 466 ms 15148 KB Output is correct
44 Correct 326 ms 14868 KB Output is correct
45 Correct 359 ms 14912 KB Output is correct
46 Correct 282 ms 14820 KB Output is correct
47 Correct 331 ms 14960 KB Output is correct
48 Correct 309 ms 14752 KB Output is correct
49 Correct 336 ms 15008 KB Output is correct
50 Correct 302 ms 14880 KB Output is correct
51 Correct 367 ms 14988 KB Output is correct
52 Execution timed out 524 ms 15152 KB Time limit exceeded
53 Halted 0 ms 0 KB -