Submission #586676

# Submission time Handle Problem Language Result Execution time Memory
586676 2022-06-30T14:25:22 Z MilosMilutinovic Tenis (COI19_tenis) C++14
Compilation error
0 ms 0 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);
    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:54:35: error: 'mid' was not declared in this scope
   54 |       return walk(node + node, l, mid);
      |                                   ^~~
tenis.cpp:56:36: error: 'mid' was not declared in this scope
   56 |       return walk(node + node + 1, mid + 1, r);
      |                                    ^~~