Submission #23215

# Submission time Handle Problem Language Result Execution time Memory
23215 2017-05-05T04:56:40 Z RockyB Wall (IOI14_wall) C++14
24 / 100
963 ms 154772 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#include "wall.h"

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define Toktama ""

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1e6 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int n, k;
int type[N], l[N], r[N], x[N], ans[N];
pair <int, int> t[N << 2];

struct node {
  int x, id;
  node() {}
  node(int x, int id) : x(x), id(id) {}
};
struct upd {
  node u[3];
  upd() {
    u[1] = node(-inf, -1);
    u[2] = node(inf, -1);
  }
} u[N << 2];

pair <int, int> combo(pair <int, int> l, pair <int, int> r) {
  return {min(l.f, r.f), max(l.s, r.s)};
}
void push(int v) {
  if (u[v].u[1].id != -1 && u[v].u[2].id != -1) {
    if (u[v].u[1].id > u[v].u[2].id) {
      int x = u[v].u[2].x;
      t[v + v].s = min(t[v + v].s, x);
      t[v + v].f = min(t[v + v].f, t[v + v].s);
      t[v + v + 1].s = min(t[v + v + 1].s, x);
      t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s);
      x = u[v].u[1].x;
      t[v + v].f = max(t[v + v].f, x);
      t[v + v].s = max(t[v + v].s, t[v + v].f);
      t[v + v + 1].f = max(t[v + v + 1].f, x);
      t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f);
    }
    else {
      int x = u[v].u[1].x;
      t[v + v].f = max(t[v + v].f, x);
      t[v + v].s = max(t[v + v].s, t[v + v].f);
      t[v + v + 1].f = max(t[v + v + 1].f, x);
      t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f);
      x = u[v].u[2].x;
      t[v + v].s = min(t[v + v].s, x);
      t[v + v].f = min(t[v + v].f, t[v + v].s);
      t[v + v + 1].s = min(t[v + v + 1].s, x);
      t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s);
    }
    if (u[v + v].u[1].x <= u[v].u[1].x) u[v + v].u[1] = u[v].u[1];
    if (u[v + v].u[2].x >= u[v].u[2].x) u[v + v].u[2] = u[v].u[2];
    if (u[v + v + 1].u[1].x <= u[v].u[1].x) u[v + v + 1].u[1] = u[v].u[1];
    if (u[v + v + 1].u[2].x >= u[v].u[2].x) u[v + v + 1].u[2] = u[v].u[2];
    u[v] = upd();
  }
  else if (u[v].u[1].id != -1) {
    int x = u[v].u[1].x;
    t[v + v].f = max(t[v + v].f, x);
    t[v + v].s = max(t[v + v].s, t[v + v].f);
    t[v + v + 1].f = max(t[v + v + 1].f, x);
    t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f);

    if (u[v + v].u[1].x <= u[v].u[1].x) u[v + v].u[1] = u[v].u[1];
    if (u[v + v + 1].u[1].x <= u[v].u[1].x) u[v + v + 1].u[1] = u[v].u[1];
    u[v] = upd();
  }
  else if (u[v].u[2].id != -1) {
    int x = u[v].u[2].x;
    t[v + v].s = min(t[v + v].s, x);
    t[v + v].f = min(t[v + v].f, t[v + v].s);
    t[v + v + 1].s = min(t[v + v + 1].s, x);
    t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s);

    if (u[v + v].u[2].x >= u[v].u[2].x) u[v + v].u[2] = u[v].u[2];
    if (u[v + v + 1].u[2].x >= u[v].u[2].x) u[v + v + 1].u[2] = u[v].u[2];
    u[v] = upd();
  }
}
void upd(int l, int r, int type, int x, int id, int v, int tl, int tr) {
  if (l <= tl && tr <= r) {
    if (type == 1) {
      t[v].f = max(t[v].f, x);
      t[v].s = max(t[v].s, t[v].f);
      if (u[v].u[1].x <= x) u[v].u[1] = node(x, id);
    }
    else {
      t[v].s = min(t[v].s, x);
      t[v].f = min(t[v].f, t[v].s);
      if (u[v].u[2].x >= x) u[v].u[2] = node(x, id);
    }
    return;
  }
  if (tl > r || tr < l) return;
  int tm = tl + tr >> 1;
  push(v);
  upd(l, r, type, x, id, v + v, tl, tm);
  upd(l, r, type, x, id, v + v + 1, tm + 1, tr);
  t[v] = combo(t[v + v], t[v + v + 1]);
}
pair <int, int> get(int l, int r, int v, int tl, int tr) {
  if (l <= tl && tr <= r) return t[v];
  if (tl > r || tr < l) return {inf, -inf};
  int tm = tl + tr >> 1;
  push(v);
  return combo(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
void bye(int v, int tl, int tr) {
  if (tl == tr) {
    return;
  }
  int tm = tl + tr >> 1;
  bye(v + v, tl, tm);
  bye(v + v + 1, tm + 1, tr);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
  rep(i, 0, k - 1)
    upd(left[i], right[i], op[i], height[i], i, 1, 0, n - 1);
  rep(i, 0, n - 1)
    finalHeight[i] = get(i, i, 1, 0, n - 1).f;
}
/*
int main() {
  #ifndef Toktama
    freopen (Toktama".in", "r", stdin);
    freopen (Toktama".out", "w", stdout);
  #endif
  scanf ("%d%d", &n, &k);
  rep(i, 0, k - 1) {
    scanf ("%d%d%d%d", &type[i], &l[i], &r[i], &x[i]);
  }
  buildWall(n, k, type, l, r, x, ans);
  rep(i, 0, n - 1)
    printf ("%d\n", ans[i]);
  ioi
}
*/

Compilation message

wall.cpp: In function 'void upd(int, int, int, int, int, int, int, int)':
wall.cpp:133:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
wall.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
wall.cpp:142:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
wall.cpp: In function 'void bye(int, int, int)':
wall.cpp:150:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
# Verdict Execution time Memory Grader output
1 Correct 16 ms 146556 KB Output is correct
2 Correct 19 ms 146692 KB Output is correct
3 Incorrect 26 ms 146556 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 146556 KB Output is correct
2 Correct 186 ms 154380 KB Output is correct
3 Correct 313 ms 149952 KB Output is correct
4 Correct 963 ms 154772 KB Output is correct
5 Correct 419 ms 154772 KB Output is correct
6 Correct 399 ms 154772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 146556 KB Output is correct
2 Correct 13 ms 146692 KB Output is correct
3 Incorrect 26 ms 146556 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 146556 KB Output is correct
2 Correct 23 ms 146692 KB Output is correct
3 Incorrect 16 ms 146556 KB Output isn't correct
4 Halted 0 ms 0 KB -