제출 #551288

#제출 시각아이디문제언어결과실행 시간메모리
551288hoanghq2004다리 (APIO19_bridges)C++14
59 / 100
3087 ms8924 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 10;
const int B = 200;

int n, m, q;
struct edges {
    int u, v, w, i;
    int operator < (const edges& other) const {
        if (w != other.w) return w > other.w;
        return i < other.i;
    }
} e[N];

set <edges> s;
int temp, num;
int par[N], sz[N];
int ans[N];

struct dta {
    int u, par, sz;
} old[N];

int Find(int u) {
    if (u == par[u]) return u;
    if (temp) old[num++] = {u, par[u], sz[u]};
    return par[u] = Find(par[u]);
}

void Union(int u, int v) {
    if ((u = Find(u)) == (v = Find(v))) return;
    if (temp) {
        old[num++] = {u, par[u], sz[u]};
        old[num++] = {v, par[v], sz[v]};
    }
    if (sz[u] < sz[v]) swap(u, v);
    par[v] = u;
    sz[u] += sz[v];
}

void rollback() {
    for (int i = num - 1; i >= 0; --i) {
        int u = old[i].u;
        par[u] = old[i].par;
        sz[u] = old[i].sz;
    }
    num = 0;
}

int cmd[N], x[N], y[N];
int flag[N], cur[N];

struct triple {
    int x, y, z;
    int operator < (const triple& other) const {
        if (x != other.x) return x > other.x;
        if (y != other.y) return y > other.y;
        return z > other.z;
    }
} ask[N], upd[N];

int _[N];

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> e[i].u >> e[i].v >> e[i].w;
        e[i].i = i;
        s.insert(e[i]);
    }
    cin >> q;
    int cnt = 0;
    for (int T = 0; T < q; ++T) {
        cin >> cmd[cnt] >> x[cnt] >> y[cnt];
        ++cnt;
        if (cnt == B || T == q - 1) {
            for (int i = 1; i <= n; ++i) par[i] = i, sz[i] = 1;
            int n1 = 0, n2 = 0, n3 = 0;
            for (int i = 0; i < cnt; ++i) {
                if (cmd[i] == 1) {
                    if (!flag[x[i]]) flag[x[i]] = 1, _[n3++] = x[i];
                    upd[n2++] = {y[i], x[i], i};
                } else {
                    ask[n1++] = {y[i], x[i], i};
                }
            }
            sort(ask, ask + n1);
            auto iter = s.begin();
            for (int j = 0; j < n1; ++j) {
                auto [w, z, id] = ask[j];
                while (1) {
                    if (iter == s.end() || iter -> w < w) break;
                    if (!flag[iter -> i]) Union(iter -> u, iter -> v);
                    ++iter;
                }
                for (int i = 0; i < n3; ++i) cur[_[i]] = e[_[i]].w;
                temp = 1;
                for (int i = 0; i < n2; ++i) {
                    if (upd[i].z > id) break;
                    cur[upd[i].y] = upd[i].x;
                }
                for (int i = 0; i < n3; ++i) if (cur[_[i]] >= w) Union(e[_[i]].u, e[_[i]].v);
                ans[id] = sz[Find(z)];
                temp = 0;
                rollback();
            }
            for (int i = 0; i < cnt; ++i) {
                if (cmd[i] == 1) {
                    s.erase(e[x[i]]);
                    e[x[i]].w = y[i];
                    s.insert(e[x[i]]);
                    flag[x[i]] = 0;
                } else {
                    cout << ans[i] << '\n';
                }
            }
            cnt = 0;
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'int main()':
bridges.cpp:101:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  101 |                 auto [w, z, id] = ask[j];
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...