QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771532#9250. Max GCD401rk8#TL 13ms75336kbC++172.8kb2024-11-22 13:56:172024-11-22 13:56:18

Judging History

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

  • [2024-11-22 13:56:18]
  • 评测
  • 测评结果:TL
  • 用时:13ms
  • 内存:75336kb
  • [2024-11-22 13:56:17]
  • 提交

answer

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mkp make_pair
#define mem(a,x,n) memset(a,x,sizeof(a[0])*(n+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }

const int mod = 998244353;
struct mint {
	int x; mint(int x=0):x(x<0?x+mod:x<mod?x:x-mod){}
	mint(LL y) { y%=mod, x=y<0?y+mod:y; }
	mint& operator += (const mint &y) { x=x+y.x<mod?x+y.x:x+y.x-mod; return *this; }
	mint& operator -= (const mint &y) { x=x<y.x?x-y.x+mod:x-y.x; return *this; }
	mint& operator *= (const mint &y) { x=1ll*x*y.x%mod; return *this; }
	friend mint operator + (mint x,const mint &y) { return x+=y; }
	friend mint operator - (mint x,const mint &y) { return x-=y; }
	friend mint operator * (mint x,const mint &y) { return x*=y; }
};	mint Pow(mint x,LL y=mod-2) { mint z(1);for(;y;y>>=1,x*=x)if(y&1)z*=x;return z; }

const int N = 1e6+5;
int n,m,ans[N];
Vi pos[N];
vector<Pii> a[N],q[N];

#define ls (u<<1)
#define rs (u<<1|1)
#define mid (l+r>>1)
#define root int u=1,int l=1,int r=n
#define lson ls,l,mid
#define rson rs,mid+1,r
int t[N*4];
void mdf(int ql,int qr,int x,root) {
	if( qr < l || r < ql || x <= t[u] ) return;
	if( ql <= l && r <= qr ) { t[u] = x; return; }
	mdf(ql,qr,x,lson), mdf(ql,qr,x,rson);
}
int qry(int p,root) {
	if( l == r ) return t[u];
	return max(t[u], p<=mid?qry(p,lson):qry(p,rson));
}

void MAIN() {
	cin>>n>>m;
	For(i,1,n, x) {
		cin>>x;
		for(int j = 2; j*j <= x; ++j) if( !(x % j) ) {
			pos[j].pb(i);
			if( j*j != x ) pos[x/j].pb(i);
		}
		pos[x].pb(i);
	}
	rFor(i,1e6,2)
		Rep(j,1,sz(pos[i])) {
			auto it = lower_bound(all(pos[i]),pos[i][j]+pos[i][j]-pos[i][j-1]);
			if( it != pos[i].end() ) a[pos[i][j-1]].pb(*it,i);
		}
	For(i,1,m, l,r) if(cin>>l>>r; r-l > 1 ) q[l].pb(i,r);
	mdf(1,n,1);
	rFor(i,n,1) {
		for(auto [j,x] : a[i]) mdf(j,n,x);
		for(auto [id,j] : q[i]) ans[id] = qry(j);
	}
	For(i,1,m) cout<<ans[i]<<'\n';
} signed main() {
#ifdef FS
	freopen("in","r",stdin); freopen("out","w",stdout);
#endif
	ios::sync_with_stdio(0);cin.tie(0);
	int lft=1; while( lft-- ) {
		MAIN();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 75336kb

input:

8 8
8 24 4 6 6 7 3 3
1 5
2 6
3 7
5 8
4 8
1 3
2 5
3 8

output:

4
2
3
1
3
4
2
3

result:

ok 8 tokens

Test #2:

score: -100
Time Limit Exceeded

input:

150000 100000
982800 554400 665280 982800 997920 720720 786240 831600 997920 982800 786240 982800 942480 831600 887040 665280 831600 960960 786240 982800 786240 942480 665280 831600 942480 665280 982800 960960 960960 997920 720720 960960 960960 665280 982800 665280 982800 942480 786240 997920 554400...

output:


result: