Submission #1114266

# Submission time Handle Problem Language Result Execution time Memory
1114266 2024-11-18T13:20:45 Z epicci23 Sličnost (COI23_slicnost) C++17
50 / 100
137 ms 13136 KB
#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;

const int N = 1e5 + 5;

struct LazySeg{

  vector<array<int,2>> seg;
  vector<int> Lazy;
 
  LazySeg(int n){
  	seg.resize(4*n+5);
  	Lazy.assign(4*n+5,0);
  	build(1,1,n);
  }

  array<int,2> merge(array<int,2> a,array<int,2> b){
    array<int,2> res;
    res[0]=max(a[0],b[0]);
    res[1]=0;
    if(res[0]==a[0]) res[1]+=a[1];
    if(res[0]==b[0]) res[1]+=b[1];
    return res;
  }

  inline void push(int rt, int l, int r){
  	if(Lazy[rt] == 0) return;
    int u = Lazy[rt];
    Lazy[rt] = 0;
    seg[rt][0] += u;
    if(l==r) return;
    Lazy[rt*2] += u;
    Lazy[rt*2+1] += u;
  }

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

  void upd(int rt,int l,int r,int gl,int gr,int u){
  	push(rt,l,r);
  	if(r<gl || l>gr) return;
  	if(l>=gl && r<=gr){
  	  Lazy[rt] += u;
  	  push(rt,l,r);
  	  return;
  	}
  	int m = (l+r)/2;
  	upd(rt*2,l,m,gl,gr,u),upd(rt*2+1,m+1,r,gl,gr,u);
  	seg[rt] = merge(seg[rt*2],seg[rt*2+1]);
  }
 
};



void _(){
  int n,k,q;
  cin >> n >> k >> q;
  int a[n+5],b[n+5];
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n;i++) cin >> b[i];
  
  int ind[n+5],mx=-1,ans=0;
  for(int i=1;i<=n;i++) ind[b[i]]=i;
  
  LazySeg T(n);

  for(int i=1;i<=n;i++){
  	// open number
    int p = ind[a[i]];
    // cout << "p: " << p << '\n';
    T.upd(1,1,n,max(1LL,p-k+1),min(n-k+1,p),1);
    // remove number
    if(i > k){
      p = ind[a[i-k]];
      T.upd(1,1,n,max(1LL,p-k+1),min(n-k+1,p),-1);
    }

    array<int,2> cur = T.seg[1];
    if(cur[0] < mx) continue;
    if(cur[0] > mx){
      mx = cur[0];
      if(i>=k) ans = cur[1];
    }
    else if(i>=k) ans+=cur[1];

    // cout << mx << ' ' << ans << '\n';
  }

  cout << mx << ' ' << ans << '\n';
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 5 ms 984 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 848 KB Output is correct
23 Correct 5 ms 1068 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 1056 KB Output is correct
26 Correct 5 ms 848 KB Output is correct
27 Correct 6 ms 848 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 5 ms 984 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 848 KB Output is correct
23 Correct 5 ms 1068 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 1056 KB Output is correct
26 Correct 5 ms 848 KB Output is correct
27 Correct 6 ms 848 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Correct 61 ms 12880 KB Output is correct
32 Correct 68 ms 12880 KB Output is correct
33 Correct 34 ms 12880 KB Output is correct
34 Correct 84 ms 13000 KB Output is correct
35 Correct 130 ms 13136 KB Output is correct
36 Correct 76 ms 12776 KB Output is correct
37 Correct 34 ms 13128 KB Output is correct
38 Correct 133 ms 12688 KB Output is correct
39 Correct 77 ms 13136 KB Output is correct
40 Correct 96 ms 12624 KB Output is correct
41 Correct 111 ms 12980 KB Output is correct
42 Correct 137 ms 12624 KB Output is correct
43 Correct 83 ms 12624 KB Output is correct
44 Correct 72 ms 13136 KB Output is correct
45 Correct 37 ms 12872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 5 ms 984 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 848 KB Output is correct
23 Correct 5 ms 1068 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 1056 KB Output is correct
26 Correct 5 ms 848 KB Output is correct
27 Correct 6 ms 848 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Incorrect 1 ms 336 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 5 ms 984 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 848 KB Output is correct
23 Correct 5 ms 1068 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 1056 KB Output is correct
26 Correct 5 ms 848 KB Output is correct
27 Correct 6 ms 848 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 3 ms 848 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Correct 61 ms 12880 KB Output is correct
32 Correct 68 ms 12880 KB Output is correct
33 Correct 34 ms 12880 KB Output is correct
34 Correct 84 ms 13000 KB Output is correct
35 Correct 130 ms 13136 KB Output is correct
36 Correct 76 ms 12776 KB Output is correct
37 Correct 34 ms 13128 KB Output is correct
38 Correct 133 ms 12688 KB Output is correct
39 Correct 77 ms 13136 KB Output is correct
40 Correct 96 ms 12624 KB Output is correct
41 Correct 111 ms 12980 KB Output is correct
42 Correct 137 ms 12624 KB Output is correct
43 Correct 83 ms 12624 KB Output is correct
44 Correct 72 ms 13136 KB Output is correct
45 Correct 37 ms 12872 KB Output is correct
46 Incorrect 1 ms 336 KB Output isn't correct
47 Halted 0 ms 0 KB -