QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752074 | #9738. Make It Divisible | sdnuwy# | WA | 1ms | 9936kb | C++20 | 4.9kb | 2024-11-15 21:54:03 | 2024-11-15 21:54:04 |
Judging History
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;
// #define DEBUG 1 // 调试开关
struct IO{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf){
}
~IO(){ fwrite(pbuf, 1, pp - pbuf, stdout); }
#endif
char gc(){
#if DEBUG // 调试,可显示字符
return getchar();
#endif
if(p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
return p1 == p2 ? ' ' : *p1++;
}
bool blank(char ch){
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template<class T>
void read(T &x){
double tmp = 1;
bool sign = false;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
void read(char *s){
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
}
void read(char &c){ for(c = gc(); blank(c); c = gc()); }
void push(const char &c){
#if DEBUG // 调试,可显示字符
putchar(c);
#else
if(pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template<class T>
void write(T x){
if(x < 0) x = -x, push('-'); // 负数输出
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while(x);
while(top) push(sta[--top] + '0');
}
template<class T>
void write(T x, char lastChar){
write(x), push(lastChar);
}
} io;
const int N=5e4+10;
int st[N][20];
int pos[N][20];
int a[N];
int lg2[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]);
}
}
}
inline int query_num(int l, int r,int x) {
if(l>r) return -x;
int s = lg2[r - l + 1];
return min(st[l][s], st[r - (1 << s) + 1][s]);
}
inline 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];
}
}
bool check(int l,int r,int x)
{
if(l==r||l>r) return true;
bool res=true;
int idx=query_pos(l,r);
int mn=query_num(l,r,x)+x;
if((query_num(l,idx-1,x)+x)%mn!=0||(query_num(idx+1,r,x)+x)%mn!=0) return false;
res&=check(l,idx-1,x);
if(!res) return false;
res&=check(idx+1,r,x);
return res;
}
void solve()
{
int n,k;
io.read(n);
io.read(k);
int num=0;
int mn=inf;
for(int i=1;i<=n;i++)
{
io.read(a[i]);
mn=min(mn,a[i]);
}
bool flag=1;
for(int i=2;i<=n;i++)
{
if(a[i]!=a[i-1]) flag=false;
}
if(flag)
{
cout << k << ' ' << k*(k+1)/2 << endl;
return;
}
int mn2=inf;
for(int i=1;i<=n;i++)
{
if(a[i]!=mn)
{
mn2=min(a[i],mn2);
}
}
build(n);
for(int i=2;i<=n;i++)
{
num=gcd(num,abs(a[i]-a[i-1]));
}
int ans1=0;
int ans2=0;
vector<int>c;
for(int i=1;i*i<=num;i++)
{
if(num%i==0)
{
c.push_back(i);
if(num/i!=i) c.push_back(num/i);
}
}
sort(c.begin(),c.end());
for(int y:c)
{
int x=y-mn;
if(x>=mn2) break;
if(x<=0||x>k) continue;
if(check(1,n,x))
{
ans1++;
ans2+=x;
}
}
// cout << ans1 << ' ' << ans2 << endl;
io.write(ans1,' ');
io.write(ans2,'\n');
}
int32_t main()
{
// std::ios_base::sync_with_stdio(false);
// std::cin.tie(nullptr);
// std::cout.tie(nullptr);
int t = 1;
io.read(t);
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9936kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
100 5050 3 8 0 0
result:
wrong answer 1st lines differ - expected: '3 8', found: '100 5050'