QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369223#6317. XOR Tree PathVengeful_Spirit#WA 1ms7648kbC++204.1kb2024-03-27 22:16:032024-03-27 22:16:05

Judging History

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

  • [2024-03-27 22:16:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7648kb
  • [2024-03-27 22:16:03]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
struct node {
    vector<pair<int, int>> in, ou;
}c[N];
ll sum = 0;


struct LCT {
    int f[N], c[N][2], siz[N], st[N];
    ll s[N], v[N];
    bool lz[N];
    void init(int n) {
        ++n;
        for(int i = 0; i < n; ++i) {
            f[i] = c[i][0] = c[i][1] = lz[i] = 0;
            siz[i] = 1;
        }
    }
    ll cal(int x) {
        return 1ll * x * (x - 1) / 2;
    }
    bool nroot(int x) const {
        return c[f[x]][0] == x || c[f[x]][1] == x;
    }
    void pushup(int x) {
        int lc = c[x][0], rc = c[x][1];
        siz[x] = 1;
        if(lc) {
            siz[x] += siz[lc];
        }
        if(rc) {
            siz[x] += siz[rc];
        }
    }
    void swp(int x) {
        swap(c[x][0], c[x][1]);
        lz[x] ^= 1;
    }
    void pushdown(int x) {
        int lc = c[x][0], rc = c[x][1];
        if(lz[x]) {
            if(lc) swp(lc);
            if(rc) swp(rc);
            lz[x] = 0;
        }
    }
    void zigzag(int x) {
        int y = f[x], z = f[y], typ = (c[y][0] == x);
        if(nroot(y)) c[z][c[z][1] == y] = x;
        f[x] = z, f[y] = x;
        if(c[x][typ]) f[c[x][typ]] = y;
        c[y][typ ^ 1] = c[x][typ];
        c[x][typ] = y;
        pushup(y);
    }
    void splay(int x) {
        int y, tp = 0;
        st[tp = 1] = y = x;
        while(nroot(y)) st[++tp] = y = f[y];
        while(tp) pushdown(st[tp--]);
        for(; nroot(x); zigzag(x)) if(!nroot(f[x])) continue;
        else zigzag((c[f[x]][0]==x) ^ (c[f[f[x]]][0]==f[x]) ? x : f[x]);
        pushup(x);
    }
    void access(int x) {
        for(int y = 0; x; x = f[x]) {
            splay(x);
            c[x][1] = y; pushup(x);
        }
    }
    int findroot(int x) {
        access(x); splay(x); pushdown(x);
        while(c[x][0]) pushdown(x=c[x][0]);
        splay(x);
        return x;
    }
    void split(int x, int y) {
        makeroot(x);
        access(y);
        splay(y);
    }
    void makeroot(int x) {
        access(x); splay(x);
        swp(x);
    }
    void link(int x, int y) {
        makeroot(x); sum -= cal(siz[x]);
        makeroot(y); sum -= cal(siz[y]);
        if(x != findroot(y)) {
            makeroot(x); f[x] = y;
        }
        makeroot(y); sum += cal(siz[y]);
    }
    void cut(int x, int y) {
        makeroot(x); sum -= cal(siz[x]);
        if(x == findroot(y)) {
            pushdown(x);
            if(c[x][1] == y && !c[y][0] && !c[y][1]) {
                c[x][1] = f[y] = 0;
                pushup(x);
            }
        }
        makeroot(x); sum += cal(siz[x]);
        makeroot(y); sum += cal(siz[y]);
    }
} tr;

map<int, int> mp;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k, res = 0;
    cin >> n >> m >> k;
    tr.init(n);
    vector<pair<int, int>> q;
    int Q;
    cin >> Q;
    for(int o = 0, x; o < Q; ++o) {
        cin >> x;
        q.push_back({x, o});
    }
    for(int i = 1, x, y, z; i <= m; ++i) {
        cin >> x >> y >> z;
        int pos = 0;
        // cerr << i << "=======\n";
        for(int i = 29; i >= 0; --i) {
            int ki = (k >> i) & 1, zi = (z >> i) & 1;
            if(!ki) {
                int l = pos | ((!zi) << i), r = l + ((1 << i) - 1) + 1;
                // cerr << l << " " << r << "\n";
                if(!mp.count(l)) mp[l] = ++res;
                if(!mp.count(r)) mp[r] = ++res;
                (c[mp[l]].in).push_back({x, y});
                (c[mp[r]].ou).push_back({x, y});
            }
            pos |= (ki != zi) << i;
        }
    }
    sort(all(q));
    vector<ll> ans;

    auto it = mp.begin();
    for(auto [val, id] : q) {
        for(; it != mp.end() && (*it).first <= val; ++it) {
            int i = (*it).second;
            for(auto[x, y] : c[i].in) tr.link(x, y);
            for(auto[x, y] : c[i].ou) tr.cut(x, y);
        }
        ans[id] = sum;
    }
    for(ll x: ans) cout << x << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7648kb

input:

5
1 0 0 1 0
1 2
1 3
3 4
3 5

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements