QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430151#8000. 平方数WilliamxzhCompile Error//C++233.1kb2024-06-03 15:19:252024-06-03 15:19:25

Judging History

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

  • [2024-06-03 15:19:25]
  • 评测
  • [2024-06-03 15:19:25]
  • 提交

answer

#pragma GCC optimize("O2,O3,Ofast,inline,unroll-loops")
#pragma GCC target("avx2,sse4")
#include <bits/stdc++.h>
#define il inline
#define B __int128
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
il B read(){
    B x=0,c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-48,c=getchar();
    return x;
}
void write(B x){
    if(x<0){putchar('-'),write(-x);return ;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
il void print(B x,char c){write(x),putchar(c);}
const B P=468263885104630483818660242866188947;
typedef long long ll;
const int mod[101]={0,998244353,998244389,998244391,998244397,998244407,998244431,998244433,998244473,998244487,998244493,998244521,998244523,998244529,998244601,998244617,998244619,998244631,998244649,998244673,998244677,998244679,998244707,998244713,998244749,998244761,998244787,998244799,998244803,998244839,998244853,998244889,998244893,998244899,998244911,998244943,998244967,998244991,998245037,998245063,998245091,998245097,998245099,998245109,998245111,998245141,998245147,998245153,998245159,998245169,998245177,998245189,998245207,998245211,998245223,998245247,998245331,998245349,998245373,998245403,998245463,998245481,998245483,998245487,998245489,998245531,998245543,998245553,998245571,998245613,998245631,998245639,998245687,998245697,998245709,998245711,998245733,998245739,998245757,998245777,998245799,998245837,998245867,998245877,998245909,998245943,998245949,998245981,998246021,998246047,998246071,998246077,998246101,998246129,998246143,998246177,998246189,998246191,998246237,998246251,998246257};
il int qp(int a,int b,int mod){
    int ans=1;
    while(b){
        if(b&1) ans=(1ll*ans*a)%mod;
        a=(1ll*a*a)%mod,b>>=1;
    }return ans;
}
il int INV(int a,int p){return qp(a,p-2,p);}
const int N=3e5+5,K=1e5,inf=1e9;
int n,m,k,b[N],cnt,p[N];B a[N],c[N],d[N];pii ans[N];ll sum;
il int CHECK(int p,int v){return (!v) || qp(v,(b[p]-1)/2,b[p])==1;}
vector<int> f[N];
bitset<N> t[105];
B x,y,z;int u,v,w;
int main(){
    //freopen("ex_1.in","r",stdin);
    //freopen("ex_1.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;++i) a[i]=read();
    k=50;for(int i=1;i<=k;++i) b[i]=mod[i];
    for(int j=1;j<=k;++j){
        t[j][0]=0;
        for(int i=1;i<=n;++i){
            t[j][i]=1-CHECK(j,a[i]%b[j]);
            if(t[j][i]==t[j][i-1]) t[j][i]=0;
            else t[j][i]=1;
        }
    }
    for(int i=0;i<=n;++i){
        x=0;
        for(int j=1;j<=k;++j) x=(x*B(2)+t[j][i])%P;
        c[i]=d[i+1]=x;
    }
    sort(d+1,d+2+n);cnt=unique(d+1,d+2+n)-d-1;
    for(int i=0;i<=n;++i) c[i]=lower_bound(d+1,d+1+cnt,c[i])-d,f[c[i]].push_back(i),p[i]=f[c[i]].size()-1;
    for(int i=1;i<=cnt;++i){
        u=f[i].size();
        sum+=u*(u-1ll)/2ll;
    }
    printf("%lld\n",sum);
    for(int i=0;i<=n;++i){
        for(int j=p[i]+1;j<f[c[i]].size();++j){
            ans[++m]={i+1,f[c[i]][j]};
            if(m>=K) break;
        }
        if(m>=K) break;
    }
    for(int i=1;i<=min(m,K);++i) printf("%d %d\n",ans[i].fi,ans[i].se);
    return 0;
}

詳細信息

answer.code:22:11: warning: integer constant is too large for its type
   22 | const B P=468263885104630483818660242866188947;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~