Submission #1093591

# Submission time Handle Problem Language Result Execution time Memory
1093591 2024-09-27T04:42:44 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(){
    build(0,0,n-k);
    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);
    }
    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;
    }
    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 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 1 ms 412 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 4 ms 856 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 604 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 1 ms 412 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 4 ms 856 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 604 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 62 ms 8880 KB Output is correct
32 Correct 66 ms 8828 KB Output is correct
33 Correct 12 ms 2524 KB Output is correct
34 Correct 53 ms 5720 KB Output is correct
35 Correct 96 ms 8840 KB Output is correct
36 Correct 65 ms 8796 KB Output is correct
37 Correct 14 ms 3160 KB Output is correct
38 Correct 112 ms 8840 KB Output is correct
39 Correct 70 ms 8796 KB Output is correct
40 Correct 83 ms 5724 KB Output is correct
41 Correct 73 ms 8788 KB Output is correct
42 Correct 103 ms 8796 KB Output is correct
43 Correct 54 ms 5720 KB Output is correct
44 Correct 39 ms 5720 KB Output is correct
45 Correct 14 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 1 ms 412 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 4 ms 856 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 604 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 1 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 1 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 2 ms 344 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Execution timed out 3026 ms 980 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 1 ms 412 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 4 ms 856 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 604 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 62 ms 8880 KB Output is correct
32 Correct 66 ms 8828 KB Output is correct
33 Correct 12 ms 2524 KB Output is correct
34 Correct 53 ms 5720 KB Output is correct
35 Correct 96 ms 8840 KB Output is correct
36 Correct 65 ms 8796 KB Output is correct
37 Correct 14 ms 3160 KB Output is correct
38 Correct 112 ms 8840 KB Output is correct
39 Correct 70 ms 8796 KB Output is correct
40 Correct 83 ms 5724 KB Output is correct
41 Correct 73 ms 8788 KB Output is correct
42 Correct 103 ms 8796 KB Output is correct
43 Correct 54 ms 5720 KB Output is correct
44 Correct 39 ms 5720 KB Output is correct
45 Correct 14 ms 2908 KB Output is correct
46 Correct 1 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 1 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 2 ms 344 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Execution timed out 3026 ms 980 KB Time limit exceeded
62 Halted 0 ms 0 KB -