Submission #66972872
Source Code Expand
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
const int BASE = 911382629;
const int MOD = 1e9+7;
struct HashedString {
vector<long long> prefix;
vector<long long> power;
HashedString(const string& s) {
int n = s.size();
prefix.resize(n+1);
power.resize(n+1);
power[0] = 1;
for(int i=0; i<n; i++) {
prefix[i+1] = (prefix[i]*BASE + s[i]) % MOD;
power[i+1] = (power[i]*BASE) % MOD;
}
}
long long get_hash(int l, int r) {
return (prefix[r] - prefix[l]*power[r-l] % MOD + MOD) % MOD;
}
};
void solve() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<HashedString> h(n, HashedString(""));
vector<HashedString> t;
while(q--) {
int op;
cin >> op;
if(op == 1) {
int p;
cin >> p;
h[p-1] = t.empty() ? HashedString("") : t.back();
}
else if(op == 2) {
int p;
string s;
cin >> p >> s;
string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
h[p-1] = HashedString(new_str);
}
else if(op == 3) {
int p;
cin >> p;
if(!t.empty()) t.pop_back();
t.push_back(h[p-1]);
}
}
if(t.empty()) {
cout << "\n";
} else {
cout << t.back().prefix.back() << "\n";
}
}
int main() {
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Conflict 2 |
| User | wyzl |
| Language | C++ 23 (gcc 12.2) |
| Score | 0 |
| Code Size | 1671 Byte |
| Status | CE |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:53:80: error: no match for ‘operator+’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} and ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’})
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ~~~~~~~~~~~~~~~~~~~~ ^ ~
| | |
| | std::string {aka std::__cxx11::basic_string<char>}
| __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}
In file included from /usr/include/c++/12/string:47,
from /usr/include/c++/12/bits/locale_classes.h:40,
from /usr/include/c++/12/bits/ios_base.h:41,
from /usr/include/c++/12/ios:42,
from /usr/include/c++/12/ostream:38,
from /usr/include/c++/12/iostream:39,
from Main.cpp:1:
/usr/include/c++/12/bits/stl_iterator.h:630:5: note: candidate: ‘template<class _Iterator> constexpr std::reverse_iterator<_IteratorL> std::operator+(typename reverse_iterator<_IteratorL>::difference_type, const reverse_iterator<_IteratorL>&)’
630 | operator+(typename reverse_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:630:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::reverse_iterator<_IteratorL>’
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/stl_iterator.h:1786:5: note: candidate: ‘template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)’
1786 | operator+(typename move_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:1786:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
In file included from /usr/include/c++/12/string:53:
/usr/include/c++/12/bits/basic_string.h:3432:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)’
3432 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3432:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
In file included from /usr/include/c++/12/string:54:
/usr/include/c++/12/bits/basic_string.tcc:606:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)’
606 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.tcc:606:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const _CharT*’ and ‘long long int’
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.tcc:627:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)’
627 | operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.tcc:627:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: deduced conflicting types for parameter ‘_CharT’ (‘long long int’ and ‘char’)
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3472:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)’
3472 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3472:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3489:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)’
3489 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3489:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3502:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)’
3502 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3502:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3509:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)’
3509 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3509:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3516:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)’
3516 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3516:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3539:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)’
3539 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3539:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘const _CharT*’ and ‘long long int’
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3546:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)’
3546 | operator+(_CharT __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3546:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: deduced conflicting types for parameter ‘_CharT’ (‘long long int’ and ‘char’)
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3553:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*)’
3553 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3553:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^
/usr/include/c++/12/bits/basic_string.h:3560:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, _CharT)’
3560 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/12/bits/basic_string.h:3560:5: note: template argument deduction/substitution failed:
Main.cpp:53:82: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Allocator>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’}
53 | string new_str = h[p-1].prefix.empty() ? s : (h[p-1].prefix.back() + s);
| ^