Submission #231822

# Submission time Handle Problem Language Result Execution time Memory
231822 2020-05-15T00:56:05 Z eggag32 Spiderman (COCI20_spiderman) C++17
70 / 70
1568 ms 18108 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MAXN = 1e6 + 5;
 
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
 
template<class T> struct BIT{
	vector<T> bit;
	BIT(){
		bit.assign(MAXN, 0);
	}
	void update(int ind, T delta){
		for(; ind < MAXN; ind = ind | (ind + 1)){
			bit[ind] += delta;
		}
	}
	T query(int ind){
		T sum = 0;
		for(; ind >= 0; ind = (ind & (ind + 1)) - 1){
			sum += bit[ind];
		}
		return sum;
	}
};
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vi h(n);
	unordered_map<int, int> m;
	BIT<int> bit;
	rep(i, n) cin >> h[i], m[h[i]]++, bit.update(h[i], 1);
	rep(i, n){
		int num = h[i] - k;
		int ans = 0;
		if(!num) ans += n - bit.query(h[i]);
		for(int j = 1; (j * j) <= num; j++){
			if(num % j == 0){
				if(h[i] % j == k) ans += m[j] - (h[i] == j);
				if(j != (num / j) && h[i] % (num / j) == k) ans += m[num / j] - (h[i] == (num / j));
			}
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4608 KB Output is correct
2 Correct 15 ms 4480 KB Output is correct
3 Correct 362 ms 5752 KB Output is correct
4 Correct 1044 ms 7048 KB Output is correct
5 Correct 488 ms 11452 KB Output is correct
6 Correct 1347 ms 12732 KB Output is correct
7 Correct 575 ms 16964 KB Output is correct
8 Correct 574 ms 16828 KB Output is correct
9 Correct 1552 ms 18108 KB Output is correct
10 Correct 1568 ms 18108 KB Output is correct