Submission #1014454

# Submission time Handle Problem Language Result Execution time Memory
1014454 2024-07-04T22:09:42 Z MarwenElarbi Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 7004 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e5+5;
const int MOD=1e9+7;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
pair<int,int> segtree[nax*4];
int lazy[nax*4];
int n,k,q;
void build(int pos,int l,int r){
    lazy[pos]=0;
    if(l==r){
        if(l<=n-k) segtree[pos]={0,1};
        else segtree[pos]={0,0};
        return;
    }
    int mid=(r+l)/2;
    build(pos*2+1,l,mid);
    build(pos*2+2,mid+1,r);
    segtree[pos].fi=max(segtree[pos*2+1].fi,segtree[pos*2+2].fi);
    if(segtree[pos*2+1].fi==segtree[pos*2+2].fi) segtree[pos].se=segtree[pos*2+1].se+segtree[pos*2+2].se;
    else if(segtree[pos*2+1].fi>segtree[pos*2+2].fi) segtree[pos].se=segtree[pos*2+1].se;
    else segtree[pos].se=segtree[pos*2+2].se;
}
void propagate(int pos){
    if(lazy[pos]!=0){
        lazy[pos*2+1]+=lazy[pos];
        lazy[pos*2+2]+=lazy[pos];
        segtree[pos*2+1].fi+=lazy[pos];
        segtree[pos*2+2].fi+=lazy[pos];
    }
    lazy[pos]=0;
}
void update(int pos,int l,int r,int left,int right,int value){
    if(l>r||l>right||r<left) return;
    if(l>=left&&r<=right){
        segtree[pos].fi+=value;
        lazy[pos]+=value;
        return;
    }
    propagate(pos);
    int mid=(r+l)/2;
    update(pos*2+1,l,mid,left,right,value);
    update(pos*2+2,mid+1,r,left,right,value);
    segtree[pos].fi=max(segtree[pos*2+1].fi,segtree[pos*2+2].fi);
    if(segtree[pos*2+1].fi==segtree[pos*2+2].fi) segtree[pos].se=segtree[pos*2+1].se+segtree[pos*2+2].se;
    else if(segtree[pos*2+1].fi>segtree[pos*2+2].fi) segtree[pos].se=segtree[pos*2+1].se;
    else segtree[pos].se=segtree[pos*2+2].se;
    return;
}
pair<int,int> query(int pos,int l,int r,int left,int right){
    if(l>r||l>right||r<left) return {0,0};
    if(l>=left&&r<=right){
        return segtree[pos];
    }
    propagate(pos);
    int mid=(r+l)/2;
    auto a=query(pos*2+1,l,mid,left,right);
    auto b=query(pos*2+2,mid+1,r,left,right);
    if(a.fi==b.fi) return {a.fi,b.se+a.se};
    else if(a.fi>b.fi) return a;
    else return b;
}
int main()
{
    optimise; 
    cin>>n>>k>>q;
    int a[n];
    int b[n];
    int pos[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin>>b[i];
        pos[b[i]-1]=i;
    }
    for (int i = 0; i < q+1; ++i)
    {
        if(i){
            int x;
            cin>>x;
            x--;
            swap(a[x],a[x+1]);
        }
        build(0,0,n-1);
        int res=0;
        long long cnt=0;
        for (int i = 0; i < k; ++i)
        {
            update(0,0,n-1,max(pos[a[i]-1]-k+1,0),pos[a[i]-1],1);
            /*for (int i = 0; i < n; ++i)
            {
                cout << query(0,0,n-1,i,i).se <<" ";
            }cout <<endl;*/
        }
        //cout <<segtree[0].fi<<" "<<segtree[0].se<<endl;
        res=segtree[0].fi;
        cnt=segtree[0].se;
        for (int i = k; i < n; ++i)
        {
            update(0,0,n-1,max(pos[a[i-k]-1]-k+1,0),pos[a[i-k]-1],-1);
            
            update(0,0,n-1,max(pos[a[i]-1]-k+1,0),pos[a[i]-1],1);
            //cout <<a[i]<<" "<<max(pos[a[i]-1]-k+1,0)<<" "<<pos[a[i]-1]<<endl;
            //cout <<segtree[0].fi<<" "<<segtree[0].se<<endl;
            if(res<segtree[0].fi){
                cnt=segtree[0].se;
                res=segtree[0].fi;
            }else if(res==segtree[0].fi) cnt+=segtree[0].se;
        }
        cout <<res<<" "<<cnt<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 5 ms 2396 KB Output is correct
26 Correct 3 ms 2392 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 5 ms 2396 KB Output is correct
26 Correct 3 ms 2392 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 44 ms 5868 KB Output is correct
32 Correct 47 ms 5720 KB Output is correct
33 Correct 28 ms 5724 KB Output is correct
34 Correct 68 ms 5696 KB Output is correct
35 Correct 94 ms 5724 KB Output is correct
36 Correct 55 ms 5844 KB Output is correct
37 Correct 26 ms 5720 KB Output is correct
38 Correct 87 ms 5968 KB Output is correct
39 Correct 58 ms 5720 KB Output is correct
40 Correct 72 ms 6748 KB Output is correct
41 Correct 79 ms 7004 KB Output is correct
42 Correct 96 ms 6748 KB Output is correct
43 Correct 68 ms 6952 KB Output is correct
44 Correct 54 ms 7004 KB Output is correct
45 Correct 34 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 5 ms 2396 KB Output is correct
26 Correct 3 ms 2392 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 2 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2392 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Execution timed out 3089 ms 2612 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 5 ms 2396 KB Output is correct
26 Correct 3 ms 2392 KB Output is correct
27 Correct 4 ms 2396 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 44 ms 5868 KB Output is correct
32 Correct 47 ms 5720 KB Output is correct
33 Correct 28 ms 5724 KB Output is correct
34 Correct 68 ms 5696 KB Output is correct
35 Correct 94 ms 5724 KB Output is correct
36 Correct 55 ms 5844 KB Output is correct
37 Correct 26 ms 5720 KB Output is correct
38 Correct 87 ms 5968 KB Output is correct
39 Correct 58 ms 5720 KB Output is correct
40 Correct 72 ms 6748 KB Output is correct
41 Correct 79 ms 7004 KB Output is correct
42 Correct 96 ms 6748 KB Output is correct
43 Correct 68 ms 6952 KB Output is correct
44 Correct 54 ms 7004 KB Output is correct
45 Correct 34 ms 7004 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 2 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 2 ms 2396 KB Output is correct
54 Correct 2 ms 2396 KB Output is correct
55 Correct 2 ms 2392 KB Output is correct
56 Correct 2 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 2 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Execution timed out 3089 ms 2612 KB Time limit exceeded
62 Halted 0 ms 0 KB -