Submission #485789

# Submission time Handle Problem Language Result Execution time Memory
485789 2021-11-09T11:45:09 Z LptN21 Spiderman (COCI20_spiderman) C++14
70 / 70
125 ms 18044 KB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define PI acos(-1.0)
#define FF first
#define SS second
#define eps 1e-3
// vector
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define lb lower_bound
#define ub upper_bound
// bit
#define CNTBIT(x) __builtin_popcount(x)
#define ODDBIT(x) __builtin_parity(x)
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//typedef __int128 i128;
typedef pair<int, int> ii;
typedef pair<int, ii> i3;
/* CODE BELOW */
const int N=3e5+7, M=1e6+7;
const int MOD=1e9+7;
const int oo=1e9+7;

int n, m, k, t;

int a[N], p[M], sub[M];
int cnt[M], sum[M];

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d%d", &n, &m);

    memset(cnt, 0, sizeof cnt);
    memset(sub, 0, sizeof sub);
    memset(p, 0, sizeof p);
    for(int i=1;i<=n;i++) {
        scanf("%d", &a[i]);
        cnt[a[i]]++, p[a[i]]++;
    }

    const int SUB1=2000;
    if(n<=SUB1) {
        for(int i=1;i<=n;i++) {
            int ans=0;
            for(int j=1;j<=n;j++) {
                if(a[i]!=a[j]) {
                    ans+=(a[i]%a[j]==m);
                }
            }
            printf("%d ", ans);
        }
        return 0;
    }

    for(int i=M-1;i>0;i--) {
        p[i]+=p[i+1];
        for(int j=2*i;j<M;j+=i) {
            cnt[j]+=cnt[i];
            if(i<=m) sum[j]+=cnt[i];
        }
        if(i<=m) sum[i]+=cnt[i];
    }

    for(int i=1;i<=n;i++) {
        if(a[i]<m) printf("0");
        else if(a[i]==m) printf("%d", p[m+1]);
        else {
            if(!m) printf("%d", cnt[a[i]]-1);
            else printf("%d", cnt[a[i]-m]-sum[a[i]-m]);
        }
        printf(" ");
    }

    return 0;
}
/* stuff you should look for
    - int overflow, array bounds
    - special/edge cases (n=1?)
    - do smth instead of nothing and stay organized
    - WRITE STUFF DOWN
    - DONT JUST STICK ON ONE APPROACH
*/

Compilation message

spiderman.cpp: In function 'int main()':
spiderman.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
spiderman.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 12052 KB Output is correct
2 Correct 25 ms 11980 KB Output is correct
3 Correct 44 ms 16636 KB Output is correct
4 Correct 87 ms 18044 KB Output is correct
5 Correct 54 ms 12636 KB Output is correct
6 Correct 107 ms 14068 KB Output is correct
7 Correct 68 ms 16528 KB Output is correct
8 Correct 57 ms 16452 KB Output is correct
9 Correct 110 ms 17820 KB Output is correct
10 Correct 125 ms 17772 KB Output is correct