Submission #231822

#TimeUsernameProblemLanguageResultExecution timeMemory
231822eggag32Spiderman (COCI20_spiderman)C++17
70 / 70
1568 ms18108 KiB
#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 timeMemoryGrader output
Fetching results...