結果

問題 No.206 数の積集合を求めるクエリ
ユーザー momoyuumomoyuu
提出日時 2022-10-12 13:30:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 7,000 ms
コード長 2,250 bytes
コンパイル時間 3,486 ms
コンパイル使用メモリ 251,100 KB
実行使用メモリ 22,072 KB
最終ジャッジ日時 2023-09-08 14:46:04
合計ジャッジ時間 9,810 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 9 ms
4,396 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
4,392 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 332 ms
22,072 KB
testcase_18 AC 307 ms
21,584 KB
testcase_19 AC 327 ms
21,808 KB
testcase_20 AC 309 ms
21,448 KB
testcase_21 AC 312 ms
21,620 KB
testcase_22 AC 312 ms
21,692 KB
testcase_23 AC 330 ms
21,776 KB
testcase_24 AC 340 ms
21,944 KB
testcase_25 AC 333 ms
21,736 KB
testcase_26 AC 314 ms
21,744 KB
testcase_27 AC 306 ms
21,388 KB
testcase_28 AC 318 ms
21,684 KB
testcase_29 AC 331 ms
21,788 KB
testcase_30 AC 312 ms
21,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vc<int>;
using vvi = vvc<int>;
using vl = vc<ll>;
using vvl = vvc<ll>;

#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++)
#define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--)
#define all(a) a.begin(),a.end()
#define print(n) cout << n << '\n'
#define pritn(n) print(n)
#define printv(n,a) {copy(all(n),ostream_iterator<a>(cout," ")); cout<<"\n";}
#define printvv(n,a) {for(auto itr:n) printv(itr,a);}
#define rup(a,b) (a+b-1)/b
#define input(A,N) rep(i,0,N) cin>>A[i]
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

void FFT(vector<complex<double>> &a,int ni){
    int n = a.size();
    if(n==1) return;
    vector<complex<double>> a1(n/2,0),a2(n/2,0);
    for(int i = 0;i<n/2;i++){
        a1[i] = a[i*2];
        a2[i] = a[i*2+1];
    }
    FFT(a1,ni);FFT(a2,ni);
    for(int i = 0;i<n/2;i++){
        a2[i] *= polar(1.0,ni*2.0*acos(-1)*i/n);
        a[i] = a1[i] + a2[i];
        a[n/2+i] = a1[i] - a2[i];
    }
}

template< typename T >
vector<T> conv(vector<T> a,vector<T> b){
    int m = a.size() + b.size() - 1;
    int n = 1;
    while(n<m) n<<=1;
    vector<complex<double>> na(n,0);
    vector<complex<double>> nb(n,0);
    for(int i = 0;i<(int)a.size();i++) na[i] = a[i];
    for(int i = 0;i<(int)b.size();i++) nb[i] = b[i];
    FFT(na,1);FFT(nb,1);
    rep(i,0,n) na[i] *= nb[i];
    FFT(na,-1);
    rep(i,0,n) na[i] /= n;
    vector<T> ans(n,0);
    for(int i = 0;i<n;i++) ans[i] = (T)(na[i].real()+0.5);
    return ans;
}

int main(){
    cout << fixed << setprecision(15);
    
    int l,m,n;
    cin>>l>>m>>n;
    vi a(n+1,0);
    vi b(n+1,0);
    rep(i,0,l){
        int x;
        cin>>x;
        a[x]++;
    }
    vi c(m);
    input(c,m);
    int q;
    cin>>q;
    rep(i,0,m){
        int x = c[i];
        b[x]++;
        // x += q;
        // if(x<=n) b[x]--;
    }
    reverse(all(b));
    vi ans = conv<int>(a,b);
    rep(i,n,n+q) print(ans[i]);
    
    //printv(ans,int);
    
    
    //system("pause");
    return 0;
}
0