Submission #568141

# Submission time Handle Problem Language Result Execution time Memory
568141 2022-05-24T17:04:55 Z abc864197532 Making Friends on Joitter is Fun (JOI20_joitter2) C++17
1 / 100
5000 ms 100768 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    if (a.empty()) return o << "{}";
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
    vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
    vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
    vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
    vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 2000, logN = 20, K = 48763;

set <int> unvis[N], rev[N], norev[N];
set <int> both[N];
int ans = 0;

int main () {
    owo;
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) if (i ^ j)
            unvis[i].insert(j), norev[j].insert(i);
    }
    auto upd = [&](int u, int v) {
        unvis[u].erase(v), norev[v].erase(u), rev[v].insert(u), ans++;
        if (!unvis[v].count(u))
            both[v].insert(u), both[u].insert(v);
    };
    while (q--) {
        int u, v;
        cin >> u >> v, --u, --v;
        if (unvis[u].count(v)) {
            upd(u, v);
            queue <pii> q;
            q.emplace(u, v);
            while (!q.empty()) {
                int u, v; tie(u, v) = q.front(); q.pop();
                vector <pii> add;
                if (unvis[u].size() > both[v].size()) {
                    for (int x : both[v]) if (unvis[u].count(x))
                        add.eb(u, x);
                } else {
                    for (int x : unvis[u]) if (both[v].count(x))
                        add.eb(u, x);
                }
                if (both[u].count(v)) {
                    if (rev[u].size() > norev[v].size()) {
                        for (int x : norev[v]) if (rev[u].count(x))
                            add.eb(x, v);
                    } else {
                        for (int x : rev[u]) if (norev[v].count(x))
                            add.eb(x, v);
                    }
                    swap(v, u);
                    if (rev[u].size() > norev[v].size()) {
                        for (int x : norev[v]) if (rev[u].count(x))
                            add.eb(x, v);
                    } else {
                        for (int x : rev[u]) if (norev[v].count(x))
                            add.eb(x, v);
                    }
                }
                for (auto [u, v] : add)
                    upd(u, v), q.emplace(u, v);
            }
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 700 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 700 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 832 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 824 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 4 ms 852 KB Output is correct
15 Correct 3 ms 852 KB Output is correct
16 Correct 4 ms 940 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 6 ms 968 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 6 ms 864 KB Output is correct
24 Correct 4 ms 852 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 852 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 6 ms 852 KB Output is correct
30 Correct 4 ms 824 KB Output is correct
31 Correct 4 ms 968 KB Output is correct
32 Correct 4 ms 852 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 700 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 700 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 832 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 824 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 4 ms 852 KB Output is correct
15 Correct 3 ms 852 KB Output is correct
16 Correct 4 ms 940 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 6 ms 968 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 6 ms 864 KB Output is correct
24 Correct 4 ms 852 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 852 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 6 ms 852 KB Output is correct
30 Correct 4 ms 824 KB Output is correct
31 Correct 4 ms 968 KB Output is correct
32 Correct 4 ms 852 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
34 Correct 20 ms 1760 KB Output is correct
35 Execution timed out 5038 ms 100768 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 700 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 700 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 832 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 824 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 4 ms 852 KB Output is correct
15 Correct 3 ms 852 KB Output is correct
16 Correct 4 ms 940 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 6 ms 968 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 6 ms 864 KB Output is correct
24 Correct 4 ms 852 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 852 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 6 ms 852 KB Output is correct
30 Correct 4 ms 824 KB Output is correct
31 Correct 4 ms 968 KB Output is correct
32 Correct 4 ms 852 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
34 Correct 20 ms 1760 KB Output is correct
35 Execution timed out 5038 ms 100768 KB Time limit exceeded
36 Halted 0 ms 0 KB -