QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#552096#9250. Max GCDucup-team159#TL 0ms26652kbC++234.0kb2024-09-07 20:33:072024-09-07 20:33:07

Judging History

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

  • [2024-09-07 20:33:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:26652kb
  • [2024-09-07 20:33:07]
  • 提交

answer

#line 1 "I.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")

#line 2 "/home/sigma/comp/library/template.hpp"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
#line 5 "I.cpp"

struct segtree{
	using D = int;
	D inf = 1e9;

	int N;
	vector<D> val;

	segtree(){}
	segtree(int n){
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,-inf);
	}
	segtree(const vector<D>& ds){
		int n = ds.size();
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,-inf);
		rep(i,n) val[i+N] = ds[i];
		for(int i=N-1;i>0;i--) val[i] = max(val[i*2],val[i*2+1]);
	}
	void changemax(int k,D d){
		k+=N;
		chmax(val[k],d);
		k/=2;
		while(k){
			val[k] = max(val[k*2],val[k*2+1]);
			k/=2;
		}
	}
	D getmax(int a,int b){
		D res = -inf;
		a+=N,b+=N;
		while(a<b){
			if(a&1) chmax(res,val[a++]);
			if(b&1) chmax(res,val[--b]);
			a/=2,b/=2;
		}
		return res;
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	const int X = 1000000;
	int N,Q; cin >> N >> Q;
	V<int> A(N); rep(i,N) cin >> A[i];
	VV<int> d2is(X+1);
	rep(i,N){
		int a = A[i];
		for(int x=1;x*x<=a;x++) if(a%x == 0){
			d2is[x].eb(i);
			if(x*x != a) d2is[a/x].eb(i);
		}
	}

	using P = pair<int,int>;
	VV<P> k2ids(N);
	rep1(d,X) if(si(d2is[d]) >= 3){
		auto& is = d2is[d];
		int K = si(is);
		rep(i,K-2){
			int j = i+1;
			int k = lwb(is,is[j]*2-is[i]);
			if(k != K){
				k2ids[is[k]].eb(is[i],d);
			}
		}
	}
	VV<P> r2lqs(N);
	rep(q,Q){
		int l,r; cin >> l >> r; l--,r--;
		r2lqs[r].eb(l,q);
	}
	segtree seg(N);
	V<int> ans(Q);
	rep(r,N){
		// add k = r
		for(auto [i,d]: k2ids[r]){
			seg.changemax(i, d);
		}
		for(auto [l,q]: r2lqs[r]){
			ans[q] = seg.getmax(l,N);
		}
	}
	rep(q,Q) cout << ans[q] << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 26652kb

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: