/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.773 MiB
#2 Accepted 3ms 2.77 MiB
#3 Wrong Answer 4ms 2.707 MiB
#4 Wrong Answer 5ms 2.812 MiB
#5 Wrong Answer 51ms 4.176 MiB
#6 Wrong Answer 38ms 4.242 MiB
#7 Wrong Answer 443ms 17.18 MiB
#8 Wrong Answer 448ms 17.18 MiB
#9 Wrong Answer 447ms 17.086 MiB
#10 Wrong Answer 227ms 14.156 MiB

Code

//....................................<In the name of Allah>...............................//

//.................................<b_bitsmillahir Rahmanir Rahim>...................................//
// Author : Riaj Udd_bitn

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pii;
typedef pair<double, double> pdd;

typedef double dl;

#define lower(a, b) lower_bound((a).begin(), (a).end(), b) - (a).begin()
#define mem(a, b) memset(a, b, sizeof(a));

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

#define fraction(a)               \
    cout.unsetf(ios::floatfield); \
    cout.precision(a);            \
    cout.setf(ios::fined, ios::floatfield);
//////////////////////////////////////////
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p)
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << it->first << " = " << it->second;
    }
    return os << "]";
}

#define dbg(args...)            \
    do                          \
    {                           \
        cerr << #args << " : "; \
        faltu(args);            \
    } while (0)

void faltu()
{
    cerr << endl;
}

template <typename T>
void faltu(T a[], ll n)
{
    for (ll i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename... hello>
void faltu(T arg, const hello &...rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

///////////b_bitt-manipulation///////////////
#define Mb(msk) 63 - __builtin_clzll(msk)
#define Lb(msk) __builtin_ctzll(msk)
#define ONE(msk) __builtin_popkll(msk)
#define CHECK(msk, b_bitt) (msk & (1LL << b_bitt))
#define ON(msk, b_bitt) (msk | (1LL << b_bitt))
#define Off(msk, b_bitt) (msk & ~(1LL << b_bitt))
#define CHANGE(msk, b_bitt) (msk ^ (1LL << b_bitt))

//////////////

const ll N = 1e5 + 123, inf = 1e9 + 9;
struct st_lazy
{

    vector<ll> t, lazy;
    ll n;

    st_lazy(ll n)
    {
        this->n = n;
        t.resize(4 * n, 0);
        lazy.resize(4 * n, 0);
    }
    void push(ll nod, ll a, ll b)
    {
        if (lazy[nod] == 0)
            return;
        t[nod] += (b - a + 1) * lazy[nod];

        if (a != b)
        {
            lazy[nod << 1] += lazy[nod];
            // lazy[nod << 1] %= 2;
            lazy[nod << 1 | 1] += lazy[nod];
            // lazy[nod << 1 | 1] %= 2;
        }

        lazy[nod] = 0;
    }

    void update(ll nod, ll a, ll b, ll l, ll r, ll x)
    {
        push(nod, a, b);
        if (r < a || b < l)
            return;
        if (l == a && b == r)
        {
            lazy[nod] += x;
            push(nod, a, b);
            return;
        }

        ll mid = (a + b) >> 1;
        update(nod << 1, a, mid, l, min(r, mid), x);
        update(nod << 1 | 1, mid + 1, b, max(l, mid + 1), r, x);
    }

    ll query(ll nod, ll a, ll b, ll idx)
    {
        push(nod, a, b);
        if (idx == a && idx == b)
            return t[nod];

        ll mid = (a + b) >> 1;
        if (idx > mid)
            return query(nod << 1 | 1, mid + 1, b, idx);
        else
            return query(nod << 1, a, mid, idx);
    }
};

vector<ll> g[N];
ll li[N], in[N], out[N];
ll tim = 0;

void dfs(ll node, ll par)
{
    in[node] = ++tim;

    for (auto u : g[node])
    {
        if (u != par)
        {
            dfs(u, node);
        }
    }
    out[node] = tim;
}

void solve(int tc)
{
    ll n, q;
    cin >> n >> q;
    for (ll i = 1; i <= n; i++)
        cin >> li[i];
    for (ll i = 0; i < n - 1; i++)
    {
        ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, -1);
    st_lazy tr(n + 1);

    for (int i = 1; i <= q; i++)
    {
        ll nd;
        cin >> nd;
        tr.update(1, 1, n, in[nd], out[nd], 1);
    }
    for (ll i = 1; i <= n; i++)
    {
        ll tot = tr.query(1, 1, n, in[i]);
        if (tot & 1)
            li[i] ^= 1;
    }
    cout << "Case " << tc << ": ";
    for (ll i = 1; i <= n; i++)
        cout << li[i] << " ";
    cout << "\n";
    for (ll i = 0; i <= n; i++)
    {
        g[i].clear();
        in[i] = out[i] = li[i] = 0;
    }
    tim = 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1, cs = 0;
    cin >> t;
    for (int tc = 1; tc <= t; tc++)
    {
        solve(tc);
    }
}

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:06:10
Judged At
2024-10-03 17:06:10
Judged By
Score
0
Total Time
448ms
Peak Memory
17.18 MiB