Submission #1093593

# Submission time Handle Problem Language Result Execution time Memory
1093593 2024-09-27T04:45:27 Z Luvidi Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 8880 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back

const int maxn=1e5;
int n,k,q,a[maxn],b[maxn],idx[maxn];
pair<pll,ll> seg[4*maxn+31];

void prop(int v){
    seg[2*v+1].fs.fs+=seg[v].sc;
    seg[2*v+1].sc+=seg[v].sc;
    seg[2*v+2].fs.fs+=seg[v].sc;
    seg[2*v+2].sc+=seg[v].sc;
    seg[v].sc=0;
}

pll merge(pll p1,pll p2){
    ll x=max(p1.fs,p2.fs);
    ll y=0;
    if(p1.fs==x)y+=p1.sc;
    if(p2.fs==x)y+=p2.sc;
    return {x,y};
}

void build(int v,int l,int r){
    if(l==r){
        seg[v]={{0,1},0};
        return;
    }
    int m=(l+r)/2;
    build(2*v+1,l,m);
    build(2*v+2,m+1,r);
    seg[v]={merge(seg[2*v+1].fs,seg[2*v+2].fs),0};
}

void upd(int v,int l,int r,int l2,int r2,int x){
    if(l>r2||r<l2)return;
    if(l2<=l&&r<=r2){
        seg[v].fs.fs+=x;
        seg[v].sc+=x;
        return;
    }
    prop(v);
    int m=(l+r)/2;
    upd(2*v+1,l,m,l2,r2,x);
    upd(2*v+2,m+1,r,l2,r2,x);
    seg[v].fs=merge(seg[2*v+1].fs,seg[2*v+2].fs);
}

void upd(int i,int x){
    i=idx[a[i]];
    upd(0,0,n-k,max(0,i-(k-1)),min(i,n-k),x);
}

void calc(){
    pll ans={0,0};
    for(int i=0;i<k-1;i++){
        upd(i,1);
    }
    for(int i=0;i<=n-k;i++){
        upd(i+k-1,1);
        ans=merge(ans,seg[0].fs);
        upd(i,-1);
    }
    for(int i=n-k+1;i<n;i++){
        upd(i,-1);
    }
    cout<<ans.fs<<' '<<ans.sc<<'\n';
}

void solve(){
    cin>>n>>k>>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        cin>>b[i];;
        idx[--b[i]]=i;
    }
    build(0,0,n-k);
    calc();
    while(q--){
        int idx;
        cin>>idx;
        swap(a[idx],a[idx-1]);
        calc();
    }
}

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

    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 976 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 976 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 53 ms 8796 KB Output is correct
32 Correct 63 ms 8796 KB Output is correct
33 Correct 14 ms 2644 KB Output is correct
34 Correct 62 ms 5724 KB Output is correct
35 Correct 90 ms 8880 KB Output is correct
36 Correct 62 ms 8792 KB Output is correct
37 Correct 14 ms 3160 KB Output is correct
38 Correct 86 ms 8792 KB Output is correct
39 Correct 63 ms 8792 KB Output is correct
40 Correct 73 ms 5720 KB Output is correct
41 Correct 80 ms 8796 KB Output is correct
42 Correct 100 ms 8840 KB Output is correct
43 Correct 64 ms 5724 KB Output is correct
44 Correct 51 ms 5724 KB Output is correct
45 Correct 18 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 976 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Execution timed out 3064 ms 976 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 976 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 53 ms 8796 KB Output is correct
32 Correct 63 ms 8796 KB Output is correct
33 Correct 14 ms 2644 KB Output is correct
34 Correct 62 ms 5724 KB Output is correct
35 Correct 90 ms 8880 KB Output is correct
36 Correct 62 ms 8792 KB Output is correct
37 Correct 14 ms 3160 KB Output is correct
38 Correct 86 ms 8792 KB Output is correct
39 Correct 63 ms 8792 KB Output is correct
40 Correct 73 ms 5720 KB Output is correct
41 Correct 80 ms 8796 KB Output is correct
42 Correct 100 ms 8840 KB Output is correct
43 Correct 64 ms 5724 KB Output is correct
44 Correct 51 ms 5724 KB Output is correct
45 Correct 18 ms 2904 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Execution timed out 3064 ms 976 KB Time limit exceeded
62 Halted 0 ms 0 KB -