Submission #1273582

#TimeUsernameProblemLanguageResultExecution timeMemory
1273582SmuggingSpunSpiderman (COCI20_spiderman)C++20
56 / 70
706 ms120964 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
const int lim = 1e6 + 5;
int n, k, f[lim];
vector<int>d[lim];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> k;
	memset(f, 0, sizeof(f));
	for(int i = 1; i < lim; i++){
		for(int j = i; j < lim; j += i){
			d[j].emplace_back(i);
		}
	}
	vector<int>a(n);
	for(int& x : a){
		cin >> x;
		f[x]++;
	}
	for(int i = 1; i < lim; i++){
		f[i] += f[i - 1];
	}
	for(int& x : a){
		if(x <= k){
			cout << (x == k ? n - f[x] : 0) << " ";
			continue;
		}
		int ans = 0;
		for(int& y : d[x - k]){
			if(y > k){
				ans += f[y] - f[y - 1];
			}
		}
		cout << ans << " ";
	}
}

Compilation message (stderr)

spiderman.cpp: In function 'int main()':
spiderman.cpp:10:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...