Submission #1060323

# Submission time Handle Problem Language Result Execution time Memory
1060323 2024-08-15T12:58:14 Z aymanrs Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 6740 KB
#include<bits/stdc++.h>
using namespace std;
const int nx = 4e5+100;
int st[nx], co[nx], lz[nx];
void cons(int i, int l, int r){
    st[i]=lz[i]=0;
    co[i] = r-l+1;
    if(l==r) return;
    int m = l+r>>1;
    cons(i<<1, l, m);cons(i<<1|1, m+1, r);
}
void upd(int i, int l, int r, int a, int b, int v){
    if(lz[i]){
        st[i] += lz[i];
        if(l!=r){
            lz[i<<1] += lz[i];
            lz[i<<1|1] += lz[i];
        }
        lz[i]=0;
    }
    if(b<l||r<a) return;
    if(a <= l && r <= b) {
        st[i] += v;
        if(l!=r){
            lz[i<<1] += v;
            lz[i<<1|1] += v;
        }
        return;
    }
    int m = l+r>>1;
    upd(i<<1, l, m, a, b, v);upd(i<<1|1, m+1, r, a, b, v);
    st[i] = max(st[i<<1], st[i<<1|1]);
    co[i] = 0;
    if(st[i<<1] == st[i]) co[i]=co[i<<1];
    if(st[i<<1|1] == st[i]) co[i]+=co[i<<1|1];
}
void ans(int n, int k, int a[], int b[]){
    cons(1, 0, n-1);
    for(int i = 0;i < k;i++) {
        upd(1, 0, n-1, max(0, b[a[i]]-k+1), min(n-k,b[a[i]]), 1);
    }
    int tans = st[1];long long c = co[1];
    for(int i = 1;i+k <= n;i++){
        upd(1, 0, n-1, max(0, b[a[i-1]]-k+1), min(n-k,b[a[i-1]]), -1);
        upd(1, 0, n-1, max(0, b[a[i+k-1]]-k+1), min(n-k,b[a[i+k-1]]), 1);
        if(st[1] > tans){
            tans = st[1];
            c = co[1];
        } else if(st[1] == tans) c += co[1];
    }
    cout << tans << ' ' << c << '\n';
}
void solve(){
    int n, k ,q;cin >> n >> k >> q;
    int a[n],b[n+1];
    for(int i = 0;i < n;i++) cin >> a[i];
    for(int i = 0;i < n;i++) {
        int th;cin >> th;
        b[th] = i;
    }
    ans(n, k, a, b);
    while(q--){
        int p;cin >> p;
        p--;
        swap(a[p],a[p+1]);
        ans(n,k,a,b);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Compilation message

Main.cpp: In function 'void cons(int, int, int)':
Main.cpp:9:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    9 |     int m = l+r>>1;
      |             ~^~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:30:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |     int m = l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4444 KB Output is correct
20 Correct 4 ms 4444 KB Output is correct
21 Correct 3 ms 4596 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4664 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4444 KB Output is correct
20 Correct 4 ms 4444 KB Output is correct
21 Correct 3 ms 4596 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4664 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 50 ms 5488 KB Output is correct
32 Correct 52 ms 5316 KB Output is correct
33 Correct 23 ms 5464 KB Output is correct
34 Correct 61 ms 5320 KB Output is correct
35 Correct 102 ms 5468 KB Output is correct
36 Correct 58 ms 5464 KB Output is correct
37 Correct 25 ms 5468 KB Output is correct
38 Correct 92 ms 5468 KB Output is correct
39 Correct 62 ms 5468 KB Output is correct
40 Correct 78 ms 6488 KB Output is correct
41 Correct 83 ms 6740 KB Output is correct
42 Correct 104 ms 6488 KB Output is correct
43 Correct 66 ms 6492 KB Output is correct
44 Correct 55 ms 6600 KB Output is correct
45 Correct 28 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4564 KB Output is correct
20 Correct 3 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 2 ms 4440 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 3 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4444 KB Output is correct
20 Correct 4 ms 4444 KB Output is correct
21 Correct 3 ms 4596 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4664 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4564 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 2 ms 4440 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 3 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Execution timed out 3038 ms 4640 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 3 ms 4440 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4444 KB Output is correct
20 Correct 4 ms 4444 KB Output is correct
21 Correct 3 ms 4596 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4664 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 50 ms 5488 KB Output is correct
32 Correct 52 ms 5316 KB Output is correct
33 Correct 23 ms 5464 KB Output is correct
34 Correct 61 ms 5320 KB Output is correct
35 Correct 102 ms 5468 KB Output is correct
36 Correct 58 ms 5464 KB Output is correct
37 Correct 25 ms 5468 KB Output is correct
38 Correct 92 ms 5468 KB Output is correct
39 Correct 62 ms 5468 KB Output is correct
40 Correct 78 ms 6488 KB Output is correct
41 Correct 83 ms 6740 KB Output is correct
42 Correct 104 ms 6488 KB Output is correct
43 Correct 66 ms 6492 KB Output is correct
44 Correct 55 ms 6600 KB Output is correct
45 Correct 28 ms 6492 KB Output is correct
46 Correct 2 ms 4444 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 2 ms 4564 KB Output is correct
50 Correct 3 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4440 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 2 ms 4444 KB Output is correct
57 Correct 3 ms 4444 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 2 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Execution timed out 3038 ms 4640 KB Time limit exceeded
62 Halted 0 ms 0 KB -