QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356659#6567. Repetitive String Inventionec1117Compile Error//C++144.0kb2024-03-18 07:12:462024-03-18 07:12:46

Judging History

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

  • [2024-03-18 07:12:46]
  • 评测
  • [2024-03-18 07:12:46]
  • 提交

answer

#include <bits/stdc++.h>
#include <random>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi; 
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define For(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7;
const int MX = 807;
const int MX2 = 407;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

/**
 * Description: Multiply two 64-bit integers mod another if 128-bit is not available.
	* modMul is equivalent to \texttt{(ul)(\_\_int128(a)*b\%mod)}. 
	* Works for $0\le a,b<mod<2^{63}.$
 * Source: KACTL
 * Verification: see "Faster Factoring"
 */

typedef unsigned long long ul;
ul modMul(ul a, ul b, const ul mod) {
	ll ret = a*b-mod*(ul)((ld)a*b/mod);
	return ret+((ret<0)-(ret>=(ll)mod))*mod; }
ul modPow(ul a, ul b, const ul mod) {
	if (b == 0) return 1;
	ul res = modPow(a,b/2,mod); res = modMul(res,res,mod);
	return b&1 ? modMul(res,a,mod) : res;
}

unordered_map<pi,int> M;
int pr = 1007, pw[MX];
unordered_map<int,int> toPush[MX][MX], toPush2[MX][MX2], have[MX2], have2[MX2];

unordered_map<int,int> sameLen[MX];
//have is when later is longer end
//have2 is for shorter end

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string S;cin>>S;
	int n = sz(S);
	pw[0]=1;
	ll ans = 0;
	FOR(i,1,n+1)
		pw[i] = pw[i-1]*pr%MOD;

	For(i,n) {
		ll cur = 0;
		FOR(j,i,n) {
			cur = (cur*pr+ (S[j]-'a')+1)%MOD;
			M[{i,j}] = cur;
		}
	}

	
	ll ans2 = 0;
	For(i,n) {
		FOR(j,i,n) { // i to j
			ans2 += sameLen[j-i+1][M[{i,j}]];
		}
		For(j,i+1) {// j to i
			int len = i-j+1;
			sameLen[len][M[{j,i}]]++;
		}

	}

	For(i,n) {
		For(j,n+1) { //j is needLen
			trav(x,toPush2[i][j]) {
				have2[j][x.f] += x.s;
			}
			trav(x,toPush[i][j]) {
				have[j][x.f] += x.s;
			}
		}

		ll cur = 0;
		FOR(j,i,n) { //i st, j end
			int len = j-i+1;
			cur = (cur*pr+ (S[j]-'a')+1)%MOD;
			
			for(int k=j-1;k>=0 && 2*(k-i+1)>len; k--) { // i to k
				dbg(i,k,j);
				int newLen = k-i+1;
				int needLen = 2*newLen - len;

				// ll val = v[k-i];
				ll val = M[{i,k}];
				ll fin = (val*pw[newLen]+val)%MOD;
				ll want = (fin-(cur*pw[needLen])%MOD+MOD)%MOD;
				dbg("D",val,fin,want,needLen);
				toPush2[j+1][needLen][want]++;

			}
			dbg("A",j+1,len,cur);
			toPush[j+1][len][cur]++;
		}
		
		cur = 0;
		FOR(j,i,n) { // second part
			int len = j-i+1;
			cur = (cur*pr+ (S[j]-'a')+1)%MOD;

			dbg("C",len,cur, have2[len][cur]);
			ans += have2[len][cur];

			for(int k=i+1;k<j && 2*(j-k+1)>len;k++) { // k to j
				int newLen = j-k+1;
				int needLen = 2*newLen - len;

				ll val = M[{k,j}];
				ll fin = (val*pw[newLen]+val)%MOD;
				ll want = ((fin-cur)%MOD+MOD)*modPow(pw[len],MOD-2,MOD)%MOD;
				dbg("B",val, fin, needLen,want, have[needLen][want]);
				ans += have[needLen][want];
			}

		}
	}
	dbg(ans2);
	cout << ans+ans2 << '\n';

}

/*
FOR(i,1,n+1) {
	int cur = 0;
	For(j,n) {
		cur = (cur*pr + (S[j]-'a'))%MOD;
		if(j>=i-1) {
			M[i][cur]++;
		}
	}
}

FOR(i,1,n/2+1) {
	//count strings of len 2i
	int len = 2*i;
	FOR(j,1,len) {
		int k = 2*i-j;
		

	}
}

*/


/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

詳細信息

answer.code:62:23: error: use of deleted function ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]’
   62 | unordered_map<pi,int> M;
      |                       ^
In file included from /usr/include/c++/13/unordered_map:41,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:188,
                 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<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, 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<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, 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<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, 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<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, 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<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, 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<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]’
/usr/include/c++/13/bits/hashtable_policy.h: In instantiation of ‘std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<int, int> >]’:
/usr/include/c++/13/bits/hashtable_policy.h:1297:7:   required from here
/usr/include/c++/13/bits/hashtable_policy.h:1214:49: error: use of deleted function ‘std::hash<std::pair<int, int> >::hash()’
 1214 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included ...