不知道为什么wa3,明明韦达定理的求根公式没问题
查看原帖
不知道为什么wa3,明明韦达定理的求根公式没问题
1122530
elpsconr楼主2024/10/21 21:33

我甚至扩大范围去搜都搜不全,差这么多吗?

/*
   卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul tuple<int,int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=2e5+5,yyx=998244353;
vector<int> to[N],t;
int n,q,a[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
int f(int b,int c,int x){
    return x*x-b*x+c;
}
inline void solve(){
  cin>>n;
  map<int,int> mp;
  rep(i,1,n) cin>>a[i],mp[a[i]]++;
  cin>>q;
  rep(i,1,q){
    int x,y;cin>>x>>y;
    if(x*x-4*y<0){
        cout<<0<<" ";continue;
    }
    if(x*x-4*y==0){
        double d=sqrt(x*x-4*y);
        double x0=(-x+d)*1.0/2;
        int p=x0;
        rep(i,x0-1000,x0+1000){
            if(f(x,y,i)==0){
                p=i;break;
            }
        }
        cout<<mp[p]*(mp[p]-1)/2<<" ";continue;
    }
    double d=sqrt(x*x-4*y);
    double x0=(-x+d)*1.0/2,x1=(-x-d)*1.0/2;
    int p=x0,ok=0;
    rep(i,x0-1000,x0+1000){
        if(f(x,y,i)==0){
            ok=1;
            p=i;break;
        }
    }
    if(ok){
        int g=x-p;
        cout<<mp[g]*mp[p]<<" ";
    }
    else{
        rep(i,x1-1000,x1+1000){
            if(f(x,y,i)==0){
                ok=1;
                p=i;break;
            }
        }
        int g=x-p;
        cout<<mp[g]*mp[p]<<" ";
    }
  }
  cout<<endl;
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  cin>>_;
  while(_--)
  solve();
  return 0;
}
2024/10/21 21:33
加载中...