QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267716#7748. Karshilov's Matching Problem IIredwhiteCompile Error//C++173.5kb2023-11-27 16:52:422023-11-27 16:52:43

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2023-11-27 16:52:43]
  • 评测
  • [2023-11-27 16:52:42]
  • 提交

answer

/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 6e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, m, pref[N], z[N], mx=0, ansp[N], anss[N], ans[N];
ll par[N], tree[N], lps[N];
int seg[2*N], mark[N];
string s, t, str;
vector<int> adj[N];

queue<int> q;
void dfs(int v) {
	mark[v] = 1; q.push(v);
	while(size(q) > 0) {
		int u = q.front();
		q.pop();
		for(auto it : adj[u]) {
			if(mark[it] == 1) continue;
			tree[it] += (tree[u] + (u<=2*n ? pref[u+1]-pref[u] : 0));
			q.push(it); mark[it] = 1;
		}
	}
}

void build(int ind=1) {
	if(ind >= (1<<lg)) {
		int id = ind-(1<<lg)+1;
		seg[ind] = (id<=n ? z[n+id]+id-1 : 0);
		return ;
	} 
	build(2*ind); build(2*ind+1);
	seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}

int vec[N], nxt = 0;
void query2(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
	if(r<=lc || rc<=l) return;
	if(lc>=l && rc<=r) {
		vec[++nxt] = ind; return;
	}
	int mid = (lc+rc)/2;
	query2(l, r, 2*ind, lc, mid);
	query2(l, r, 2*ind+1, mid, rc);
}

int query3(int r, int ind) {
	if(ind>=(1<<lg)) return (ind-(1<<lg)+1);
	if(seg[2*ind] >= r) return query3(r, 2*ind);
	return query3(r, 2*ind+1);
}

int query(int l, int r)  {
	nxt = 0;
	query2(l, r);
	for(int i=1; i<=nxt; i++) {
		if(seg[vec[i]] >= r) return query3(r, vec[i]);
	}
	return -1;
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>m>>s>>t;
	for(int i=1; i<=n; i++) {cin>>pref[i]; pref[i] += pref[i-1];}

	str = s+'#'+t;

	adj[2*n+1].pb(0);
	for(int i=1; i<=2*n; i++) {
		if(mx+z[mx] > i) {
			z[i] = min(mx+z[mx]-i, z[i-mx]);
		}
		while(z[i]<=2*n && str[z[i]+i]==str[z[i]]) {
			z[i]++;
		}
		if(z[i]+i > mx) mx = i;

		int k = lps[i-1];
		while(k>0&&str[k]!=str[i]) {
			k = lps[k-1];
		}
		lps[i] = k+(str[i]==str[k]);
		par[i] = lps[i]-1;
		if(lps[i]!=0)adj[lps[i]-1].pb(i);
		else adj[2*n+1].pb(i);
	}

	dfs(2*n+1);
	build(1);
	ansp[0] = tree[0] + pref[1];
	for(int i=1; i<=2*n; i++) {
		ansp[i] = ansp[i-1] + tree[i] + (pref[i+1]-pref[i]);
	}
	for(int i=2*n; i>=n+1; i--) {
		anss[i] = anss[i+1] + pref[z[i]];
	}

	
	for(int l,r,i=1; i<=m; i++) {
		cin>>l>>r;
		int x = query(l, r+1);
		if(x == -1) {
			cout<<anss[n+l]-anss[n+r+1]<<endl;
		} else {
			cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
		}
	}	

	return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:144:79: error: no matching function for call to ‘min(int&, ll)’
  144 |                         cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
      |                                                                            ~~~^~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:4:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)’
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
answer.code:144:79: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘ll’ {aka ‘long long int’})
  144 |                         cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
      |                                                                            ~~~^~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:4:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
answer.code:144:79: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘ll’ {aka ‘long long int’})
  144 |                         cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
      |                                                                            ~~~^~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:4:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)’
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
answer.code:144:79: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
  144 |                         cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
      |                                                                            ~~~^~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:4:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)’
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
answer.code:144:79: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
  144 |                         cout<<(r-x<0 ? 0 : ansp[r-x]) + anss[n+l] - anss[n+min(x,n+1)]<<endl;
      |                                                                            ~~~^~~~~~~