QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718291#9449. New School TermMher777Compile Error//C++209.0kb2024-11-06 20:11:452024-11-06 20:11:48

Judging History

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

  • [2024-11-06 20:11:48]
  • 评测
  • [2024-11-06 20:11:45]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
using namespace std;
mt19937 rnd(time(nullptr));

/* -------------------- Typedefs -------------------- */

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;

/* -------------------- Usings -------------------- */

using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* -------------------- Defines -------------------- */

#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
#define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout);

/* -------------------- Constants -------------------- */

const int dx[8] = { -1, 0, 1, 0, -1, -1, 1, 1 };
const int dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(1000000007);
const ll MOD2 = ll(998244353);

/* -------------------- Functions -------------------- */

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void precision(int x) {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(x);
}

ll gcd(ll a, ll b) {
    if (a == 0 || b == 0) return(max(a, b));
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll range_sum(ll a, ll b) {
    if (a > b) return 0ll;
    ll dif = a - 1, cnt = b - a + 1;
    ll ans = ((b - a + 1) * (b - a + 2)) / 2;
    ans += ((b - a + 1) * dif);
    return ans;
}

string dec_to_bin(ll a) {
    string s = "";
    for (ll i = a; i > 0; ) {
        ll k = i % 2;
        i /= 2;
        char c = k + 48;
        s += c;
    }
    if (a == 0) {
        s = "0";
    }
    reverse(all(s));
    return s;
}

ll bin_to_dec(string s) {
    ll num = 0;
    for (int i = 0; i < s.size(); i++) {
        num *= 2ll;
        num += (s[i] - '0');
    }
    return num;
}

ll factorial_by_mod(ll n, ll mod) {
    ll ans = 1;
    ll num;
    for (ll i = 1; i <= n; ++i) {
        num = i % mod;
        ans *= num;
        ans %= mod;
    }
    return ans;
}

bool isPrime(ll a) {
    if (a == 1) return false;
    for (ll i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

ll binpow(ll a, ll b) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
        }
        b >>= 1;
        a *= a;
    }
    return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= mod;
        }
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return ans;
}

/* -------------------- Solution -------------------- */

const int N = 1000005;
pii edge[N];
pii dp[N];
int clr[N], sz[N], p[N], cnt[N][2], used[N], usedd[N], dpp[N], from[N];
vi comp[N];
pii M = { 1000000007, 1000000009 };
int n, m, last, s, cur_ind;

void clearr() {
    n = m = last = s = cur_ind = 0;
    for (int i = 0; i <= N - 5; ++i) {
        edge[i] = dp[i] = { 0,0 };
        clr[i] = sz[i] = p[i] = cnt[i][0] = cnt[i][1] = used[i] = usedd[i] = ans[i] = dpp[i] = from[i] = 0;
        comp[i].clear();
    }
}

pair<int, int> sum(const pair<int, int>& a, const pair<int, int>& b) {
    return make_pair((a.ff + b.ff) % M.ff, (a.ss + b.ss) % M.ss);
}

pair<int, int> dif(const pair<int, int>& a, const pair<int, int>& b) {
    return make_pair((a.ff - b.ff + M.ff) % M.ff, (a.ss - b.ss + M.ss) % M.ss);
}

pair<int, int> pro(const pair<int, int>& a, const pair<int, int>& b) {
    return make_pair((a.ff * 1LL * b.ff) % M.ff, (a.ss * 1LL * b.ss) % M.ss);
}

void add(int x) {
    if (!x) return;
    for (int i = n; i >= x; --i) {
        dp[i] = sum(dp[i], dp[i - x]);
    }
}

void del(int x) {
    if (!x) return;
    for (int i = x; i <= n; ++i) {
        dp[i] = dif(dp[i], dp[i - x]);
    }
}

void make_set(int x) {
    comp[x] = { x };
    cnt[x][0] = 1;
    cnt[x][1] = 0;
    clr[x] = 0;
    sz[x] = 1;
    p[x] = x;
}

int find_set(int x) {
    if (x == p[x]) return x;
    return p[x] = find_set(p[x]);
}

