Submission #1124489

#TimeUsernameProblemLanguageResultExecution timeMemory
1124489ljtunasSpiderman (COCI20_spiderman)C++20
70 / 70
218 ms27156 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fi first
#define se second
#define Rep(i, n)  for(int i = 1; i <= n; ++i)
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define Forv(v, h) for(auto &v : h)
#define Bit(x, i) ((x) >> (i) & 1ll)
#define onbit(x, i) ((x) | (1ll << i))
#define offbit(x, i) ((x) &~ (1ll << i))
#define cnt_bit(x) __builtin_popcountll(x)
#define Log2(x) (63 - __builtin_clzll(x))
#define all(h) h.begin(), h.end()
#define reset(h, v) (memset(h, v, sizeof(h)))
#define memoryof(v) (sizeof(v) / 1024 / 1024)

using ii  = pair<int, int>;
using ull = unsigned long long;
using db  = long double;
using vi  = vector<int>;
using vvi  = vector<vi>;
using vii  = vector<ii>;

const int dx[] = {0, 0, +1, -1};
const int dy[] = {-1, +1, 0, 0};
const int MAXN = 1e6  + 100;
const int  MOD = 1e9  + 7;
const int   oo = 1e18 + 1;
const int base = 311;

template <class X, class Y> bool maximize(X &a, const Y &b) {
    if(a < b) return a = b, true;
    return false;
}

template <class X, class Y> bool minimize(X &a, const Y &b) {
    if(a > b) return a = b, true;
    return false;
}

// (x, y) -> (u, v) = Ckn(u - x, x + y - u - v);
// Ckn(k, a) * Ckn(k, b) = C(a, a + b);  (k : 1 -> min(a, b))

void fixmod(int &val) {
    if (val < 0) val += MOD*MOD;
    val %= MOD;
}
int n, k, a[MAXN], cnt[MAXN], dp[MAXN];

int bit[MAXN];

void upd(int u) 
{
	for (;u; u -= (u &- u)) bit[u]++;
}

int get(int u)
{
	int res = 0;
	for (;u <= 1e6; u += (u &- u)) res += bit[u];
	return res;
}

void Progess() {
	cin >> n >> k;
	For (i, 1, n) cin >> a[i], upd(a[i]), ++cnt[a[i]];

	// cout << '\n';
	// For (i, 1, n) {
	// 	int cur = 0; For (j, 1 ,n) cur += (a[i] % a[j] == k);
	// 	cout << cur << ' ';
	// }

	For (i, 1, 1e6) {
		for (int j = i; j + k <= 1e6; j += i) {
			if ((j + k) % i == k)
				dp[j + k] += cnt[i];
		}
	}
	For (i, 1, n) cout << (a[i] == k) * get(a[i] + 1) + dp[a[i]] - (a[i] % a[i] == k) << ' ';
}

signed main(void) {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    cout.tie(nullptr);

    #define task "a"
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }//_______________________________
    Progess();
    cerr << "\nTime elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s.\n";
    return (0 ^ 0);
}

Compilation message (stderr)

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