• P3710 方方方的数据结构 [KD-Tree]


    这题似乎就 KD-Tree 板子。

    矩形加法,矩形乘法,QAQ。

    都是离线下来按顺序添加的,所以没有什么关系。

    // powered by c++11
    // by Isaunoya
    #include <bits/stdc++.h>
    
    #define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
    #define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
    
    using namespace std;
    using db = double;
    using ll = long long;
    using uint = unsigned int;
    using ull = unsigned long long;
    
    using pii = pair<int, int>;
    
    #define fir first
    #define sec second
    
    template <class T>
    
    void cmax(T& x, const T& y) {
      if (x < y) x = y;
    }
    
    template <class T>
    
    void cmin(T& x, const T& y) {
      if (x > y) x = y;
    }
    
    #define all(v) v.begin(), v.end()
    #define sz(v) ((int)v.size())
    #define pb emplace_back
    
    template <class T>
    
    void sort(vector<T>& v) {
      sort(all(v));
    }
    
    template <class T>
    
    void reverse(vector<T>& v) {
      reverse(all(v));
    }
    
    template <class T>
    
    void unique(vector<T>& v) {
      sort(all(v)), v.erase(unique(all(v)), v.end());
    }
    
    void reverse(string& s) { reverse(s.begin(), s.end()); }
    
    const int io_size = 1 << 23 | 233;
    const int io_limit = 1 << 22;
    struct io_in {
      char ch;
    #ifndef __WIN64
      char getchar() {
        static char buf[io_size], *p1 = buf, *p2 = buf;
    
        return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, io_size, stdin), p1 == p2) ? EOF : *p1++;
      }
    #endif
      io_in& operator>>(char& c) {
        for (c = getchar(); isspace(c); c = getchar())
          ;
    
        return *this;
      }
      io_in& operator>>(string& s) {
        for (s.clear(); isspace(ch = getchar());)
          ;
    
        if (!~ch) return *this;
    
        for (s = ch; !isspace(ch = getchar()) && ~ch; s += ch)
          ;
    
        return *this;
      }
    
      io_in& operator>>(char* str) {
        char* cur = str;
        while (*cur) *cur++ = 0;
    
        for (cur = str; isspace(ch = getchar());)
          ;
        if (!~ch) return *this;
    
        for (*cur = ch; !isspace(ch = getchar()) && ~ch; *++cur = ch)
          ;
    
        return *++cur = 0, *this;
      }
    
      template <class T>
    
      void read(T& x) {
        bool f = 0;
        while ((ch = getchar()) < 48 && ~ch) f ^= (ch == 45);
    
        x = ~ch ? (ch ^ 48) : 0;
        while ((ch = getchar()) > 47) x = x * 10 + (ch ^ 48);
        x = f ? -x : x;
      }
    
      io_in& operator>>(int& x) { return read(x), *this; }
    
      io_in& operator>>(ll& x) { return read(x), *this; }
    
      io_in& operator>>(uint& x) { return read(x), *this; }
    
      io_in& operator>>(ull& x) { return read(x), *this; }
    
      io_in& operator>>(db& x) {
        read(x);
        bool f = x < 0;
        x = f ? -x : x;
        if (ch ^ '.') return *this;
    
        double d = 0.1;
        while ((ch = getchar()) > 47) x += d * (ch ^ 48), d *= .1;
        return x = f ? -x : x, *this;
      }
    } in;
    
    struct io_out {
      char buf[io_size], *s = buf;
      int pw[233], st[233];
    
      io_out() {
        set(7);
        rep(i, pw[0] = 1, 9) pw[i] = pw[i - 1] * 10;
      }
    
      ~io_out() { flush(); }
    
      void io_chk() {
        if (s - buf > io_limit) flush();
      }
    
      void flush() { fwrite(buf, 1, s - buf, stdout), fflush(stdout), s = buf; }
    
      io_out& operator<<(char c) { return *s++ = c, *this; }
    
      io_out& operator<<(string str) {
        for (char c : str) *s++ = c;
        return io_chk(), *this;
      }
    
      io_out& operator<<(char* str) {
        char* cur = str;
        while (*cur) *s++ = *cur++;
        return io_chk(), *this;
      }
    
      template <class T>
    
      void write(T x) {
        if (x < 0) *s++ = '-', x = -x;
    
        do {
          st[++st[0]] = x % 10, x /= 10;
        } while (x);
    
        while (st[0]) *s++ = st[st[0]--] ^ 48;
      }
    
      io_out& operator<<(int x) { return write(x), io_chk(), *this; }
    
      io_out& operator<<(ll x) { return write(x), io_chk(), *this; }
    
      io_out& operator<<(uint x) { return write(x), io_chk(), *this; }
    
      io_out& operator<<(ull x) { return write(x), io_chk(), *this; }
    
      int len, lft, rig;
    
      void set(int _length) { len = _length; }
    
      io_out& operator<<(db x) {
        bool f = x < 0;
        x = f ? -x : x, lft = x, rig = 1. * (x - lft) * pw[len];
        return write(f ? -lft : lft), *s++ = '.', write(rig), io_chk(), *this;
      }
    } out;
    #define int long long
    
    template <int sz, int mod>
    
    struct math_t {
      math_t() {
        fac.resize(sz + 1), ifac.resize(sz + 1);
        rep(i, fac[0] = 1, sz) fac[i] = fac[i - 1] * i % mod;
    
        ifac[sz] = inv(fac[sz]);
        Rep(i, sz - 1, 0) ifac[i] = ifac[i + 1] * (i + 1) % mod;
      }
    
      vector<int> fac, ifac;
    
      int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = x * x % mod)
          if (y & 1) ans = ans * x % mod;
        return ans;
      }
    
      int inv(int x) { return qpow(x, mod - 2); }
    
      int C(int n, int m) {
        if (n < 0 || m < 0 || n < m) return 0;
        return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
      }
    };
    
    int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
    int lcm(int x, int y) { return x * y / gcd(x, y); }
    
    const int maxn = 2e5 + 52;
    const int mod = 998244353;
    
    int inc(int x, int y) { return (x + y >= mod) ? (x + y - mod) : (x + y); }
    
    int dec(int x, int y) { return (x - y >= 0) ? (x - y) : (x - y + mod); }
    
    int n, m, rt;
    int sum[maxn];
    int add[maxn], mul[maxn];
    int t[maxn], top = 0;
    int opt, tmp, x[2], y[2];
    int mn[maxn][2], mx[maxn][2];
    int val[maxn][2], ch[maxn][2];
    
    struct node {
      int opt, l, r, ed, val;
    } q[maxn];
    
    int K;
    bool cmp(int a, int b) { return val[a][K] < val[b][K]; }
    #define ls ch[u][0]
    #define rs ch[u][1]
    void pushup(int u) {
      add[u] = 0, mul[u] = 1;
      for (int i = 0; i < 2; i++) {
        mn[u][i] = min(val[u][i], min(mn[ls][i], mn[rs][i]));
        mx[u][i] = max(val[u][i], max(mx[ls][i], mx[rs][i]));
      }
    }
    
    void build(int& u, int l, int r, int k) {
      if (l > r) return;
      K = k;
      int mid = l + r >> 1;
      sort(t + l, t + r + 1, cmp);
      u = t[mid];
      build(ls, l, mid - 1, k ^ 1);
      build(rs, mid + 1, r, k ^ 1);
      pushup(u);
    }
    
    void pushdown(int u) {
      if (mul[u] ^ 1) {
        sum[ls] = (sum[ls] * mul[u]) % mod;
        sum[rs] = (sum[rs] * mul[u]) % mod;
        mul[ls] = (mul[ls] * mul[u]) % mod;
        mul[rs] = (mul[rs] * mul[u]) % mod;
        add[ls] = (add[ls] * mul[u]) % mod;
        add[rs] = (add[rs] * mul[u]) % mod;
        mul[u] = 1;
      }
    
      if (add[u]) {
        sum[ls] = inc(sum[ls], add[u]);
        sum[rs] = inc(sum[rs], add[u]);
        add[ls] = inc(add[ls], add[u]);
        add[rs] = inc(add[rs], add[u]);
        add[u] = 0;
      }
    }
    
    int allin, allout, thisin;
    
    void chk(int u) {
      allin = allout = thisin = 1;
      for (int i = 0; i < 2; i++) {
        if (x[i] > mn[u][i] || mx[u][i] > y[i]) {
          allin = 0;
          if (x[i] > val[u][i] || val[u][i] > y[i]) {
            thisin = 0;
            if (x[i] > mx[u][i] || y[i] < mn[u][i]) {
              allout = 0;
            }
          }
        }
      }
      allout ^= 1;
    }
    
    void _add(int u) {
      if (!u) return;
      chk(u);
      if (allout) return;
      if (thisin) {
        if (opt == 1) {
          sum[u] = inc(sum[u], tmp);
        } else {
          sum[u] = sum[u] * tmp % mod;
        }
      }
      if (allin) {
        if (opt == 1) {
          add[u] = inc(add[u], tmp);
        } else {
          add[u] = add[u] * tmp % mod;
          mul[u] = mul[u] * tmp % mod;
        }
        return;
      }
    
      pushdown(u);
      _add(ls);
      _add(rs);
    }
    
    void qry(int u, int v) {
      if (!u) return;
      if (val[v][0] < mn[u][0] || val[v][0] > mx[u][0]) return;
      if (val[v][1] < mn[u][1] || val[v][1] > mx[u][1]) return;
    
      if (u == v) {
        out << sum[u] << '
    ';
        return;
      }
    
      pushdown(u);
    
      qry(ls, v);
      qry(rs, v);
    }
    
    signed main() {
      // code begin.
      in >> n >> m;
      mn[0][0] = mn[0][1] = maxn;
      mx[0][0] = mx[0][1] = 0;
      rep(i, 1, m) {
        in >> q[i].opt;
        if (q[i].opt <= 2) {
          in >> q[i].l >> q[i].r >> q[i].val;
          q[i].ed = m;
        } else {
          if (q[i].opt == 3) {
            in >> val[i][1];
            val[i][0] = i;
            t[++top] = i;
            mul[i] = 1;
          } else {
            in >> q[i].ed;
            q[q[i].ed].ed = i;
          }
        }
      }
      build(rt, 1, top, 0);
      rep(i, 1, m) {
        if (q[i].opt <= 2) {
          opt = q[i].opt, tmp = q[i].val;
          tmp %= mod;
          x[0] = i, y[0] = q[i].ed;
          x[1] = q[i].l, y[1] = q[i].r;
          _add(rt);
        } else {
          if (q[i].opt == 3) qry(rt, i);
        }
      }
      return 0;
      // code end.
    }
    
  • 相关阅读:
    Idea主题下载
    使用plsql创建用户并授权(图形化界面)
    PLSQL Developer 没有64位版本 + 找不到 msvcr71.dll
    NOIp2017TG解题报告
    Restart
    NOIp2018RP++
    其他题
    Errors
    NOIpDairy
    Code Style for OI
  • 原文地址:https://www.cnblogs.com/Isaunoya/p/12602587.html
Copyright © 2020-2023  润新知