QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406817#5100. 卡牌游戏IratisCompile Error//C++201.7kb2024-05-07 19:00:542024-05-07 19:01:14

Judging History

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

  • [2024-05-07 19:01:14]
  • 评测
  • [2024-05-07 19:00:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)

bool ST;

const int N=500005;
int n,S,Type,Tid,B,a[N],Ans[N];
int f[N],g[N][2],pos[2],q[710][2],gcd[710][710];vector<int>inc[710];
inline int lcm(int x,int y){if(x>y)swap(x,y);if(x<=B)return x*y/gcd[x][y%x];return x*y/__gcd(x,y);}
inline int w(int x,int y){int d=lcm(x,y);return (S/d)*d;}

inline void New(int j,int i,int v)
{
	f[i]=max(f[i],f[j]+v);
}

bool ED;

signed main()
{
    // int time_st=clock();
	cerr<<(&ST-&ED)/1024.0/1024<<endl;ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>S>>Type>>Tid;assert(Type==0);B=sqrt(S);for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=0;i<=B;i++)for(int j=0;j<=B;j++)if(i||j)gcd[i][j]=__gcd(i,j);
	for(int i=n;i>=1;i--)if(a[i]<=B)inc[a[i]].push_back(i);int mx=1;
	for(int i=1;i<=n;i++)
	{
		f[i]=max(f[i],f[i-1]);while(mx<i-1&&f[mx]+S<=f[i])mx++;
		if(i-mx<=100){for(int j=mx;j<i;j++)f[i]=max(f[i],f[j]+w(a[j],a[i]));}
		else
		{
			for(int t=0;t<2;t++)if(pos[t])New(pos[t],i,w(a[pos[t]],a[i]));
			for(int j=1;j<=B;j++)for(int t=0;t<2;t++)if(q[j][t])New(q[j][t],i,w(j,a[i]));
			if(a[i]>B){for(int j=a[i];j<=S;j+=a[i])for(int t=0;t<2;t++)if(g[j][t])New(g[j][t],i,j);}
		}

		if(a[i]<=B)pos[0]=pos[1],pos[1]=i,q[a[i]][0]=q[a[i]][1],q[a[i]][1]=i;
		else
		{
			for(int j=a[i];j<=S;j+=a[i])g[j][0]=g[j][1],g[j][1]=i;
			for(int j=1;j<=B;j++)
			{
				while(!inc[j].empty()&&inc[j].back()<=i)inc[j].pop_back();int s=inc[j].size();
				if(s>=1)New(i,inc[j][s-1],w(j,a[i]));if(s>=2)New(i,inc[j][s-2],w(j,a[i]));
			}
		}
	}
	cout<<f[n]<<'\n';
    // cerr<<(clock()-time_st)/1e6<<endl;return 0;
}

详细

answer.code: In function ‘long long int lcm(long long int, long long int)’:
answer.code:12:65: error: reference to ‘gcd’ is ambiguous
   12 | inline int lcm(int x,int y){if(x>y)swap(x,y);if(x<=B)return x*y/gcd[x][y%x];return x*y/__gcd(x,y);}
      |                                                                 ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58,
                 from answer.code:1:
/usr/include/c++/13/numeric:164:5: note: candidates are: ‘template<class _Mn, class _Nn> constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn)’
  164 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
answer.code:11:35: note:                 ‘long long int gcd [710][710]’
   11 | int f[N],g[N][2],pos[2],q[710][2],gcd[710][710];vector<int>inc[710];
      |                                   ^~~
answer.code: In function ‘int main()’:
answer.code:27:59: error: reference to ‘gcd’ is ambiguous
   27 |         for(int i=0;i<=B;i++)for(int j=0;j<=B;j++)if(i||j)gcd[i][j]=__gcd(i,j);
      |                                                           ^~~
/usr/include/c++/13/numeric:164:5: note: candidates are: ‘template<class _Mn, class _Nn> constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn)’
  164 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
answer.code:11:35: note:                 ‘long long int gcd [710][710]’
   11 | int f[N],g[N][2],pos[2],q[710][2],gcd[710][710];vector<int>inc[710];
      |                                   ^~~