結果

問題 No.206 数の積集合を求めるクエリ
ユーザー koprickykopricky
提出日時 2017-07-23 06:57:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,742 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 166,712 KB
実行使用メモリ 17,332 KB
最終ジャッジ日時 2024-04-17 16:30:35
合計ジャッジ時間 4,753 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 125 ms
17,332 KB
testcase_18 AC 119 ms
16,984 KB
testcase_19 AC 126 ms
17,184 KB
testcase_20 AC 60 ms
10,480 KB
testcase_21 AC 120 ms
17,012 KB
testcase_22 AC 119 ms
16,876 KB
testcase_23 AC 121 ms
17,152 KB
testcase_24 AC 134 ms
17,260 KB
testcase_25 AC 135 ms
17,180 KB
testcase_26 AC 119 ms
16,976 KB
testcase_27 AC 119 ms
16,900 KB
testcase_28 AC 125 ms
17,060 KB
testcase_29 AC 123 ms
16,904 KB
testcase_30 AC 121 ms
16,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:92:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |     scanf("%d%d%d",&l,&m,&n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:95:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:98:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |         scanf("%d",&b[i]);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:111:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  111 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;
typedef complex<double>C;

const int MAX_N = 100005;
const double PI = 4*atan(1.0);

//aにはAiおよびBi(係数)が入っている
vector<C> FFT(double theta, const vector<C>& a){
    int n = (int)a.size();
    vector<C> ret = a;
    for(int m=n; m>=2; m>>=1){
        int mh = m>>1;
        rep(i,mh){
            C w = exp(i*theta*C(0,1));
            for(int j=i; j<n; j+=m){
                int k = j+mh;
                C x = ret[j] - ret[k];
                ret[j] += ret[k];
                ret[k] = w*x;
            }
        }
        theta *= 2;
    }
    int i=0;
    for(int j=1; j<n-1; j++){
        for(int k=n>>1; k>(i^=k); k>>= 1){

        }
        if(j < i) swap(ret[i], ret[j]);
    }
    return ret;
}

//畳み込み
template<class T>
vector<T> Convolution(const vector<T> &lhs, const vector<T> &rhs){
    int n = 1;
    while(n <= (int)(lhs.size() + rhs.size())){
        n <<= 1;
    }
    vector<C> temp1(n);
    vector<C> temp2(n);
    for(int i=0; i<n; i++){
        if(i < (int)lhs.size()){
            temp1[i] = C(lhs[i], 0);
            if(i < (int)rhs.size()){
                temp2[i] = C(rhs[i], 0);
            }
        }else if(i < (int)rhs.size()){
            temp2[i] = C(rhs[i], 0);
        }else{
            break;
        }
    }
    //FFTにかけて周波数分解
    temp1 = FFT(2.0*PI/n, temp1);
    temp2 = FFT(2.0*PI/n, temp2);
    //周波数同士で掛け算
    rep(i,n){
        temp1[i] *= temp2[i];
    }
    //逆FFTをかけて元に戻す
    temp1 = FFT(-2.0*PI/n, temp1);
    vector<T> ret(n);
    rep(i,n){
        ret[i] = (T)(temp1[i].real()/n + 0.5); //T=intの時用
    }
    return ret;
}

int main()
{
    int l,m,n;
    scanf("%d%d%d",&l,&m,&n);
    vector<int> a(l),b(m);
    rep(i,l){
        scanf("%d",&a[i]);
    }
    rep(i,m){
        scanf("%d",&b[i]);
        b[i] = n-b[i];
    }
    vector<int> u(*max_element(all(a))+1,0);
    vector<int> v(*max_element(all(b))+1,0);
    rep(i,l){
        u[a[i]]++;
    }
    rep(i,m){
        v[b[i]]++;
    }
    vector<int> res = Convolution(u,v);
    int q;
    scanf("%d",&q);
    rep(i,q){
        printf("%d\n",res[n+i]);
    }
}
0