답안 #954510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954510 2024-03-28T05:30:43 Z GrandTiger1729 Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 26364 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
struct Data
{
    long long maxn = 0, cnt = 0;
    Data() = default;
    Data(long long maxn_, long long cnt_) : maxn(maxn_), cnt(cnt_) {}
    inline friend Data merge(Data a, Data b)
    {
        if (a.maxn < b.maxn)
        {
            return b;
        }
        if (a.maxn > b.maxn)
        {
            return a;
        }
        return Data(a.maxn, a.cnt + b.cnt);
    }
};
struct SegTree
{
    int l, r, mid;
    SegTree *lc, *rc;
    Data val_;
    long long lz = 0;
    SegTree(int l_, int r_) : l(l_), r(r_)
    {
        mid = (l + r) / 2;
        if (l == r - 1)
        {
            val_ = Data(0, 1);
            return;
        }
        lc = new SegTree(l, mid);
        rc = new SegTree(mid, r);
        pull();
    }
    ~SegTree()
    {
        if (l == r - 1)
        {
            return;
        }
        delete lc;
        delete rc;
    }
    Data val()
    {
        return Data(val_.maxn + lz, val_.cnt);
    }
    void push()
    {
        if (lz != 0)
        {
            lc->lz += lz;
            rc->lz += lz;
            lz = 0;
        }
    }
    void pull()
    {
        val_ = merge(lc->val(), rc->val());
    }
    void add(int ll, int rr, long long u)
    {
        if (ll <= l && rr >= r)
        {
            lz += u;
            return;
        }
        push();
        if (ll < mid)
        {
            lc->add(ll, rr, u);
        }
        if (mid < rr)
        {
            rc->add(ll, rr, u);
        }
        pull();
    }
    Data query(int ll, int rr)
    {
        if (ll <= l && rr >= r)
        {
            return val();
        }
        push();
        Data ret(-INF, 0);
        if (ll < mid)
        {
            ret = merge(ret, lc->query(ll, rr));
        }
        if (mid < rr)
        {
            ret = merge(ret, rc->query(ll, rr));
        }
        pull();
        return ret;
    }
};

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, K, q;
    cin >> n >> K >> q;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        b[i]--;
    }
    auto solve = [&]()
    {
        vector<int> aa(n), bb(n);
        for (int i = 0; i < n; i++)
        {
            aa[a[i]] = i;
            bb[b[i]] = i;
        }
        vector<vector<int>> add(n + 1), del(n + 1);
        for (int i = 0; i < n; i++)
        {
            add[max(0, aa[i] - (K - 1)) + (K - 1)].push_back(i);
            del[min(n, aa[i] + K)].push_back(i);
        }
        Data ans(-INF, 0);
        SegTree st(0, n);
        for (int t = 0; t <= n; t++)
        {
            for (int id : add[t])
            {
                int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K);
                st.add(l, r, 1);
            }
            for (int id : del[t])
            {
                int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K);
                st.add(l, r, -1);
            }
            Data res = st.query(K - 1, n);
            ans = merge(ans, res);
        }
        cout << ans.maxn << ' ' << ans.cnt << '\n';
    };
    solve();
    while (q--)
    {
        int i;
        cin >> i;
        i--;
        swap(a[i], a[i + 1]);
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 4 ms 1564 KB Output is correct
20 Correct 6 ms 1880 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 2 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1732 KB Output is correct
25 Correct 5 ms 1576 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
27 Correct 6 ms 1700 KB Output is correct
28 Correct 5 ms 1372 KB Output is correct
29 Correct 4 ms 1368 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 4 ms 1564 KB Output is correct
20 Correct 6 ms 1880 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 2 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1732 KB Output is correct
25 Correct 5 ms 1576 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
27 Correct 6 ms 1700 KB Output is correct
28 Correct 5 ms 1372 KB Output is correct
29 Correct 4 ms 1368 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 109 ms 25712 KB Output is correct
32 Correct 127 ms 25540 KB Output is correct
33 Correct 56 ms 20168 KB Output is correct
34 Correct 108 ms 22864 KB Output is correct
35 Correct 202 ms 26364 KB Output is correct
36 Correct 93 ms 25024 KB Output is correct
37 Correct 51 ms 20768 KB Output is correct
38 Correct 176 ms 25108 KB Output is correct
39 Correct 102 ms 26064 KB Output is correct
40 Correct 137 ms 23132 KB Output is correct
41 Correct 148 ms 24376 KB Output is correct
42 Correct 195 ms 24896 KB Output is correct
43 Correct 117 ms 22884 KB Output is correct
44 Correct 99 ms 22708 KB Output is correct
45 Correct 65 ms 20740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 3 ms 484 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 3 ms 472 KB Output is correct
28 Correct 3 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 4 ms 1564 KB Output is correct
20 Correct 6 ms 1880 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 2 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1732 KB Output is correct
25 Correct 5 ms 1576 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
27 Correct 6 ms 1700 KB Output is correct
28 Correct 5 ms 1372 KB Output is correct
29 Correct 4 ms 1368 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 3 ms 344 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 3 ms 344 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 3 ms 484 KB Output is correct
38 Correct 3 ms 348 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 4 ms 348 KB Output is correct
42 Correct 3 ms 472 KB Output is correct
43 Correct 3 ms 344 KB Output is correct
44 Correct 4 ms 348 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Execution timed out 3034 ms 2068 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 4 ms 1564 KB Output is correct
20 Correct 6 ms 1880 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 2 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1732 KB Output is correct
25 Correct 5 ms 1576 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
27 Correct 6 ms 1700 KB Output is correct
28 Correct 5 ms 1372 KB Output is correct
29 Correct 4 ms 1368 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 109 ms 25712 KB Output is correct
32 Correct 127 ms 25540 KB Output is correct
33 Correct 56 ms 20168 KB Output is correct
34 Correct 108 ms 22864 KB Output is correct
35 Correct 202 ms 26364 KB Output is correct
36 Correct 93 ms 25024 KB Output is correct
37 Correct 51 ms 20768 KB Output is correct
38 Correct 176 ms 25108 KB Output is correct
39 Correct 102 ms 26064 KB Output is correct
40 Correct 137 ms 23132 KB Output is correct
41 Correct 148 ms 24376 KB Output is correct
42 Correct 195 ms 24896 KB Output is correct
43 Correct 117 ms 22884 KB Output is correct
44 Correct 99 ms 22708 KB Output is correct
45 Correct 65 ms 20740 KB Output is correct
46 Correct 3 ms 344 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 2 ms 348 KB Output is correct
49 Correct 3 ms 344 KB Output is correct
50 Correct 4 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 3 ms 484 KB Output is correct
53 Correct 3 ms 348 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 4 ms 348 KB Output is correct
57 Correct 3 ms 472 KB Output is correct
58 Correct 3 ms 344 KB Output is correct
59 Correct 4 ms 348 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
61 Execution timed out 3034 ms 2068 KB Time limit exceeded
62 Halted 0 ms 0 KB -