QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863597#9738. Make It Divisible22016020736TL 891ms21008kbC++143.6kb2025-01-19 19:49:282025-01-19 19:49:29

Judging History

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

  • [2025-01-19 19:49:29]
  • 评测
  • 测评结果:TL
  • 用时:891ms
  • 内存:21008kb
  • [2025-01-19 19:49:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

int arr[20000009];
int brr[20000009];
map<int,vector<int>>pos;
int st[2000009][30];
bool f;
void init(int n)
{
   for(int i=1;i<30;i++)
   {
      for(int j=1;j+(1<<i)-1<=n;j++)
      {
         st[j][i]=min(st[j][i-1],st[j+(1ll<<(i-1))][i-1]);
      }
   }
}

int get(int l,int r)
{
   int k=__lg(r-l+1);
   return min(st[l][k],st[r-(1ll<<k)+1][k]);
}

void check(int l,int r,int val,int n)
{
    //printf("l,r:%lld %lld %lld\n",l,r,val);
    if(!f) return ;
    if(l>=r)
    {

       return ;
    }
    int mn=get(l,r);///1 4 3 4
    //printf("mn:%lld %lld %lld %lld\n",l,r,mn,val);
    //printf("l,r:%lld %lld %lld %lld\n",l,r,val,pos[mn].front());
    //_sleep(1000);
   // for(int i=l;i<=r;i++)
    //{
     //   if( (brr[i]+val)%(mn+val)!=0) f=false;
    //}
    int pre=l-1;
    int idx=lower_bound(pos[mn].begin(),pos[mn].end(),l)-pos[mn].begin();


   // while(!pos[mn].empty()&&pos[mn].front()<l) pos[mn].pop_front();
    for(int i=idx;i<pos[mn].size();i++)
    {
        int x=pos[mn][idx];
        //if(l==3&&r==4) printf("x:%lld %lld\n",x,val);
        if(x-1>r) break;
     //   printf("11111\n");
       if(pre+1<=x-1)
       {
           int mx=get(pre+1,x-1);
           if((mx+val)%(mn+val)!=0) f=false;
          check(pre+1,x-1,val,n);
       }
        pre=x;
    }
  //  while(!pos[mn].empty()&&pos[mn].front()<=r) pos[mn].pop_front();
    if(pre!=r)
    {
        int mx=get(pre+1,r);
       if((mx+val)%(mn+val)!=0) f=false;
       check(pre+1,r,val,n);

    }
}

signed main() {
   int tt=0;
   //if(3%(1==0) ) printf("aaaaa\n");
   scanf("%lld",&tt);
   int tmpt=tt;
   int t=0;
   while(tt--)
   {
       t++;
       int top=0;
       set<int>stt;
      int n,k;
      scanf("%lld%lld",&n,&k);
      pos.clear();
      int mx=0;
      for(int i=1;i<=n;i++)
      {
         int x;
         scanf("%lld",&x);
         brr[i]=x;
         //mx=max(mx,x);
         stt.insert(x);
         pos[x].push_back(i);
         st[i][0]=x;
      }
      init(n);
      for(int i=1;i<=n;i++)
      {
        // for(int j=i;j<=n;j++) printf("l,r:%d %d %d\n",i,j,get(i,j));

      }
     if(tmpt==500&&t==474)
     {
       // for(int i=1;i<=n;i++) printf("%lld ",brr[i]);
       // printf("\n");
     }
      //return 0;
      if(stt.size()==1)
      {
          int ans=k,sum=k*(k+1)/2;
          printf("%lld %lld\n",ans,sum);
          continue;
      }
      for(auto x:stt)
      {
         arr[++top]=x;
      }
       int nx=arr[1];;
       mx=arr[2];
       if(nx>=mx)
       {
            printf("0 0\n");
           continue;
       }
       else
       {
          int shu=mx-nx;
          set<int>xulie;
          for(int i=1;i*i<=shu;i++)
          {
              if(shu%i==0)
              {
                  if(i-nx>=1&&i-nx<=k)
                 xulie.insert(i-nx);
                 if(shu/i-nx>=1&&shu/i-nx<=k)
                 xulie.insert(shu/i-nx);
              }
          }
          int ans=0,sum=0;
             for(auto x:xulie)
             {
                f=true;
                check(1,n,x,n);
                //pos.clear();
                //for(int i=1;i<=n;i++) pos[brr[i]].push_back(i);
                //printf("777:%lld\n",pos[7].front());
               // if(f) printf("x:%lld\n",x);
                if(f) ans++,sum+=x;
             }
             printf("%lld %lld\n",ans,sum);
          }
       }
   return 0;
}
/*
1000
4 1000000000
11 1 22 11


10000
6 1000
8 2 4 3 1 9
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8012kb

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: 0ms
memory: 8060kb

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: 0
Accepted
time: 0ms
memory: 8016kb

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:

ok 500 lines

Test #4:

score: 0
Accepted
time: 7ms
memory: 21008kb

input:

1
50000 1000000000
230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 7ms
memory: 20716kb

input:

1
50000 1000000000
12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...

output:

0 0

result:

ok single line: '0 0'

Test #6:

score: 0
Accepted
time: 9ms
memory: 20724kb

input:

1
50000 1000000000
2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: 0
Accepted
time: 17ms
memory: 8016kb

input:

500
39 1000000000
75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7
61 1000000000
327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...

output:

0 0
25 631568356
13 18925862
1 1
2 6878
1 2
1 1
2 10
1 1
1 110
0 0
1 36
11 4796
1 29
1 4
6 2209209
0 0
3 8
1 2
9 30770061
1000000000 500000000500000000
1 3
1000000000 500000000500000000
0 0
1 5
1 1
6 6615501
3 8233825
2 1035
2 4
7 1288
0 0
1 3
16 1617883221
2 10
0 0
1 5739
15 102584
3 1100
100000000...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 136ms
memory: 8340kb

input:

50
794 1000000000
32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 ...

output:

4 13399
1 488
0 0
1 1
2 764
1 3762
2 3
1 4
3 704189325
1 1
7 226705168
7 2992
1 10
2 14
0 0
2 4136
1 1
5 1503264540
1 6
1 9
2 178
12 1965492
3 8622003
1 1
1 10
0 0
0 0
1 316605749
1 4
2 8
1 22
2 1452
0 0
1 47
1 1
3 11
7 709953544
20 10709552
3 8
1 3
19 84763135
2 1256
3 1268
29 1652299260
1 1
3 1124...

result:

ok 50 lines

Test #9:

score: 0
Accepted
time: 891ms
memory: 11196kb

input:

5
8181 1000000000
846711550 846711550 846711550 846711550 31870 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 31870 338703742 338703742 190 14224510 14224510 6526 6526 190 190 190 10 190 10 21214 21214 154 154 8578 10 190 10 10 82 3862 ...

output:

2 10
1 8
26 3610753
1 3
2 4

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 628ms
memory: 20956kb

input:

1
50000 1000000000
8376 1656 5016 20136 5016 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 16776 8376 50376 251976 1656 1656 10056 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 5016 1656 3336 3336 3336 3336 3336 83976 16776 16776 16776 1656 536 1096 2216 1096 1096 67176 33576 5576 1096 ...

output:

1 24

result:

ok single line: '1 24'

Test #11:

score: -100
Time Limit Exceeded

input:

1
50000 1000000000
91892194 394 137838094 394 137838094 137838094 394 183783994 394 183783994 183783994 183783994 183783994 394 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 394 137838094 137838094 137838094 394 91892194...

output:


result: