답안 #936926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936926 2024-03-03T03:59:20 Z _callmelucian Matching (CEOI11_mat) C++14
63 / 100
665 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

struct pBIT {
    vector<vector<pii>> tr;
    pBIT (int sz) : tr(sz + 1, vector<pii>(1, make_pair(-1, 0))) {}

    int get (int k, int ver) {
        auto it = upper_bound(all(tr[k]), make_pair(ver, INT_MAX));
        return (it == tr[k].begin() ? 0 : prev(it)->second);
    }

    int p (int k) { return k & -k; }

    void update (int k, int val, int ver) {
        for (; k < tr.size(); k += p(k)) {
            int cur = tr[k].back().second + val;
            tr[k].push_back(make_pair(ver, cur));
        }
    }

    int query (int k, int ver, int ans = 0) {
        for (; k; k -= p(k)) ans += get(k, ver);
        return ans;
    }
};

vector<int> pFunc (vector<int> vec, int sz) {
    int n = vec.size();
    vector<int> pi(n);

    pBIT tree(sz);
    for (int i = 0; i < n; i++)
        if (vec[i] < INT_MAX) tree.update(vec[i], 1, i);

    function<int(int,int)> countSmall = [&] (int l, int r) {
        return tree.query(vec[r], r) - (l? tree.query(vec[r], l - 1) : 0);
    };
    function<bool(int,int)> same = [&] (int i, int j) {
        // [0..i-1] + i == [j-i..j-1] + j
        //return true;
        if (vec[i] == INT_MAX || vec[j] == INT_MAX) return false;
        return countSmall(0, i) == countSmall(j - i, j);
    };

    for (int i = 1; i < n; i++) {
        int j = pi[i - 1];
        while (j && !same(j, i)) j = pi[j - 1];
        if (same(j, i)) pi[i] = j + 1;
    }
    return pi;
}

map<int,int> mp;

void compress() {
    int mark = 0;
    for (pii it : mp) mp[it.first] = ++mark;
}

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

    int n, m; cin >> n >> m;
    vector<int> s(n), h(m);
    for (int i = 1; i <= n; i++) {
        int p; cin >> p;
        s[p - 1] = i;
    }
    for (int i = 0; i < m; i++) {
        cin >> h[i];
        mp[h[i]] = 0;
    }
    compress();

    vector<int> vec = s;
    vec.push_back(INT_MAX);
    for (int u : h) vec.push_back(mp[u]);

    vector<int> pi = pFunc(vec, max(n, m)), ans;
    for (int i = 0; i < pi.size(); i++)
        if (pi[i] == n) ans.push_back(i - 2 * n + 1);

    cout << ans.size() << "\n";
    for (int u : ans) cout << u << " ";

    return 0;
}

Compilation message

mat.cpp: In member function 'void pBIT::update(int, int, int)':
mat.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (; k < tr.size(); k += p(k)) {
      |                ~~^~~~~~~~~~~
mat.cpp: In function 'int main()':
mat.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int i = 0; i < pi.size(); i++)
      |                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 5076 KB Output is correct
2 Correct 28 ms 4816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 5328 KB Output is correct
2 Correct 31 ms 5336 KB Output is correct
3 Correct 5 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 341 ms 48396 KB Output is correct
2 Correct 257 ms 45256 KB Output is correct
3 Correct 641 ms 57328 KB Output is correct
4 Correct 665 ms 57976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 54740 KB Output is correct
2 Correct 576 ms 50480 KB Output is correct
3 Correct 352 ms 49704 KB Output is correct
4 Correct 248 ms 46536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 52988 KB Output is correct
2 Correct 326 ms 53472 KB Output is correct
3 Correct 436 ms 50968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 526 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 530 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 495 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 541 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -