답안 #485801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485801 2021-11-09T11:55:44 Z dz001 Spiderman (COCI20_spiderman) C++11
70 / 70
1133 ms 11604 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MX=1e6+10;
const int N=3e5+10;
int a[N],cnt[MX],ans[N],bit[MX];
int n,k;
 
vector<int> getDiv(int x){
    vector<int> kq;
    if((x==1&&k!=0)||x!=1)kq.push_back(x);
    for(int i=2;i*i<=x;++i){
        if(x%i==0){
            kq.push_back(i);
            if(x/i!=i)kq.push_back(x/i);
        }
    }
 
    return kq;
}
 
void upd(int i,int val){
    for(;i<MX;i+=i&(-i))bit[i]+=val;
}
 
int get(int i){
    int kq=0;
    for(;i>0;i-=i&(-i))kq+=bit[i];
 
    return kq;
}
 
signed main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(nullptr);
 
    cin>>n>>k;
    for(int i=0;i<n;++i)cin>>a[i],cnt[a[i]]++;
    for(int i=1;i<MX;++i)if(cnt[i])upd(i,cnt[i]);
 
    for(int i=0;i<n;++i){
        if(a[i]<k){ans[i]=0;continue;}
        if(k==0&&a[i]==0){ans[i]=n;continue;}
        if(a[i]==k){
            ans[i]=(n-get(a[i])-cnt[0]);
        }else{
            auto tmp=getDiv(a[i]-k);
            for(int j:tmp){
                if(a[i]%j==k)ans[i]+=cnt[j];
            }
        }
    }
    for(int i=0;i<n;++i)cout<<ans[i]<<' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5836 KB Output is correct
2 Correct 9 ms 4316 KB Output is correct
3 Correct 302 ms 7164 KB Output is correct
4 Correct 879 ms 9368 KB Output is correct
5 Correct 344 ms 9064 KB Output is correct
6 Correct 1002 ms 11604 KB Output is correct
7 Correct 388 ms 9056 KB Output is correct
8 Correct 389 ms 9184 KB Output is correct
9 Correct 1127 ms 11320 KB Output is correct
10 Correct 1133 ms 11168 KB Output is correct