void union_sets(int x, int y, bool f) {
    if (sz[x] > sz[y]) swap(x, y);
    del(max(cnt[x][0], cnt[x][1]) - min(cnt[x][0], cnt[x][1]));
    s -= min(cnt[x][0], cnt[x][1]);
    del(max(cnt[y][0], cnt[y][1]) - min(cnt[y][0], cnt[y][1]));
    s -= min(cnt[y][0], cnt[y][1]);
    if (f) {
        swap(cnt[y][0], cnt[y][1]);
    }
    cnt[x][0] += cnt[y][0];
    cnt[x][1] += cnt[y][1];
    add(max(cnt[x][0], cnt[x][1]) - min(cnt[x][0], cnt[x][1]));
    s += min(cnt[x][0], cnt[x][1]);
    if ((!dp[n - s].ff && !dp[n - s].ss)) {
        del(max(cnt[x][0], cnt[x][1]) - min(cnt[x][0], cnt[x][1]));
        s -= min(cnt[x][0], cnt[x][1]);
        cnt[x][0] -= cnt[y][0];
        cnt[x][1] -= cnt[y][1];
        if (f) {
            swap(cnt[y][0], cnt[y][1]);
        }
        add(max(cnt[x][0], cnt[x][1]) - min(cnt[x][0], cnt[x][1]));
        s += min(cnt[x][0], cnt[x][1]);
        add(max(cnt[y][0], cnt[y][1]) - min(cnt[y][0], cnt[y][1]));
        s += min(cnt[y][0], cnt[y][1]);
        return;
    }
    last = cur_ind;
    sz[x] += sz[y];
    p[y] = x;
    for (auto elem : comp[y]) {
        comp[x].pub(elem);
        if (f) {
            clr[elem] ^= 1;
        }
    }
}


void slv() {
    dp[0] = { 1,1 };
    /*while (1) {
        n = rnd() % 15 + 1;
        if (n <= 2) continue;
        break;
    }
    while (1) {
        m = rnd() % 20 + 1;
        if (m <= 4) continue;
        break;
    }
    cout << n << " " << m << '\n';*/
    cin >> n >> m;
    last = m + 1, cur_ind = m;
    for (int i = 1; i <= m; ++i) {
        /*edge[i].ff = rnd() % (2 * n) + 1;
        while (1) {
            edge[i].ss = rnd() % (2 * n) + 1;
            if (edge[i].ss == edge[i].ff) {
                continue;
            }
            break;
        }
        cout << edge[i].ff << " " << edge[i].ss << '\n';*/
        cin >> edge[i].ff >> edge[i].ss;
    }
    for (int i = 1; i <= 2 * n; ++i) {
        make_set(i);
        add(1);
    }
    for (int i = m; i >= 1; --i) {
        cur_ind = i;
        int x = edge[i].ff, y = edge[i].ss;
        int x_comp = find_set(x), y_comp = find_set(y);
        if (x_comp != y_comp) {
            union_sets(x_comp, y_comp, (clr[x] == clr[y]));
            continue;
        }
        if (clr[x] != clr[y] && (dp[n - s].ff || dp[n - s].ss)) {
            last = i;
        }
    }
    vi v;
    for (int i = 1; i <= 2 * n; ++i) {
        int u = find_set(i);
        if (used[u]) continue;
        used[u] = 1;
        if (cnt[u][0] != cnt[u][1]) {
            v.pub(max(cnt[u][0], cnt[u][1]) - min(cnt[u][0], cnt[u][1]));
        }
    }
    dpp[0] = 1;
    sort(all(v));
    for (auto elem : v) {
        for (int i = n - s; i >= elem; --i) {
            if (dpp[i]) continue;
            if (dpp[i - elem]) {
                dpp[i] = 1;
                from[i] = elem;
            }
        }
    }
    int node = n - s;
    while (node) {
        ++usedd[from[node]];
        node -= from[node];
    }
    for (int i = 1; i <= 2 * n; ++i) {
        used[i] = 0;
    }
    int m1 = 0, m2 = 0;
    for (int i = 1; i <= 2 * n; ++i) {
        int u = find_set(i);
        if (used[u]) continue;
        used[u] = 1;
        int val = max(cnt[u][0], cnt[u][1]) - min(cnt[u][0], cnt[u][1]), mn = min(cnt[u][0], cnt[u][1]);
        bool f = false;
        if (cnt[u][0] < cnt[u][1]) {
            swap(cnt[u][0], cnt[u][1]);
            for (auto elem : comp[u]) {
                clr[elem] ^= 1;
            }
        }
        if (!usedd[val]) {
            for (auto elem : comp[u]) {
                clr[elem] ^= 1;
            }
        }
        for (auto elem : comp[u]) {
            if (clr[elem] == 0) ++m1;
            else ++m2;
        }
        if (usedd[val]) --usedd[val];
    }
    for (int i = 1; i <= 2 * n; ++i) {
        cout << clr[i];
    }
    cout << '\n';
}

void cs() {
    int tstc = 1;
    //cin >> tstc;
    while (tstc--) {
        slv();
    }
}

void precalc() {
    return;
}

int main() {
    fastio();
    precalc();
    //precision(0);
    cs();
    return 0;
}

详细

answer.code: In function ‘void clearr()’:
answer.code:188:78: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
  188 |         clr[i] = sz[i] = p[i] = cnt[i][0] = cnt[i][1] = used[i] = usedd[i] = ans[i] = dpp[i] = from[i] = 0;
      |                                                                              ^~~
      |                                                                              abs