QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#810149 | #6512. Completely Multiplicative Function | the_fool# | WA | 847ms | 168552kb | C++20 | 2.8kb | 2024-12-11 20:05:47 | 2024-12-11 20:05:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1E6 + 10;
vector<int> prim;
int vis[N],m,f[N],k;
vector<vector<int> > prims;
vector<vector<int> > count_1;
int count_prime[N];
vector<int> px[40];
void solve() {
int n,k;
cin>>n>>k;
if (1&(n^k)) {
cout<<-1<<endl;
return ;
}
int c_1 = n-(n+k)/2;
int cp = count_prime[n] - count_prime[(n+1)/2];
int id = -1;
for (int i=0;i<40;i++) {
if (count_1[i][n] + cp >= c_1 && count_1[i][n] <= c_1) {
id = i;
}
}
vector<int> res(n+1,1);
for (int i=1;i<=n;i++) {
if (count_1[id][i] - count_1[id][i-1])res[i] = -1;
}
int cntt = c_1 - count_1[id][n];
int p = upper_bound(prim.begin(),prim.end(),n)-prim.begin()-1;
while (prim[p]+prim[p]>n && cntt) {
res[prim[p]] = -1;
p--;
cntt--;
}
for (int i=1;i<=n;i++) {
cout<<res[i]<<' ';
}
cout<<endl;
// int s = 0;
// for (int i=1;i<=n;i++) {
// s += res[i];
// }
// assert(s == k);
// cout<<"OK"<<endl;
}
#define lb(x) ((x)&-(x))
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 2; i < N; i++) {
if (!vis[i]) {
prim.emplace_back(i);
for (int j = 2 * i; 1LL * j < N; j += i) {
vis[j] = 1;
}
}
}
int _[] = {2,3,5,7,11};
for (int i=0;i<32;i++) {
int ii = i;
prims.push_back({});
while (ii) {
prims.back().push_back(_[(int)log2(lb(ii))]);
ii -= lb(ii);
}
}
int __[] = {13,17,19,23,29,31,37,41};
for (auto x: __) {
prims.push_back({x});
}
count_1.resize(prims.size(),{0});
vector<int> ___ = {2,3,5,7,11,13,17,19,23,29,31,37,41};
for (int i=0;i<40;i++)px[i].push_back(0);
m=prim.size();
for (int i=1;i<=1e6;i++) {
count_prime[i] = count_prime[i-1]+(vis[i]^1);
vector<int> cnt;
int ii = i;
for (auto p : ___) {
cnt.push_back(0);
while (ii%p == 0) {
cnt.back()++;
ii/=p;
}
}
for (int j=0;j<40;j++) {
count_1[j].push_back(count_1[j].back());
int xx = 0;
if (j < 32) {
int iii = j;
while (iii) {
xx += cnt[(int)log2(lb(iii))];
iii-=lb(iii);
}
}
else {
xx = cnt[j-32+5];
}
count_1[j].back()+=xx&1;
}
}
// cout<<k<<endl;
int T;
cin>>T;
while (T--)solve();
}
/*
4
4 2
10 0
10 1
10 10
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 838ms
memory: 167880kb
input:
4 4 2 10 0 10 1 10 10
output:
1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 1 1 -1 1 1 1 1 1 1 1 1 1 1
result:
ok ok (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 847ms
memory: 168552kb
input:
11475 1 0 1 1 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11...
output:
-1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 1 1 1 -1 1 1 -1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 1 1 -1 -1 1 -1 1 -1 1 1 1 1 -1 1 -1 1 1 1 1 -1 1 -1 1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 -1 1 1 1 1 -1 1 -1 -1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 1 -1 1 -1 -1 -1 1 -1 1 1 1 1 -1 ...
result:
wrong answer sum of f is not k (test case 23)