Submission #225996

# Submission time Handle Problem Language Result Execution time Memory
225996 2020-04-22T09:29:22 Z quocnguyen1012 Tenis (COI19_tenis) C++14
100 / 100
245 ms 7928 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e5 + 5, inf = 1e9;

int tr[4 * maxn], lz[4 * maxn];
int N, Q;
int pos[3][maxn], a[3][maxn];

#define lc id << 1
#define rc id << 1 | 1

void push(int id, int l, int r)
{
  if(l != r){
    tr[lc] += lz[id];
    tr[rc] += lz[id];
    lz[lc] += lz[id];
    lz[rc] += lz[id];
  }
  lz[id] = 0;
}

void modify(int id, int l, int r, int L, int R, int v)
{
  push(id, l, r);
  if(r < L || R < l)
    return;
  if(L <= l && r <= R){
    tr[id] += v;
    lz[id] += v;
    push(id, l, r);
    return;
  }
  int mid = (l + r) / 2;
  modify(lc, l, mid, L, R, v); modify(rc, mid + 1, r, L, R, v);
  tr[id] = min(tr[lc], tr[rc]);
}

int get(int id, int l, int r, int L, int R)
{
  push(id, l, r);
  if(r < L || R < l)
    return inf;
  if(L <= l && r <= R){
    return tr[id];
  }
  int mid = (l + r) / 2;
  return min(get(lc, l, mid, L, R), get(rc, mid + 1, r, L, R));
}

int query(int id, int l, int r)
{
  push(id, l, r);
  if(l == r)
    return l;
  int mid = (l + r) / 2;
  if(tr[lc] == 0)
    return query(lc, l, mid);
  return query(rc, mid + 1, r);
}

int maxi(int p)
{
  int mx = 0;
  for(int i = 0; i < 3; ++i)
    mx = max(mx, pos[i][p]);
  return mx;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> Q;
  for(int i = 0; i < 3; ++i){
    for(int j = 1; j <= N; ++j){
      cin >> a[i][j];
      pos[i][a[i][j]] = j;
    }
  }
  for(int i = 1; i <= N; ++i){
    modify(1, 1, N, i, i, i);
  }
  for(int i = 1; i <= N; ++i){
    modify(1, 1, N, maxi(i), N, -1);
  }
  for(int tc = 1; tc <= Q; ++tc){
    int type; cin >> type;
    if(type == 1){
      int p; cin >> p;
      cout << (maxi(p) <= query(1, 1, N) ? "DA" : "NE");
      cout << '\n';
    }
    else{
      int t, x, y; cin >> t >> x >> y; --t;
      modify(1, 1, N, maxi(x), N, 1);
      modify(1, 1, N, maxi(y), N, 1);
      swap(pos[t][x], pos[t][y]);
      modify(1, 1, N, maxi(x), N, -1);
      modify(1, 1, N, maxi(y), N, -1);
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 103 ms 6648 KB Output is correct
14 Correct 109 ms 6520 KB Output is correct
15 Correct 134 ms 6500 KB Output is correct
16 Correct 102 ms 6520 KB Output is correct
17 Correct 109 ms 6520 KB Output is correct
18 Correct 108 ms 6480 KB Output is correct
19 Correct 113 ms 6520 KB Output is correct
20 Correct 150 ms 6528 KB Output is correct
21 Correct 119 ms 6520 KB Output is correct
22 Correct 125 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 5484 KB Output is correct
2 Correct 146 ms 7544 KB Output is correct
3 Correct 133 ms 7544 KB Output is correct
4 Correct 150 ms 7544 KB Output is correct
5 Correct 159 ms 7544 KB Output is correct
6 Correct 147 ms 7508 KB Output is correct
7 Correct 134 ms 7544 KB Output is correct
8 Correct 141 ms 7544 KB Output is correct
9 Correct 149 ms 7604 KB Output is correct
10 Correct 135 ms 7544 KB Output is correct
11 Correct 130 ms 7548 KB Output is correct
12 Correct 154 ms 7544 KB Output is correct
13 Correct 142 ms 7544 KB Output is correct
14 Correct 137 ms 7544 KB Output is correct
15 Correct 149 ms 7520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 103 ms 6648 KB Output is correct
14 Correct 109 ms 6520 KB Output is correct
15 Correct 134 ms 6500 KB Output is correct
16 Correct 102 ms 6520 KB Output is correct
17 Correct 109 ms 6520 KB Output is correct
18 Correct 108 ms 6480 KB Output is correct
19 Correct 113 ms 6520 KB Output is correct
20 Correct 150 ms 6528 KB Output is correct
21 Correct 119 ms 6520 KB Output is correct
22 Correct 125 ms 6520 KB Output is correct
23 Correct 140 ms 5484 KB Output is correct
24 Correct 146 ms 7544 KB Output is correct
25 Correct 133 ms 7544 KB Output is correct
26 Correct 150 ms 7544 KB Output is correct
27 Correct 159 ms 7544 KB Output is correct
28 Correct 147 ms 7508 KB Output is correct
29 Correct 134 ms 7544 KB Output is correct
30 Correct 141 ms 7544 KB Output is correct
31 Correct 149 ms 7604 KB Output is correct
32 Correct 135 ms 7544 KB Output is correct
33 Correct 130 ms 7548 KB Output is correct
34 Correct 154 ms 7544 KB Output is correct
35 Correct 142 ms 7544 KB Output is correct
36 Correct 137 ms 7544 KB Output is correct
37 Correct 149 ms 7520 KB Output is correct
38 Correct 245 ms 7800 KB Output is correct
39 Correct 161 ms 7672 KB Output is correct
40 Correct 234 ms 7928 KB Output is correct
41 Correct 184 ms 7672 KB Output is correct
42 Correct 187 ms 7800 KB Output is correct
43 Correct 229 ms 7852 KB Output is correct
44 Correct 166 ms 7672 KB Output is correct
45 Correct 186 ms 7672 KB Output is correct
46 Correct 162 ms 7672 KB Output is correct
47 Correct 180 ms 7672 KB Output is correct
48 Correct 156 ms 7672 KB Output is correct
49 Correct 188 ms 7800 KB Output is correct
50 Correct 155 ms 7672 KB Output is correct
51 Correct 189 ms 7800 KB Output is correct
52 Correct 215 ms 7800 KB Output is correct
53 Correct 187 ms 7732 KB Output is correct
54 Correct 182 ms 7672 KB Output is correct
55 Correct 184 ms 7676 KB Output is correct
56 Correct 227 ms 7744 KB Output is correct
57 Correct 167 ms 7672 KB Output is correct
58 Correct 197 ms 7716 KB Output is correct