QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864849#9738. Make It DivisiblelinxuanruiCompile Error//C++141.8kb2025-01-21 09:53:282025-01-21 09:53:28

Judging History

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

  • [2025-01-21 09:53:28]
  • 评测
  • [2025-01-21 09:53:28]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 5e4 + 5;
int qwq,n,k,a[N],st[N][20],lg[N],x,y;
ll cnt,ans;
int get(int x,int y){return (a[x] < a[y] ? x : y);}
int query(int l,int r){
	int k = lg[r - l + 1];
	return get(st[l][k],st[r - (1 << k) + 1][k]);
}
void dfs(int l,int r){
	if(x && y)return;
	int pos = query(l,r);
	if(pos != l){
		int lpos = query(l,pos - 1);
		if(a[pos] != a[lpos]){
			x = pos,y = lpos;
			return;
		}else dfs(l,pos - 1);
	}
	if(pos != r){
		int rpos = query(pos + 1,r);
		if(a[pos] != a[rpos]){
			x = pos,y = rpos;
			return;
		}else dfs(pos + 1,r);
	}
}
bool check(int x,int l,int r){
	int pos = query(l,r);
	bool flag = true;
	if(pos != l){
		int lpos = query(l,pos - 1);
		flag &= ((a[lpos] + x) % (a[pos] + x) == 0);
		flag &= check(x,l,pos - 1);
	}
	if(pos != r){
		int rpos = query(pos + 1,r);
		flag &= ((a[rpos] + x) % (a[pos] + x) == 0);
		flag &= check(x,pos + 1,r);
	}
	return flag;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> qwq;
	while(qwq--){
		cin >> n >> k;
		lg[0] = -1;
		for(int i = 1;i <= n;i++)cin >> a[i],lg[i] = lg[i >> 1] + 1,st[i][0] = i;
		if(*max_element(a + 1,a + n + 1) == *min_element(a + 1,a + n + 1)){
			cout << k << " " << 1ll * k * (k + 1) / 2 << endl;
			continue;
		}
		for(int j = 1;j <= lg[n];j++){
			for(int i = 1;i + (1 << j) - 1 <= n;i++)st[i][j] = get(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
		}
		x = y = 0;
		dfs(1,n);
		assert(x && y);
		x = a[x],y = a[y];
		cnt = ans = 0;
		for(int i = 1;i * i <= y - x;i++){
			if((y - x) % i == 0){
				int t = i - x;
				if(t <= k && t > 0 && check(t,1,n))ans += t,cnt++;
				t = (y - x) / i - x;
				if(i * i != y - x && t <= k && t > 0 && check(t,1,n))ans += t,cnt++;
			}
		}
		cout << cnt << " " << ans << endl;
	}
}

详细

answer.code:6:1: error: ‘ll’ does not name a type
    6 | ll cnt,ans;
      | ^~
answer.code: In function ‘int main()’:
answer.code:65:17: error: ‘cnt’ was not declared in this scope; did you mean ‘int’?
   65 |                 cnt = ans = 0;
      |                 ^~~
      |                 int
answer.code:65:23: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   65 |                 cnt = ans = 0;
      |                       ^~~
      |                       abs