QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131688#4676. Amalgamated ArtichokesPetroTarnavskyi#RE 0ms0kbC++172.1kb2023-07-27 21:08:282023-07-27 21:08:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 21:08:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-27 21:08:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;


typedef complex<double> base;
const int LEN = 1 << 20;
base PW[LEN];

void fft(vector<base>& a, bool invert)
{
	int lg = 0;
	while ((1 << lg) < SZ(a)) lg++;
	FOR (i, 0, SZ(a))
	{
		int x = 0;
		FOR (j, 0, lg)
			x |= ((i >> j) & 1) << (lg - j - 1);
		if (i < x)
			swap(a[i], a[x]);
	}
	for (int len = 2; len <= SZ(a); len *= 2)
	{
		int diff = LEN / len;
		if (invert) diff = LEN - diff;
		for (int i = 0; i < SZ(a); i += len)
		{
			int pos = 0;
			FOR (j, 0, len / 2)
			{
				base v = a[i + j];
				base u = a[i + j + len / 2] * PW[pos];
				
				a[i + j] = v + u;
				a[i + j + len / 2] = v - u;
				
				pos += diff;
				if (pos >= LEN) pos -= LEN;
			}
		}
	}
	if (invert)
		FOR (i, 0, SZ(a))
			a[i] /= SZ(a);
}

const double PI = acos(-1);

void initFFT()
{
	double angle = 2 * PI / LEN;
	FOR (i, 0, LEN)
	{
		double ca = angle * i;
		PW[i] = base(cos(ca), sin(ca));
	}
}

const int N = 1 << 19;

int pr[N];



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	FOR(p, 2, N)
	{
		if(pr[p] != 0)
			continue;
		pr[p] = p;
		for(int j = 2 * p; j < N; j += p)
			pr[j] = p;
	}
	VI dv(N);
	dv[1] = 1;
	FOR(i, 2, N)
	{
		int n = i;
		int p = pr[n];
		
		int cnt = 0;
		while(n % p == 0)
		{
			n /= p;
			cnt++;
		}
		dv[i] = dv[n] * (cnt + 1);
	}
	vector<base> v(LEN);
	FOR (i, 0, N) v[i] = base(dv[i], 0);
	
	initFFT();
	fft(v, false);
	FOR (i, 0, LEN) v[i] *= v[i];
	fft(v, true);
	
	FOR (i, 0, N) dv[i] = v[i].real();


	int q;
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		
		int j = max_element(dv.begin() + l, dv.begin() + r + 1) - dv.begin();
			
		
		cout << j << " " << dv[j] << endl;
	}
	
	
	
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

42 1 23 4 8 10

output:

22 236
8 37

result: