답안 #1017914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017914 2024-07-09T11:25:57 Z stefanopulos Sličnost (COI23_slicnost) C++17
100 / 100
1429 ms 433312 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ldb;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;
 
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for(auto& a : x)
 
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)
 
const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 100005; 
 
int n, k, q;
int A[mxN];
int B[mxN];
 
int poz[mxN];
 
int L[mxN];
int R[mxN];
 
int idx = 0;
int ls[250 * mxN], rs[250 * mxN], root[250 * mxN];
int mx[250 * mxN], sum[250 * mxN], cnt[250 * mxN];
void build(int& v, int tl, int tr){
    v = ++idx;
    if(tl == tr){
        mx[v] = sum[v] = 0;
        cnt[v] = 1;
        return;
    }
    int mid = (tl + tr) / 2;
    build(ls[v], tl, mid); build(rs[v], mid + 1, tr);
 
    sum[v] = sum[ls[v]] + sum[rs[v]];
    mx[v] = max(mx[ls[v]], mx[rs[v]] + sum[ls[v]]);
    cnt[v] = (mx[v] == mx[ls[v]] ? cnt[ls[v]] : 0) + (mx[v] == mx[rs[v]] + sum[ls[v]] ? cnt[rs[v]] : 0);
}
 
void update(int& v, int rv, int tl, int tr, int pos, int val){
    v = ++idx; ls[v] = ls[rv]; rs[v] = rs[rv]; mx[v] = mx[rv]; sum[v] = sum[rv]; cnt[v] = cnt[rv];
    if(tl == tr){
        mx[v] += val;
        sum[v] += val;
        return;
    }
    int mid = (tl + tr) / 2;
    if(pos <= mid)update(ls[v], ls[rv], tl, mid, pos, val);
    else update(rs[v], rs[rv], mid + 1, tr, pos, val);
 
    sum[v] = sum[ls[v]] + sum[rs[v]];
    mx[v] = max(mx[ls[v]], mx[rs[v]] + sum[ls[v]]);
    cnt[v] = (mx[v] == mx[ls[v]] ? cnt[ls[v]] : 0) + (mx[v] == mx[rs[v]] + sum[ls[v]] ? cnt[rs[v]] : 0);
 
}
 
struct SegTree{
    ll bor[4 * mxN][2];
    void update(int v, int tl, int tr, int pos, int val, ll cnt){
        if(tl == tr){
            bor[v][0] = val;
            bor[v][1] = cnt;
            return;
        }
        int mid = (tl + tr) / 2;
        if(pos <= mid)update(v * 2, tl, mid, pos, val, cnt);
        else update(v * 2 + 1, mid + 1, tr, pos, val, cnt);
        bor[v][0] = max(bor[v * 2][0], bor[v * 2 + 1][0]);
        bor[v][1] = (bor[v][0] == bor[v * 2][0] ? bor[v * 2][1] : 0) + (bor[v][0] == bor[v * 2 + 1][0] ? bor[v * 2 + 1][1] : 0);
    }
}drvo;
 
void calc(){
 
    idx = 0;
    build(root[k],1,n - k + 1);
    ff(i,1,k){
        int l = L[poz[A[i]]];
        int r = R[poz[A[i]]];
        update(root[k],root[k],1,n - k + 1,l,1);
        if(r < n - k + 1)update(root[k],root[k],1,n - k + 1,r + 1,-1);
    }
    
    drvo.update(1,1,n - k + 1,1,mx[root[k]],cnt[root[k]]);
    ff(i,k + 1,n){
        int l1 = L[poz[A[i - k]]];
        int r1 = R[poz[A[i - k]]];
        update(root[i],root[i - 1],1,n - k + 1,l1,-1);
        if(r1 < n - k + 1)update(root[i],root[i],1,n - k + 1,r1 + 1,1);
 
        int l2 = L[poz[A[i]]];
        int r2 = R[poz[A[i]]];
        update(root[i],root[i],1,n - k + 1,l2,1);
        if(r2 < n - k + 1)update(root[i],root[i],1,n - k + 1,r2 + 1,-1);
 
        drvo.update(1,1,n - k + 1,i - k + 1,mx[root[i]],cnt[root[i]]);
 
    }
 
}
 
int main(){
    cin.tie(0)->sync_with_stdio(0);
 
    cin >> n >> k >> q;
    ff(i,1,n)cin >> A[i];
    ff(i,1,n)cin >> B[i], poz[B[i]] = i;
 
    ff(i,1,n){
        L[i] = max(1, i - k + 1);
        R[i] = min(i, n - k + 1);
    }
 
    calc();
 
    int najv = drvo.bor[1][0]; ll br = drvo.bor[1][1];
    cout << najv << " " << br << '\n';
    while(q--){
        int t;
        cin >> t;
 
        if(t - k + 1 >= 1){
            int x = t;
            if(mx[root[x]] == najv)br -= cnt[root[x]];
 
            int l1 = L[poz[A[t]]];
            int r1 = R[poz[A[t]]];
            update(root[x],root[x],1,n - k + 1,l1,-1);
            if(r1 < n - k + 1)update(root[x],root[x],1,n - k + 1,r1 + 1,1);
 
            int l2 = L[poz[A[t + 1]]];
            int r2 = R[poz[A[t + 1]]];
            update(root[x],root[x],1,n - k + 1,l2,1);
            if(r2 < n - k + 1)update(root[x],root[x],1,n - k + 1,r2 + 1,-1);
 
            drvo.update(1,1,n - k + 1,x - k + 1,mx[root[x]],cnt[root[x]]);
 
        }
 
        if(t + k <= n){
            int x = t + k;
            if(mx[root[x]] == najv)br -= cnt[root[x]];
 
            int l1 = L[poz[A[t + 1]]];
            int r1 = R[poz[A[t + 1]]];
            update(root[x],root[x],1,n - k + 1,l1,-1);
            if(r1 < n - k + 1)update(root[x],root[x],1,n - k + 1,r1 + 1,1);
 
            int l2 = L[poz[A[t]]];
            int r2 = R[poz[A[t]]];
            update(root[x],root[x],1,n - k + 1,l2,1);
            if(r2 < n - k + 1)update(root[x],root[x],1,n - k + 1,r2 + 1,-1);
 
            drvo.update(1,1,n - k + 1,x - k + 1,mx[root[x]],cnt[root[x]]);
 
        }
 
        swap(A[t], A[t + 1]);
 
        najv = drvo.bor[1][0]; br = drvo.bor[1][1];
        cout << najv << " " << br << '\n';
 
    }
 
    return 0;
}
/*
 
4 3 0
2 4 1 3
1 2 3 4
 
 
5 3 1
1 4 3 2 5
4 5 1 2 3
3
 
 
 
// probati bojenje sahovski
*/
 
 
 
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 8 ms 23132 KB Output is correct
17 Correct 8 ms 23128 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 9 ms 23048 KB Output is correct
21 Correct 8 ms 23132 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 9 ms 23132 KB Output is correct
24 Correct 8 ms 23132 KB Output is correct
25 Correct 6 ms 18988 KB Output is correct
26 Correct 7 ms 21084 KB Output is correct
27 Correct 9 ms 23128 KB Output is correct
28 Correct 6 ms 19036 KB Output is correct
29 Correct 4 ms 16928 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 8 ms 23132 KB Output is correct
17 Correct 8 ms 23128 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 9 ms 23048 KB Output is correct
21 Correct 8 ms 23132 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 9 ms 23132 KB Output is correct
24 Correct 8 ms 23132 KB Output is correct
25 Correct 6 ms 18988 KB Output is correct
26 Correct 7 ms 21084 KB Output is correct
27 Correct 9 ms 23128 KB Output is correct
28 Correct 6 ms 19036 KB Output is correct
29 Correct 4 ms 16928 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 238 ms 154960 KB Output is correct
32 Correct 246 ms 154012 KB Output is correct
33 Correct 16 ms 14676 KB Output is correct
34 Correct 139 ms 88128 KB Output is correct
35 Correct 303 ms 157520 KB Output is correct
36 Correct 194 ms 146336 KB Output is correct
37 Correct 44 ms 42324 KB Output is correct
38 Correct 279 ms 150864 KB Output is correct
39 Correct 196 ms 156752 KB Output is correct
40 Correct 181 ms 100464 KB Output is correct
41 Correct 201 ms 115536 KB Output is correct
42 Correct 265 ms 142420 KB Output is correct
43 Correct 153 ms 92064 KB Output is correct
44 Correct 115 ms 77648 KB Output is correct
45 Correct 52 ms 43348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 1 ms 14684 KB Output is correct
18 Correct 1 ms 10712 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 2 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14804 KB Output is correct
25 Correct 1 ms 14832 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 1 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 8 ms 23132 KB Output is correct
17 Correct 8 ms 23128 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 9 ms 23048 KB Output is correct
21 Correct 8 ms 23132 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 9 ms 23132 KB Output is correct
24 Correct 8 ms 23132 KB Output is correct
25 Correct 6 ms 18988 KB Output is correct
26 Correct 7 ms 21084 KB Output is correct
27 Correct 9 ms 23128 KB Output is correct
28 Correct 6 ms 19036 KB Output is correct
29 Correct 4 ms 16928 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 2 ms 14680 KB Output is correct
32 Correct 1 ms 14684 KB Output is correct
33 Correct 1 ms 10712 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 2 ms 14684 KB Output is correct
38 Correct 2 ms 14684 KB Output is correct
39 Correct 2 ms 14804 KB Output is correct
40 Correct 1 ms 14832 KB Output is correct
41 Correct 2 ms 14684 KB Output is correct
42 Correct 2 ms 14684 KB Output is correct
43 Correct 2 ms 14684 KB Output is correct
44 Correct 2 ms 14684 KB Output is correct
45 Correct 1 ms 14684 KB Output is correct
46 Correct 20 ms 29184 KB Output is correct
47 Correct 24 ms 29276 KB Output is correct
48 Correct 2 ms 10840 KB Output is correct
49 Correct 12 ms 23128 KB Output is correct
50 Correct 26 ms 28500 KB Output is correct
51 Correct 5 ms 16988 KB Output is correct
52 Correct 12 ms 25300 KB Output is correct
53 Correct 25 ms 27940 KB Output is correct
54 Correct 24 ms 28248 KB Output is correct
55 Correct 9 ms 23076 KB Output is correct
56 Correct 24 ms 28664 KB Output is correct
57 Correct 25 ms 28212 KB Output is correct
58 Correct 7 ms 19032 KB Output is correct
59 Correct 18 ms 27352 KB Output is correct
60 Correct 6 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 1 ms 14752 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 1 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 1 ms 14684 KB Output is correct
12 Correct 2 ms 14680 KB Output is correct
13 Correct 2 ms 14680 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 1 ms 14684 KB Output is correct
16 Correct 8 ms 23132 KB Output is correct
17 Correct 8 ms 23128 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 9 ms 23048 KB Output is correct
21 Correct 8 ms 23132 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 9 ms 23132 KB Output is correct
24 Correct 8 ms 23132 KB Output is correct
25 Correct 6 ms 18988 KB Output is correct
26 Correct 7 ms 21084 KB Output is correct
27 Correct 9 ms 23128 KB Output is correct
28 Correct 6 ms 19036 KB Output is correct
29 Correct 4 ms 16928 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 238 ms 154960 KB Output is correct
32 Correct 246 ms 154012 KB Output is correct
33 Correct 16 ms 14676 KB Output is correct
34 Correct 139 ms 88128 KB Output is correct
35 Correct 303 ms 157520 KB Output is correct
36 Correct 194 ms 146336 KB Output is correct
37 Correct 44 ms 42324 KB Output is correct
38 Correct 279 ms 150864 KB Output is correct
39 Correct 196 ms 156752 KB Output is correct
40 Correct 181 ms 100464 KB Output is correct
41 Correct 201 ms 115536 KB Output is correct
42 Correct 265 ms 142420 KB Output is correct
43 Correct 153 ms 92064 KB Output is correct
44 Correct 115 ms 77648 KB Output is correct
45 Correct 52 ms 43348 KB Output is correct
46 Correct 2 ms 14680 KB Output is correct
47 Correct 1 ms 14684 KB Output is correct
48 Correct 1 ms 10712 KB Output is correct
49 Correct 2 ms 14684 KB Output is correct
50 Correct 2 ms 14684 KB Output is correct
51 Correct 2 ms 14684 KB Output is correct
52 Correct 2 ms 14684 KB Output is correct
53 Correct 2 ms 14684 KB Output is correct
54 Correct 2 ms 14804 KB Output is correct
55 Correct 1 ms 14832 KB Output is correct
56 Correct 2 ms 14684 KB Output is correct
57 Correct 2 ms 14684 KB Output is correct
58 Correct 2 ms 14684 KB Output is correct
59 Correct 2 ms 14684 KB Output is correct
60 Correct 1 ms 14684 KB Output is correct
61 Correct 20 ms 29184 KB Output is correct
62 Correct 24 ms 29276 KB Output is correct
63 Correct 2 ms 10840 KB Output is correct
64 Correct 12 ms 23128 KB Output is correct
65 Correct 26 ms 28500 KB Output is correct
66 Correct 5 ms 16988 KB Output is correct
67 Correct 12 ms 25300 KB Output is correct
68 Correct 25 ms 27940 KB Output is correct
69 Correct 24 ms 28248 KB Output is correct
70 Correct 9 ms 23076 KB Output is correct
71 Correct 24 ms 28664 KB Output is correct
72 Correct 25 ms 28212 KB Output is correct
73 Correct 7 ms 19032 KB Output is correct
74 Correct 18 ms 27352 KB Output is correct
75 Correct 6 ms 19036 KB Output is correct
76 Correct 964 ms 427092 KB Output is correct
77 Correct 1008 ms 431320 KB Output is correct
78 Correct 31 ms 15952 KB Output is correct
79 Correct 509 ms 183260 KB Output is correct
80 Correct 1371 ms 433312 KB Output is correct
81 Correct 107 ms 74684 KB Output is correct
82 Correct 503 ms 266580 KB Output is correct
83 Correct 1305 ms 416340 KB Output is correct
84 Correct 894 ms 420292 KB Output is correct
85 Correct 245 ms 181780 KB Output is correct
86 Correct 1429 ms 413172 KB Output is correct
87 Correct 1380 ms 405796 KB Output is correct
88 Correct 232 ms 101968 KB Output is correct
89 Correct 1035 ms 303628 KB Output is correct
90 Correct 172 ms 95060 KB Output is correct