QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751634#9738. Make It Divisiblesdnuwy#WA 2ms9932kbC++203.1kb2024-11-15 19:56:182024-11-15 19:56:19

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-15 19:56:19]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9932kb
  • [2024-11-15 19:56:18]
  • 提交

answer

//Think twice,code once.
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define INF 0x3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ff first
#define ss second
#define pii pair<int,int>
#define mem(i,n) memset(i,n,sizeof i)
#define dg(a) std::cout << #a << " = " << a << endl
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int N=5e4+10;
int st[N][20];
int pos[N][20];
int stgcd[N][20];
int a[N];
int lg2[N];
int b[N];

void build(int n) {
    for (int i = 2; i <= n; i ++ ) lg2[i] = lg2[i >> 1] + 1;
	for (int i = 1; i <= n; i ++ ) 
    {
        st[i][0] = a[i];
        pos[i][0]=i;
    }
	for (int j = 1; (1 << j) <= n; j ++ ) {
		for (int i = 1; i + (1 << j - 1) <= n; i ++ ) {
            if(st[i][j-1]<st[i + (1 << j - 1)][j - 1])
            {
                pos[i][j]=pos[i][j-1];
            }
            else
            {
                pos[i][j]=pos[i + (1 << j - 1)][j - 1];
            }
			st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
            
		}
	}
}

void build_gcd(int n)
{
    for (int i = 1; i <= n; i ++ ) 
    {
        stgcd[i][0]=b[i];
    }
	for (int j = 1; (1 << j) <= n; j ++ ) {
		for (int i = 1; i + (1 << j - 1) <= n; i ++ ) {
			stgcd[i][j] = gcd(stgcd[i][j - 1], stgcd[i + (1 << j - 1)][j - 1]);
		}
	}
}

int query_num(int l, int r) {
	int s =  lg2[r - l + 1];
	return min(st[l][s], st[r - (1 << s) + 1][s]);
}

int query_pos(int l,int r)
{
    int s=lg2[r-l+1];
    if(st[l][s]<st[r - (1 << s) + 1][s])
    {
        return pos[l][s];
    }
    else
    {
        return pos[r - (1 << s) + 1][s];
    }
}

int query_gcd(int l,int r)
{
	int s =  lg2[r - l + 1];
	return gcd(stgcd[l][s], stgcd[r - (1 << s) + 1][s]);
}

bool check(int l,int r,int x)
{
    if(l==r||l<r) return true;
    bool res=true;
    if(query_num(l,r)+x>query_gcd(l,r)) return false;
    int idx=query_pos(l,r);
    res&=check(l,idx-1,x);
    res&=check(idx+1,r,x);
    return res;
}

void solve()
{
    int n,k;
    cin >> n >> k;
    int num=0;
    int mn=inf;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        mn=min(mn,a[i]);
    }
    if(n==1)
    {
        cout << k << ' ' << (k+1)*k/2 << endl;
        return;
    }
    build(n);
    for(int i=2;i<=n;i++)
    {
        num=gcd(num,a[i]-a[i-1]);
    }  
    int t=sqrt(num);
    int ans1=0;
    int ans2=0;
    vector<int>c;
    for(int i=1;i<=t;i++)
    {
        if(num%i==0)
        {
            c.push_back(i);
            if(num/i!=i) c.push_back(num/i);
        }
    }
    for(int y:c)
    {
        int x=y-mn;
        if(x<=0) continue;
        for(int i=1;i<=n;i++)
        {
            b[i]=a[i]+x;
        }
        build_gcd(n);
        if(check(1,n,x))
        {
            ans1++;
            ans2+=x;
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
}

int32_t main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 9924kb

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
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 1'