Submission #1107589

# Submission time Handle Problem Language Result Execution time Memory
1107589 2024-11-01T15:48:57 Z cpptowin Colors (RMI18_colors) C++17
0 / 100
94 ms 34908 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 200010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define bitcout(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
#define UNIQUE(v) v.erase(unique(all(v)), v.end())
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    if (x >= mod)
        x -= mod;
}
struct event
{
    int u, szu, v, szv;
    event(int u, int szu, int v, int szv) : u(u), szu(szu), v(v), szv(szv){};
};
struct DSU
{
    vi par, sz;
    DSU(int n) : par(n), sz(n){};
    stack<event> st;
    void rollback(int x)
    {
        if (st.empty())
            return;
        while (st.size() > x)
        {
            auto top = st.top();
            st.pop();
            par[top.v] = top.v;
            sz[top.v] = top.szv;
            par[top.u] = top.u;
            sz[top.u] = top.szu;
        }
    }
    void make(int u)
    {
        par[u] = u;
        sz[u] = 1;
    }
    int find(int u)
    {
        return u == par[u] ? u : find(par[u]);
    }
    void Union(int u, int v)
    {
        u = find(u);
        v = find(v);
        if (u == v)
            return;
        if (sz[u] < sz[v])
            swap(u, v);
        st.push(event(u, sz[u], v, sz[v]));
        sz[u] += sz[v];
        par[v] = u;
    }
} g(maxn);
vii st[4 * maxn];
void up(int id, int l, int r, int u, int v, pii edge)
{
    if (l > v or r < u)
        return;
    if (u <= l and r <= v)
    {
        st[id].pb(edge);
        return;
    }
    int mid = l + r >> 1;
    up(id << 1, l, mid, u, v, edge);
    up(id << 1 | 1, mid + 1, r, u, v, edge);
}
int n, m, a[maxn], b[maxn];
vi ca[maxn], cb[maxn];
bool ok;
void dfs(int id, int l, int r)
{
    int timer = ss(g.st);
    for (auto [u, v] : st[id])
        g.Union(u, v);
    if (l == r)
    {
        map<int,bool> st;
        for (int it : ca[l])
            st[g.find(it)] = 1;
        for (int it : cb[l])
            if (!st.count(g.find(it)))
                ok = 0;
    }
    if (l != r)
    {
        int mid = l + r >> 1;
        dfs(id << 1, l, mid);
        dfs(id << 1 | 1, mid + 1, r);
    }
    g.rollback(timer);
}
void solve()
{
    ok = 1;
    cin >> n >> m;
    fo(i, 1, n) g.make(i);
    fo(i, 1, 4 * n + 5) st[i].clear();
    fo(i, 1, n) ca[i].clear(), cb[i].clear();
    fo(i, 1, n) cin >> a[i], ca[a[i]].pb(i);
    fo(i, 1, n) cin >> b[i], cb[b[i]].pb(i);
    fo(i, 1, n) 
    {
        if(a[i] < b[i]) 
        {
            cout << 0;en;
            return;
        }
    }
    fo(i, 1, m)
    {
        int u, v;
        cin >> u >> v;
        int l = max(b[u], b[v]);
        int r = min(a[u], a[v]);
        if(l <= r)
        up(1, 1, n, l, r, {u, v});
    }
    dfs(1, 1, n);
    cout << ok;
    en;
}
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin >> T;
    while (T--)
        solve();
}

Compilation message

colors.cpp: In member function 'void DSU::rollback(int)':
colors.cpp:64:26: warning: comparison of integer expressions of different signedness: 'std::stack<event>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |         while (st.size() > x)
      |                ~~~~~~~~~~^~~
colors.cpp: In function 'void up(int, int, int, int, int, std::pair<int, int>)':
colors.cpp:106:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |     int mid = l + r >> 1;
      |               ~~^~~
colors.cpp: In function 'void dfs(int, int, int)':
colors.cpp:129:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  129 |         int mid = l + r >> 1;
      |                   ~~^~~
colors.cpp: At global scope:
colors.cpp:165:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  165 | main()
      | ^~~~
colors.cpp: In function 'int main()':
colors.cpp:170:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  170 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
colors.cpp:171:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  171 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 33208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 32508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 33096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 33096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 33208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 34908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 32304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 33208 KB Output isn't correct
2 Halted 0 ms 0 KB -