Submission #586677

# Submission time Handle Problem Language Result Execution time Memory
586677 2022-06-30T14:26:05 Z MilosMilutinovic Tenis (COI19_tenis) C++14
100 / 100
406 ms 15052 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) {
    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);
    modify(1, 0, n - 1, max({a[i][0], a[i][1], a[i][2]}), n - 1, -1);
  }
  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;
      modify(1, 0, n - 1, max({a[i][0], a[i][1], a[i][2]}), n - 1, +1);
      modify(1, 0, n - 1, max({a[j][0], a[j][1], a[j][2]}), n - 1, +1);      
      swap(a[i][p], a[j][p]);
      modify(1, 0, n - 1, max({a[i][0], a[i][1], a[i][2]}), n - 1, -1);
      modify(1, 0, n - 1, max({a[j][0], a[j][1], a[j][2]}), n - 1, -1);      
    }
  }
  return 0;
}

Compilation message

tenis.cpp: In lambda function:
tenis.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = l + r >> 1;
      |               ~~^~~
tenis.cpp: In lambda function:
tenis.cpp:53:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 152 ms 11924 KB Output is correct
14 Correct 148 ms 12032 KB Output is correct
15 Correct 167 ms 11984 KB Output is correct
16 Correct 143 ms 11948 KB Output is correct
17 Correct 148 ms 11996 KB Output is correct
18 Correct 163 ms 11984 KB Output is correct
19 Correct 142 ms 11880 KB Output is correct
20 Correct 148 ms 12056 KB Output is correct
21 Correct 164 ms 11912 KB Output is correct
22 Correct 145 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 12444 KB Output is correct
2 Correct 209 ms 12324 KB Output is correct
3 Correct 188 ms 12308 KB Output is correct
4 Correct 192 ms 12236 KB Output is correct
5 Correct 205 ms 12308 KB Output is correct
6 Correct 202 ms 12368 KB Output is correct
7 Correct 211 ms 12320 KB Output is correct
8 Correct 202 ms 12312 KB Output is correct
9 Correct 208 ms 12376 KB Output is correct
10 Correct 201 ms 12228 KB Output is correct
11 Correct 191 ms 12292 KB Output is correct
12 Correct 197 ms 12188 KB Output is correct
13 Correct 208 ms 12320 KB Output is correct
14 Correct 189 ms 12236 KB Output is correct
15 Correct 206 ms 12368 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 152 ms 11924 KB Output is correct
14 Correct 148 ms 12032 KB Output is correct
15 Correct 167 ms 11984 KB Output is correct
16 Correct 143 ms 11948 KB Output is correct
17 Correct 148 ms 11996 KB Output is correct
18 Correct 163 ms 11984 KB Output is correct
19 Correct 142 ms 11880 KB Output is correct
20 Correct 148 ms 12056 KB Output is correct
21 Correct 164 ms 11912 KB Output is correct
22 Correct 145 ms 11980 KB Output is correct
23 Correct 196 ms 12444 KB Output is correct
24 Correct 209 ms 12324 KB Output is correct
25 Correct 188 ms 12308 KB Output is correct
26 Correct 192 ms 12236 KB Output is correct
27 Correct 205 ms 12308 KB Output is correct
28 Correct 202 ms 12368 KB Output is correct
29 Correct 211 ms 12320 KB Output is correct
30 Correct 202 ms 12312 KB Output is correct
31 Correct 208 ms 12376 KB Output is correct
32 Correct 201 ms 12228 KB Output is correct
33 Correct 191 ms 12292 KB Output is correct
34 Correct 197 ms 12188 KB Output is correct
35 Correct 208 ms 12320 KB Output is correct
36 Correct 189 ms 12236 KB Output is correct
37 Correct 206 ms 12368 KB Output is correct
38 Correct 329 ms 12108 KB Output is correct
39 Correct 261 ms 12140 KB Output is correct
40 Correct 335 ms 12156 KB Output is correct
41 Correct 266 ms 12184 KB Output is correct
42 Correct 278 ms 12228 KB Output is correct
43 Correct 406 ms 12108 KB Output is correct
44 Correct 235 ms 12284 KB Output is correct
45 Correct 281 ms 12036 KB Output is correct
46 Correct 234 ms 12192 KB Output is correct
47 Correct 295 ms 12188 KB Output is correct
48 Correct 233 ms 12152 KB Output is correct
49 Correct 258 ms 12212 KB Output is correct
50 Correct 246 ms 12188 KB Output is correct
51 Correct 262 ms 12088 KB Output is correct
52 Correct 331 ms 12136 KB Output is correct
53 Correct 254 ms 14984 KB Output is correct
54 Correct 240 ms 14796 KB Output is correct
55 Correct 285 ms 14828 KB Output is correct
56 Correct 265 ms 15052 KB Output is correct
57 Correct 255 ms 14888 KB Output is correct
58 Correct 267 ms 15008 KB Output is correct