답안 #231821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231821 2020-05-15T00:49:28 Z eggag32 Spiderman (COCI20_spiderman) C++17
56 / 70
1562 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];
				if(j != (num / j) && h[i] % (num / j) == k) ans += m[num / j];
			}
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4608 KB Output is correct
2 Correct 14 ms 4480 KB Output is correct
3 Correct 363 ms 5496 KB Output is correct
4 Correct 1037 ms 7160 KB Output is correct
5 Incorrect 485 ms 11456 KB Output isn't correct
6 Incorrect 1359 ms 12652 KB Output isn't correct
7 Correct 572 ms 17084 KB Output is correct
8 Correct 577 ms 17044 KB Output is correct
9 Correct 1559 ms 18108 KB Output is correct
10 Correct 1562 ms 18108 KB Output is correct