제출 #1324806

#제출 시각아이디문제언어결과실행 시간메모리
1324806comet0Sličnost (COI23_slicnost)C++20
14 / 100
3095 ms6456 KiB
#include <bits/stdc++.h>
using namespace std;

pair<int, long long> f(int n, int k, const vector<int> &p, const vector<int> &q) {
    int m = n - k + 1;
    int z = (n + 63) >> 6;

    vector<vector<unsigned long long>> a(m, vector<unsigned long long>(z, 0));
    vector<vector<unsigned long long>> c(m, vector<unsigned long long>(z, 0));

    for (int i = 0; i < m; i++) {
        for (int t = 0; t < k; t++) {
            int x = p[i + t] - 1;
            a[i][x >> 6] |= 1ULL << (x & 63);
        }
    }
    for (int j = 0; j < m; j++) {
        for (int t = 0; t < k; t++) {
            int x = q[j + t] - 1;
            c[j][x >> 6] |= 1ULL << (x & 63);
        }
    }

    int b = -1;
    long long w = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            int u = 0;
            for (int h = 0; h < z; h++) u += __builtin_popcountll(a[i][h] & c[j][h]);
            if (u > b) {
                b = u;
                w = 1;
            } else if (u == b) {
                w++;
            }
        }
    }
    return {b, w};
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, Q;
    cin >> n >> k >> Q;
    vector<int> p(n), q(n);
    for (int &x : p) cin >> x;
    for (int &x : q) cin >> x;
    
	auto [b, w] = f(n, k, p, q);
	cout << b << ' ' << w << '\n';

    while (Q --> 0) {
		int x; cin >> x; x--;
		swap(p[x], p[x + 1]);
		auto [b, w] = f(n, k, p, q);
		cout << b << ' ' << w << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...