QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377886#5504. Flower Garden8BQube#Compile Error//C++203.4kb2024-04-05 19:14:592024-04-05 19:15:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-05 19:15:01]
  • 评测
  • [2024-04-05 19:14:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define pb push_back
#define ALL(v) v.begin(), v.end()

const int N = 33333 * 3 * 2 * 2 * 2 * 2;

struct SAT {
    int low[N], dfn[N], bln[N], n, Time, nScc;
    bool instack[N], istrue[N];
    stack<int> st;
    vector<int> G[N], SCC[n];
    void init(int _n) {
        n = _n, assert(n * 2 <= N);
        for (int i = 0; i < n + n; ++i) G[i].clear();
    }
    void add_edge(int a, int b) { G[a].pb(b); }
    int rv(int a) {
        if (a >= n) return a - n;
        return a + n;
    }
    void add_clause(int a, int b) {
        add_edge(rv(a), b), add_edge(rv(b), a);
    }
    void dfs(int u) {
        dfn[u] = low[u] = ++Time;
        instack[u] = 1, st.push(u);
        for (int i : G[u])
            if (!dfn[i])
                dfs(i), low[u] = min(low[i], low[u]);
            else if (instack[i] && dfn[i] < dfn[u])
                low[u] = min(low[u], dfn[i]);
        if (low[u] == dfn[u]) {
            int tmp;
            do {
                tmp = st.top(), st.pop();
                instack[tmp] = 0, bln[tmp] = nScc;
            } while (tmp != u);
            ++nScc;
        }
    }
    bool solve() {
        Time = nScc = 0;
        for (int i = 0; i < n + n; ++i)
            SCC[i].clear(), low[i] = dfn[i] = bln[i] = 0;
        for (int i = 0; i < n + n; ++i)
            if (!dfn[i]) dfs(i);
        for (int i = 0; i < n + n; ++i) SCC[bln[i]].pb(i);
        for (int i = 0; i < n; ++i) {
            if (bln[i] == bln[i + n]) return false;
            istrue[i] = bln[i] < bln[i + n];
            istrue[i + n] = !istrue[i];
        }
        return true;
    }
} sat;

int T[33333 * 3 * 4], F[33333 * 3 * 4], val[40000 * 3], tp;

int newnode() {
    return tp++;
}

void build(int l, int r, int rt) {
    if (l == r) return;
    T[rt] = newnode(), F[rt] = newnode();
    int mid = (l + r) >> 1;
    build(l, mid, rt << 1), build(mid + 1, r, rt << 1 | 1);
}

void build_edge(int l, int r, int rt) {
    if (l == r) return T[rt] = val[l], F[rt] = sat.rv(val[l]), void();
    int mid = (l + r) >> 1;
    build_edge(l, mid, rt << 1);
    build_edge(mid + 1, r, rt << 1 | 1);
    sat.add_clause(sat.rv(T[rt]), T[rt << 1]);
    sat.add_clause(sat.rv(T[rt]), T[rt << 1 | 1]);
    sat.add_clause(sat.rv(F[rt]), F[rt << 1]);
    sat.add_clause(sat.rv(F[rt]), F[rt << 1 | 1]);
}

void add_edge(int L, int R, int l, int r, int rt, int v, int *tag) {
    if (L <= l && R >= r)
        return sat.add_caluse(sat.rv(v), tag[rt]);
    int mid = (l + r) >> 1;
    if (L <= mid) add_edge(L, R, l, mid, rt << 1, v, tag);
    if (R > mid) add_edge(L, R, mid + 1, r, rt << 1 | 1, v, tag);
}

pii qry[100005];

void solve() {
    int n, q;
    cin >> n >> q;
    tp = 0;
    for (int i = 0; i < n * 3; ++i)
        val[i] = newnode();
    for (int i = 0; i < q; ++i) {
        qry[i].X = newnode(); 
        qry[i].Y = newnode();
    }
    build(0, 3 * n - 1, 1);
    build_edge(0, 3 * n - 1, 1);
    sat.init(tp);
    for (int i = 1; i <= q; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a, --b, --c, --d;
        add_edge(a, b, 0, 3 * n - 1, 1, qry[i].X, F);
        add_edge(c, d, 0, 3 * n - 1, 1, qry[i].Y, T);
    }
    sat.solve();
    cout << "NIE\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

详细

answer.code:18:27: error: invalid use of non-static data member ‘SAT::n’
   18 |     vector<int> G[N], SCC[n];
      |                           ^
answer.code:15:33: note: declared here
   15 |     int low[N], dfn[N], bln[N], n, Time, nScc;
      |                                 ^
answer.code: In member function ‘bool SAT::solve()’:
answer.code:51:13: error: ‘SCC’ was not declared in this scope
   51 |             SCC[i].clear(), low[i] = dfn[i] = bln[i] = 0;
      |             ^~~
answer.code:54:41: error: ‘SCC’ was not declared in this scope
   54 |         for (int i = 0; i < n + n; ++i) SCC[bln[i]].pb(i);
      |                                         ^~~
answer.code: In function ‘void add_edge(int, int, int, int, int, int, int*)’:
answer.code:90:20: error: ‘struct SAT’ has no member named ‘add_caluse’; did you mean ‘add_clause’?
   90 |         return sat.add_caluse(sat.rv(v), tag[rt]);
      |                    ^~~~~~~~~~
      |                    add_clause