Submission #237565

# Submission time Handle Problem Language Result Execution time Memory
237565 2020-06-07T10:43:27 Z NONAME Pictionary (COCI18_pictionary) C++17
140 / 140
341 ms 15092 KB
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define el '\n'
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;

int n, m, q;
int l[N], r[N], a[N], b[N], pr[N];
vector <int> v[N];

int f(int x) { return (x == pr[x]) ? x : pr[x] = f(pr[x]); }

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> q;

    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i];

        l[i] = 1, r[i] = m;
    }

    bool mk = 1;

    while (mk) {
        for (int i = 1; i <= n; ++i)
            pr[i] = i;

        mk = 0;

        for (int i = 0; i < q; ++i) {
            if (l[i] == r[i])
                continue;

            int md = (l[i] + r[i]) >> 1;

            v[md].pb(i);
            mk = 1;
        }

        for (int md = 1; md <= m; ++md) {
            int p = m - md + 1;

            for (int j = p; j <= n; j += p)
                pr[f(j)] = f(p);

            for (int j = 0; j < sz(v[md]); ++j) {
                int x = v[md][j];

                if (f(a[x]) == f(b[x])) r[x] = md;
                    else l[x] = md + 1;
            }

            v[md].clear();
        }
    }

    for (int i = 0; i < q; ++i)
        cout << l[i] << el;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7416 KB Output is correct
2 Correct 37 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 9160 KB Output is correct
2 Correct 47 ms 8000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 7604 KB Output is correct
2 Correct 78 ms 7156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 8180 KB Output is correct
2 Correct 74 ms 7036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 10308 KB Output is correct
2 Correct 136 ms 7924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 8176 KB Output is correct
2 Correct 214 ms 11508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 12980 KB Output is correct
2 Correct 259 ms 12020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 341 ms 15092 KB Output is correct
2 Correct 296 ms 13504 KB Output is correct