QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740107 | #9738. Make It Divisible | ir101 | RE | 5ms | 5912kb | C++20 | 4.0kb | 2024-11-13 01:18:06 | 2024-11-13 01:18:07 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 01:18:06]
- 提交
answer
#include <bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define PI4 pair<int,array<int,3>>
//#define endl '\n'
#define int long long
#define i64 long long
#define lc p<<1
#define rc p<<1|1
using namespace std;
const int N = 5e4 + 10;
int st[N][20],b[N];//区间长度最大不超过2^20
int Log[N];
int query(int l,int r)
{
if(l>r)return 0;
int k=Log[r-l+1];
return gcd(st[l][k],st[r-(1<<k)+1][k]);
}
bool isprime[N]; // isprime[i]表示i是不是素数
int prime[N]; // 现在已经筛出的素数列表
int cnt; // 已经筛出的素数个数
int a[N];
void euler(int n) {
memset(isprime, true, sizeof(isprime)); // 先全部标记为素数
isprime[1] = false; // 1不是素数
for (int i = 2; i <= n; ++i) { // i从2循环到n(外层循环)
if (isprime[i]) prime[++cnt] = i;
// 如果i没有被前面的数筛掉,则i是素数
for (int j = 1; j <= cnt && i * prime[j] <= n; ++j)
// 筛掉i的素数倍,即i的prime[j]倍
// j循环枚举现在已经筛出的素数(内层循环)
{
isprime[i * prime[j]] = false;
// 倍数标记为合数,也就是i用prime[j]把i * prime[j]筛掉了
if (i % prime[j] == 0) break;
// 最神奇的一句话,如果i整除prime[j],退出循环
// 这样可以保证线性的时间复杂度
}
}
}
vector<PII>qq;
vector<int>inv;
void dfs(int x, int s) {
if (x == qq.size()) {
inv.push_back(s);
return;
}
for (int i = 0; i <= qq[x].second; i++) {
dfs(x + 1, s);
s *= qq[x].first;
}
}
int L[N],R[N];
void solve() {
int n=5, k=10;
cin >> n >> k;
qq.clear();
inv.clear();
vector<int>qx;
int g = 0;
int mn = 1e9;
int f = 1;
int mi = 1;
for (int i = 1; i <= n; i++) {
L[i]=0;
R[i]=n+1;
cin >> a[i];
// if(i%2){
// a[i]=735134400+1;
// }else{
// a[i]=1;
// }
if (i > 1) {
if (a[i] == a[i - 1]) {
} else {
g = __gcd(abs(a[i] - a[i - 1]), g);
f = 0;
mi = i;
}
st[i-1][0]=a[i]-a[i-1];
}
mn = min(mn, a[i]);
}
vector<PII>q;
q.push_back({a[n],n});
for(int i=n-1;i>=1;i--){
while(q.size()&&a[i]<q.back().first){
L[q.back().second]=i;
q.pop_back();
}
q.push_back({a[i],i});
}
q.clear();
q.push_back({a[1],1});
for(int i=2;i<=n;i++){
while(q.size()&&a[i]<q.back().first){
R[q.back().second]=i;
q.pop_back();
}
q.push_back({a[i],i});
}
// for(int i=1;i<=n;i++){
// cout<<L[i]<<" \n"[i==n];
// }
// for(int i=1;i<=n;i++){
// cout<<R[i]<<" \n"[i==n];
// }
for(int j=1;j<=Log[n];j++)
{
for(int i=1;i<n;i++)
{
st[i][j]=gcd(st[i][j-1],st[i+(1<<j-1)][j-1]);
}
}
if (f) {
cout << k << ' ' << k*(k + 1) / 2 << endl;
return;
}
int t = abs(a[mi] - a[mi - 1]);
int pos = 1;
// cout<<t<<endl;
while (pos <= cnt && t > 1 && prime[pos]*prime[pos] <= t) {
int s = 0;
while (t % prime[pos] == 0) {
t /= prime[pos];
s++;
}
if (s) {
qq.push_back({prime[pos], s});
}
pos++;
}
if (t > 1) {
qq.push_back({t, 1});
}
dfs(0, 1);
int m = min(a[mi], a[mi - 1]);
for (int i = 0; i < inv.size(); i++) {
if (inv[i] > m && inv[i] - m <= k) {
qx.push_back(inv[i] - m);
}
}
// cout<<qx.size()<<endl;
// for (int i = 3; i <= n; i++) {
// int s = abs(a[i] - a[i - 1]);
// int mn = min(a[i], a[i - 1]);
// for (int j = 0; j < qx.size(); j++) {
// int x = qx[j];
// if (s % (x + mn) != 0) {
// swap(qx[j], qx.back());
// qx.pop_back();
// }
// }
// }
int cc = 0;
int sum = 0;
// cout<<g<<endl;
for (auto x : qx) {
// cout<<x<<":\n";
int f=1;
for(int i=1;i<=n;i++){
// cout<<query(L[i],R[i]-1)<<" \n";
if(query(L[i]+1,R[i]-2)%(a[i]+x)==0){
}else{
f=0;
break;
}
}
if(f){
cc++;
sum+=x;
}
}
cout << cc << ' ' << sum << endl;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
ll t = 1;
cin >> t;
euler(1e6);
Log[1]=0;
for(int i=2;i<N;i++)
Log[i]=Log[i/2]+1;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 5912kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 5636kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 0 0 0 0 0 0
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 5ms
memory: 5680kb
input:
500 4 1000000000 8 14 24 18 4 1000000000 17 10 18 14 4 1000000000 6 17 19 19 4 1000000000 15 14 15 25 4 1000000000 16 16 5 25 4 1000000000 4 30 20 5 4 1000000000 11 4 23 9 4 1000000000 14 25 13 2 4 1000000000 18 18 1 15 4 1000000000 22 22 22 28 4 1000000000 15 17 17 10 4 1000000000 22 14 13 25 4 100...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 500 lines
Test #4:
score: -100
Runtime Error
input:
1 50000 1000000000 230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...