QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609888#7780. Dark LaTeX vs. Light LaTeXucup-team2179#Compile Error//C++203.1kb2024-10-04 14:20:342024-10-04 14:20:35

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 20:53:52]
  • hack成功,自动添加数据
  • (/hack/1258)
  • [2024-10-04 14:20:35]
  • 评测
  • [2024-10-04 14:20:34]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define db double
#define pii pair<int, int>
using namespace std;
const int maxn = 6e3 + 10;
struct exKMP {
    int z[maxn];
    void get_z(string& c) {
        int len = c.length();
        int p = 0, k = 1, l;
        z[0] = len;
        while (p + 1 < len && c[p] == c[p + 1])
            p++;
        z[1] = p;
        for (int i = 2; i < len; i++) {
            p = k + z[k] - 1;
            l = z[i - k];
            if (i + l <= p)
                z[i] = l;
            else {
                int j = max(0ll, p - i + 1);
                while (i + j < len && c[i + j] == c[j])
                    j++;
                z[i] = j;
                k = i;
            }
        }
    }
} Z;
unordered_map<pii, int> mps, mpt;
const int base = 131, mod1 = 998244353, mod2 = 1e9 + 7;
int mi1[maxn], mi2[maxn];
pii h1[maxn], h2[maxn];
pii get_hash(pii h[], int l, int r) {
    l--;
    pii res;
    res.first = ((h[r].first - h[l].first * mi1[r - l]) % mod1 + mod1) % mod1;
    res.second = ((h[r].second - h[l].second * mi2[r - l]) % mod2 + mod2) % mod2;
    return res;
}
int sub[maxn][maxn];
int cal(string s, string t, int id) {
    int n = s.length(), m = t.length();
    for (int i = 1; i <= n; i++) {
        h1[i].first = (h1[i - 1].first * base + s[i - 1]) % mod1;
        h1[i].second = (h1[i - 1].second * base + s[i - 1]) % mod2;
    }
    for (int i = 1; i <= m; i++) {
        h2[i].first = (h2[i - 1].first * base + t[i - 1]) % mod1;
        h2[i].second = (h2[i - 1].second * base + t[i - 1]) % mod2;
    }
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++) 
            mps[get_hash(h1, i, j)]++;
    for (int i = 1; i <= m; i++)
        for (int j = i; j <= m; j++)
            mpt[get_hash(h2, i, j)]++;
    int ans = 0;
    if (id == 0) {
    for (auto it : mps)
        ans += it.second * mpt[it.first];
    }
    // cout << "same" << ans << endl;
    for (int i = 1; i <= n; i++) {
        string str2 = s.substr(i - 1);
        Z.get_z(str2);
        for (int j = 3; j <= str2.length(); j++) {
            int mxlen = min(Z.z[j - 1], j - 1);
            if (!mxlen) continue;
            // 右端点在 j - 1, 左端点在 2 到 mxlen + 1
            sub[i - 1 + j - 1][i - 1 + 2]++;
            sub[i - 1 + j - 1][i - 1 + mxlen + 1 + 1]--;
        }
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= i; j++) {
            sub[i][j] += sub[i][j - 1];
            if (sub[i][j] > 0) {
                ans += sub[i][j] * mpt[get_hash(h1, j, i)];
                // cout << "l, r = " << j << " " << i << endl;
            }
        }
    return ans;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    mi1[0] = mi2[0] = 1;
    for (int i = 1; i < maxn; i++) {
        mi1[i] = mi1[i - 1] * base % mod1;
        mi2[i] = mi2[i - 1] * base % mod2;
    }
    string s, t;
    cin >> s >> t;
    int res = cal(s, t, 0);
    memset(sub, 0, sizeof sub);
    mps.clear();
    mpt.clear();
    res += cal(t, s, 1);
    cout << res << endl;
    return 0;
}

Details

answer.code:32:25: error: use of deleted function ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Hash = std::hash<std::pair<long long int, long long int> >; _Pred = std::equal_to<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >]’
   32 | unordered_map<pii, int> mps, mpt;
      |                         ^~~
In file included from /usr/include/c++/13/unordered_map:41,
                 from /usr/include/c++/13/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from answer.code:1:
/usr/include/c++/13/bits/unordered_map.h:148:7: note: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Hash = std::hash<std::pair<long long int, long long int> >; _Pred = std::equal_to<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >]’ is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/13/bits/unordered_map.h:148:7: error: use of deleted function ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<const std::pair<long long int, long long int>, long long int>; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /usr/include/c++/13/bits/unordered_map.h:33:
/usr/include/c++/13/bits/hashtable.h:530:7: note: ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<const std::pair<long long int, long long int>, long long int>; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
  530 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<const std::pair<long long int, long long int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /usr/include/c++/13/bits/hashtable.h:35:
/usr/include/c++/13/bits/hashtable_policy.h:1710:7: note: ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<const std::pair<long long int, long long int>, long long int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
 1710 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1710:7: error: use of deleted function ‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<const std::pair<long long int, long long int>, long long int>; _ExtractKey = std::__detail:...