社区讨论

I love structed datastructures!

学术版参与者 8已保存回复 19

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
19 条
当前快照
1 份
快照标识符
@mhj3uot1
此快照首次捕获于
2025/11/03 20:17
4 个月前
此快照最后确认于
2025/11/03 20:45
4 个月前
查看原帖
因为全局变量与局部变量、宏与函数的纷争,我决定以后的数据结构都用结构体写,如 Trie、SgT、Block Decomposition、ST Table 等。
求评价这样的利弊awa
例如线段树模版一:
CPP
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define inl_force __attribute__((always_inline)) inline
typedef long long ll;

template <typename Tp>
struct SgT {
    int n;
    vector<Tp> t, lazy;
    inl_force void push_up(int i) {
        略;
    }
    inl_force void push_down(int i, int l, int r, int mid) {
        略;
    }
    void build(int i, int l, int r, const vector<Tp>& a) {
        略;
    }
    inl_force void operator = (const vector<Tp>& a) {
        略;
    }
    void modify(int i, int l, int r, int ql, int qr, ll x) {
        略;
    }
    Tp query(int i, int l, int r, int ql, int qr) {
        略;
    }
};
SgT<ll> sgt;
vector<ll> a;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    a.resize(n + 1);
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    sgt = a;
    while (q --) {
        略;
        }
    }
    return 0;
}

(当然不一定一定用 vector)

Structed datastructures baby I love you!

另求用 vector 的利弊。
拜谢各路大神!!!

回复

19 条回复,欢迎继续交流。

正在加载回复...