QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281256#1264. Lower AlgorithmicsKLPP#TL 3366ms310708kbC++202.9kb2023-12-10 00:53:562023-12-10 00:53:56

Judging History

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

  • [2023-12-10 00:53:56]
  • 评测
  • 测评结果:TL
  • 用时:3366ms
  • 内存:310708kb
  • [2023-12-10 00:53:56]
  • 提交

answer

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

#define rep(i,a,b) for (int i = a; i < b; i++)
#define trav(a,b) for (auto a : b)
#define lld long long
using i64 = long long;
#define all(x) begin(x),end(x)
#define sz(a) (int)a.size()
const lld MOD=998244353;
const long double PI = acos(-1.0L);
void fft(vector<complex<double>> &a) {
	int n = sz(a), L = 31-__builtin_clz(n);
	static vector<complex<long double>> R(2, 1);
	static vector<complex<double>> rt(2, 1);
	for (static int k=2; k<n; k*=2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0L, PI/k);
		for (int i=k; i<2*k; i++) rt[i] = R[i] = i&1 ? R[i/2]*x : R[i/2];
	}
	vector<int> rev(n);
	for (int i=0; i<n; i++) rev[i] = (rev[i/2] | (i&1)<<L)/2;
	for (int i=0; i<n; i++) if (i<rev[i]) swap(a[i], a[rev[i]]);
	for (int k=1; k<n; k*=2) {
		for (int i=0; i<n; i+=2*k) {
			for (int j=0; j<k; j++) {
				auto x = (double*) &rt[j+k], y = (double*) &a[i+j+k];
				complex<double> z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);
				a[i+j+k] = a[i+j] - z;
				a[i+j] += z;
			}
		}
	}
}
vector<i64> convolution_mod(const vector<i64> &a, const vector<i64> &b, i64 mod) {
	if (a.empty() || b.empty()) return {};
	vector<i64> res(sz(a)+sz(b)-1);
	int B = 32-__builtin_clz(sz(res)), n = 1<<B;
	i64 cut = sqrt(mod);
	vector<complex<double>> L(n), R(n), outs(n), outl(n);
	for (int i=0; i<sz(a); i++) L[i] = complex<double>((i64)a[i]/cut, (i64)a[i]%cut);
	for (int i=0; i<sz(b); i++) R[i] = complex<double>((i64)b[i]/cut, (i64)b[i]%cut);
	fft(L), fft(R);
	for (int i=0; i<n; i++) {
		int j = -i&(n-1);
		outl[j] = (L[i] + conj(L[j])) * R[i] / (2.0*n);
		outs[j] = (L[i] - conj(L[j])) * R[i] / (2.0*n) / 1i;
	}
	fft(outl), fft(outs);
	for (int i=0; i<sz(res); i++) {
		i64 av = i64(real(outl[i])+0.5), cv = i64(imag(outs[i])+0.5);
		i64 bv = i64(imag(outl[i])+0.5) + i64(real(outs[i])+0.5);
		res[i] = ((av % mod * cut + bv) % mod * cut + cv) % mod;
		if(res[i]>0)res[i]=1;
		else res[i]=0;
	}
	return res;
}
vector<lld> pot1[11];
vector<lld> pot2[11];
void solve() {
	int n;
	cin>>n;
	int l,r;
	cin>>l>>r;
	vector<int> arr(n);
	rep(i,0,n)cin>>arr[i];
	int mx=arr[n-1];
	pot1[0].resize(mx+1,0);
	pot2[0].resize(mx+1,0);
	rep(i,0,n)pot1[0][arr[i]]=1,pot2[0][arr[i]]=1;
	pot2[0][0]=1;
	rep(i,1,11){
		pot1[i]=convolution_mod(pot1[i-1],pot1[i-1],MOD);
		pot2[i]=convolution_mod(pot2[i-1],pot2[i-1],MOD);
	}
	vector<lld> ans;
	ans.push_back(1);
	int diff=r-l;
	for(int pt=0;pt<11;pt++){
		if(((1<<pt)&l)>0){
			ans=convolution_mod(ans,pot1[pt],MOD);
		}
	}
	for(int pt=0;pt<11;pt++){
		if(((1<<pt)&diff)>0){
			ans=convolution_mod(ans,pot2[pt],MOD);
		}
	}
	int sum=0;
	trav(a,ans)sum+=a;
	//~ trav(a,ans)cout<<a;
	//~ cout<<endl;
	cout<<sum<<"\n";
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	//~ cin >> tt;
	while (tt--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3884kb

input:

2 1 2
1 2

output:

4

result:

ok answer is '4'

Test #2:

score: 0
Accepted
time: 6ms
memory: 5544kb

input:

3 1 3
1 3 10

output:

18

result:

ok answer is '18'

Test #3:

score: 0
Accepted
time: 3ms
memory: 4472kb

input:

6 3 5
1 2 3 4 5 6

output:

28

result:

ok answer is '28'

Test #4:

score: 0
Accepted
time: 3ms
memory: 4308kb

input:

3 1 3
1 3 4

output:

12

result:

ok answer is '12'

Test #5:

score: 0
Accepted
time: 1607ms
memory: 310708kb

input:

500 1 2000
6 8 9 10 11 14 16 19 23 24 25 30 31 33 34 38 44 46 48 49 52 53 55 56 58 60 64 65 68 69 70 71 72 74 75 77 79 81 83 84 88 89 93 95 98 103 105 108 109 110 111 118 119 120 121 123 125 129 130 132 134 136 137 138 140 141 144 149 154 155 159 160 161 163 165 166 169 170 172 173 174 175 176 177 1...

output:

1999990

result:

ok answer is '1999990'

Test #6:

score: 0
Accepted
time: 925ms
memory: 154368kb

input:

500 249 290
1 3 8 9 10 12 13 16 19 20 23 25 27 28 29 30 34 35 37 39 40 42 44 46 48 53 54 55 57 59 62 64 65 67 70 73 81 82 83 85 86 87 88 89 90 93 94 95 97 99 100 101 102 105 110 111 112 113 118 120 121 123 126 127 131 134 137 138 139 140 143 146 147 151 153 156 160 164 165 166 168 170 171 172 174 17...

output:

289457

result:

ok answer is '289457'

Test #7:

score: 0
Accepted
time: 1049ms
memory: 163848kb

input:

1000 154 700
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

699847

result:

ok answer is '699847'

Test #8:

score: 0
Accepted
time: 2119ms
memory: 172100kb

input:

1000 874 935
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

934127

result:

ok answer is '934127'

Test #9:

score: 0
Accepted
time: 1085ms
memory: 167992kb

input:

1000 2 981
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

980999

result:

ok answer is '980999'

Test #10:

score: 0
Accepted
time: 1386ms
memory: 165004kb

input:

1000 426 739
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

738575

result:

ok answer is '738575'

Test #11:

score: 0
Accepted
time: 1618ms
memory: 164140kb

input:

1000 554 687
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

686447

result:

ok answer is '686447'

Test #12:

score: 0
Accepted
time: 3366ms
memory: 306620kb

input:

1000 798 1797
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

1796203

result:

ok answer is '1796203'

Test #13:

score: -100
Time Limit Exceeded

input:

1000 1381 1880
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:


result: