답안 #954508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954508 2024-03-28T05:29:10 Z GrandTiger1729 Sličnost (COI23_slicnost) C++17
57 / 100
2035 ms 524288 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();
    }
    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 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1624 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 4 ms 1628 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1628 KB Output is correct
25 Correct 5 ms 1372 KB Output is correct
26 Correct 5 ms 1368 KB Output is correct
27 Correct 5 ms 1628 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1624 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 4 ms 1628 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1628 KB Output is correct
25 Correct 5 ms 1372 KB Output is correct
26 Correct 5 ms 1368 KB Output is correct
27 Correct 5 ms 1628 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 107 ms 24924 KB Output is correct
32 Correct 116 ms 25888 KB Output is correct
33 Correct 44 ms 20400 KB Output is correct
34 Correct 108 ms 23216 KB Output is correct
35 Correct 174 ms 26604 KB Output is correct
36 Correct 89 ms 25356 KB Output is correct
37 Correct 48 ms 21148 KB Output is correct
38 Correct 159 ms 25440 KB Output is correct
39 Correct 111 ms 26444 KB Output is correct
40 Correct 139 ms 23440 KB Output is correct
41 Correct 136 ms 24748 KB Output is correct
42 Correct 178 ms 25168 KB Output is correct
43 Correct 116 ms 23216 KB Output is correct
44 Correct 109 ms 22868 KB Output is correct
45 Correct 56 ms 21308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 4 ms 1624 KB Output is correct
20 Correct 4 ms 1476 KB Output is correct
21 Correct 3 ms 1368 KB Output is correct
22 Correct 4 ms 1628 KB Output is correct
23 Correct 4 ms 1372 KB Output is correct
24 Correct 4 ms 1628 KB Output is correct
25 Correct 3 ms 1368 KB Output is correct
26 Correct 4 ms 1628 KB Output is correct
27 Correct 4 ms 1484 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Correct 4 ms 1628 KB Output is correct
30 Correct 3 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1624 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 4 ms 1628 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1628 KB Output is correct
25 Correct 5 ms 1372 KB Output is correct
26 Correct 5 ms 1368 KB Output is correct
27 Correct 5 ms 1628 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 4 ms 1628 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 4 ms 1624 KB Output is correct
35 Correct 4 ms 1476 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 4 ms 1628 KB Output is correct
38 Correct 4 ms 1372 KB Output is correct
39 Correct 4 ms 1628 KB Output is correct
40 Correct 3 ms 1368 KB Output is correct
41 Correct 4 ms 1628 KB Output is correct
42 Correct 4 ms 1484 KB Output is correct
43 Correct 3 ms 1372 KB Output is correct
44 Correct 4 ms 1628 KB Output is correct
45 Correct 3 ms 1628 KB Output is correct
46 Runtime error 2035 ms 524288 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1624 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 4 ms 1628 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 5 ms 1628 KB Output is correct
24 Correct 4 ms 1628 KB Output is correct
25 Correct 5 ms 1372 KB Output is correct
26 Correct 5 ms 1368 KB Output is correct
27 Correct 5 ms 1628 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 107 ms 24924 KB Output is correct
32 Correct 116 ms 25888 KB Output is correct
33 Correct 44 ms 20400 KB Output is correct
34 Correct 108 ms 23216 KB Output is correct
35 Correct 174 ms 26604 KB Output is correct
36 Correct 89 ms 25356 KB Output is correct
37 Correct 48 ms 21148 KB Output is correct
38 Correct 159 ms 25440 KB Output is correct
39 Correct 111 ms 26444 KB Output is correct
40 Correct 139 ms 23440 KB Output is correct
41 Correct 136 ms 24748 KB Output is correct
42 Correct 178 ms 25168 KB Output is correct
43 Correct 116 ms 23216 KB Output is correct
44 Correct 109 ms 22868 KB Output is correct
45 Correct 56 ms 21308 KB Output is correct
46 Correct 3 ms 1628 KB Output is correct
47 Correct 4 ms 1628 KB Output is correct
48 Correct 2 ms 1372 KB Output is correct
49 Correct 4 ms 1624 KB Output is correct
50 Correct 4 ms 1476 KB Output is correct
51 Correct 3 ms 1368 KB Output is correct
52 Correct 4 ms 1628 KB Output is correct
53 Correct 4 ms 1372 KB Output is correct
54 Correct 4 ms 1628 KB Output is correct
55 Correct 3 ms 1368 KB Output is correct
56 Correct 4 ms 1628 KB Output is correct
57 Correct 4 ms 1484 KB Output is correct
58 Correct 3 ms 1372 KB Output is correct
59 Correct 4 ms 1628 KB Output is correct
60 Correct 3 ms 1628 KB Output is correct
61 Runtime error 2035 ms 524288 KB Execution killed with signal 9
62 Halted 0 ms 0 KB -