QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748966#9738. Make It Divisiblekans2298WA 1ms3692kbC++173.1kb2024-11-14 22:10:532024-11-14 22:10:56

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 22:10:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3692kb
  • [2024-11-14 22:10:53]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<set>
#include<algorithm>
#include<random>
#include<numeric>
#include<cmath>
#define N 50000
#define LIM 40000
using namespace std;
int b[N+5];
struct node
{
     int pos,v;
};
node c[N+5];
int k;
void query_k(int a,int b,set<int> &f)
{
     if (a<b) swap(a,b);
     for (int x=1;x<=min(k,LIM);++x)
          if ((a+x)%(b+x)==0) f.insert(x);
     for (int y=2;y<=LIM;++y)
          {
          long long t=a-(long long)(y)*b,t2=t/(y-1);
          if (t%(y-1)==0 && t2>=1 && t2<=k) f.insert(t2);
          }
}
int st[N+5][17];
int query(int l,int r)
{
     int x=floor(log2(r-l+1));
     return gcd(st[l][x],st[r-(1<<x)+1][x]);
}
int main()
{
     int t,ti;
     // freopen("input.in","r",stdin);
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cin>>t;
     for (ti=1;ti<=t;++ti)
     {
     int n,i,j;
     cin>>n>>k;
     set<pair<int,int>> nn;
     for (i=1;i<=n;++i)
          {
          cin>>b[i];
          c[i]={i,b[i]};
          }
     for (i=1;i<n-1;++i)
          if (b[i]!=b[i+1]) nn.insert({b[i],b[i+1]});
     sort(c+1,c+n+1,[](const node &a,const node &b) -> bool {
          return a.v<b.v;
     });
     if (n==1 || nn.empty())
          {
          cout<<k<<" "<<((long long)(k+1))*(k)/2<<"\n";
          continue;
          }
     set<int> kk,k2,res;
     random_device rd;
     mt19937 gen(rd());
     vector<pair<int,int>> unx;
     for (auto elm:nn)
          unx.push_back(elm);
     uniform_int_distribution<> dist1(0,unx.size()-1);
     for (i=1;i<=3;++i)
          {
          int x=dist1(gen);
          kk.clear();
          query_k(unx[x].first,unx[x].second,kk);
          // cout<<b[x]<<" "<<b[x+1]<<"\n";
          if (i==1) res=kk;
               else
               {
               k2=res;
               res.clear();
               set_intersection(kk.begin(),kk.end(),k2.begin(),k2.end(),inserter(res,res.begin()));
               }
          }
     kk=res;
     // cout<<"k=";
     // for (auto x:kk)
     //      {
     //      cout<<x<<" ";
     //      }
     // cout<<"\n";
     vector<int> ans;
     for (auto x:kk)
          {
          bool okay=true;
          for (i=1;i<=n;++i)
               st[i][0]=b[i]+x;
          for (j=1;j<=16;++j)
               for (i=1;i<=n;++i)
                    st[i][j]=gcd(st[i][j-1],st[min(i+(1<<(j-1)),n)][j-1]);
          set<int> pp;
          pp.insert(0);
          pp.insert(n+1);
          for (i=1;i<=n;++i)
               {
               set<int>::iterator it=pp.upper_bound(c[i].pos);
               int l,r;
               r=*it;
               l=*prev(it);
               l=l+1,r=r-1;
               if (query(l,r)!=c[i].v+x)
                    {
                    okay=false;
                    break;
                    }
               pp.insert(c[i].pos);
               }
          if (okay) ans.push_back(x);
          }
     cout<<ans.size()<<" ";
     long long sum=0;
     for (auto elm:ans)
          sum+=elm;
     cout<<sum<<"\n";
     }
     return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3692kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
1000000000 500000000500000000
100 5050

result:

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