QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#865086 | #9738. Make It Divisible | lw22019 | WA | 2ms | 5968kb | C++14 | 2.1kb | 2025-01-21 14:41:35 | 2025-01-21 14:41:42 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define ls(k) p[k].ls
#define rs(k) p[k].rs
using namespace std;
const int N=50010,lgN=20;
struct node{
int ls,rs;
}p[N];
int Q,n,m,h,cnt,ans,a[N],lg[N],st[N][lgN];
vector<int> Vec;
int qmin(int i,int j){
if(a[i]<a[j]) return i;
else return j;
}
int query(int l,int r){
int Log=lg[r-l+1];
return qmin(st[l][Log],st[r-(1<<Log)+1][Log]);
}
void get(int x){
// printf("***%d\n",x);
Vec.clear();
for(int i=1;i*i<=x;i++){
if(x%i==0){
Vec.push_back(i);
if(i!=x/i) Vec.push_back(x/i);
}
}
}
int build(int l,int r){
if(r<l) return 0;
if(l==r) return l;
int k=query(l,r);
// printf("::%d\n",k);
ls(k)=build(l,k-1);
if(ls(k)&&a[ls(k)]!=a[k]&&Vec[0]==-1) /*printf("%d %d:\n",a[k],a[ls(k)]),*/get(a[ls(k)]-a[k]);
rs(k)=build(k+1,r);
if(rs(k)&&a[rs(k)]!=a[k]&&Vec[0]==-1) /*printf("%d %d:\n",a[k],a[rs(k)]),*/get(a[rs(k)]-a[k]);
return k;
}
bool chk(int k,int x){
// printf("%lld&%lld\n",k,x);
if(ls(k)){
if((a[ls(k)]+x)%(a[k]+x)!=0) return false;
if(!chk(ls(k),x)) return false;
}
if(rs(k)){
if((a[rs(k)]+x)%(a[k]+x)!=0) return false;
if(!chk(rs(k),x)) return false;
}
return true;
}
void solve(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
st[i][0]=i;
ls(i)=rs(i)=0;
}
lg[1]=0;
for(int i=2;i<=n;i++) lg[i]=lg[i/2]+1;
for(int j=1;j<lgN;j++){
for(int i=1;i+(1<<j)-1<=n;i++){
st[i][j]=qmin(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
Vec.clear();
Vec.push_back(-1);
h=build(1,n);
if(Vec[0]==-1||n==1){
printf("%lld %lld\n",m,(m+1)*m/2);
return ;
}
cnt=0,ans=0;
for(auto i:Vec){
if(i+1<=m&&chk(h,i+1)) cnt++,ans+=i+1;
}
if(chk(h,1)) cnt++,ans++;
chk(h,3);
printf("%lld %lld\n",cnt,ans);
}
signed main(){
scanf("%lld",&Q);
while(Q--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5968kb
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: 1ms
memory: 3840kb
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: -100
Wrong Answer
time: 2ms
memory: 5804kb
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:
wrong answer 467th lines differ - expected: '1 8', found: '0 0'