#include <bits/stdc++.h>
using namespace std;
// Typedef
typedef long double ld;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::vector<int> VI;
typedef std::vector<long long> VLL;
// Define For-loop
#define FOR(i, j, k, in) for (int i = (j); i < (k) ; i += (in))
#define FORW(i, j, k, in) for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in) for (int i = (j); i >= (k); i -= (in))
// Define Data structure func
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(cont) int((cont).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// Define number
#define IINF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define PI 3.1415926535897932384626433832795
// Other
#define lend '\n'
#define hardio(name) freopen(name".inp","r",stdin), freopen(name".out","w",stdout);
void FastIO() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin.exceptions(cin.failbit); srand(time(NULL)); }
const int MOD = 1e9 + 7, MOD2 = 1e9 + 9;
// ======================================================================
int a[300006] = {}, cnt[300006] = {};
int cnt3[1000006] = {};
int exist[1000006] = {};
namespace io { const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
inline void flush() { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; } // print the remaining part
inline void putc(char x) { *oS++ = x; if (oS == oT) flush (); } // putchar
template<typename A> inline bool read (A &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1; else if (c == EOF) return 0;
for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
return 1; }
inline bool read(char &x) { while((x = gc()) == ' ' || x == '\n' || x == '\r'); return x != EOF; }
inline bool read(string& x) {
while ((c = gc()) == '\n' || c == ' '|| c == '\r'); if (c == EOF) return 0; x.clear();
while (!(c == '\n' || c == ' ' || c == '\r' || c == EOF)) x.push_back(c), c = gc(); return 1;
}
template<typename A,typename ...B>
inline int read(A &x, B &...y) { return read(x) + read(y...); }
template<typename A> inline bool write(A x) {
if (!x) putc('0'); if (x < 0) putc ('-'), x = -x;
while (x) qu[++qr] = x % 10 + '0', x /= 10;
while (qr) putc(qu[qr--]);
return 0; }
inline bool write(char x) { putc(x); return 0; }
inline bool write(const char *x){ while (*x){ putc(*x); ++x; } return 0; }
inline bool write(char *x){ while (*x){ putc(*x); ++x; } return 0; }
template<typename A,typename ...B>
inline bool write(A x,B ...y){ return write(x) || write(y...); }
//no need to call flush at the end manually!
struct Flusher_ {~Flusher_(){ flush(); }} io_flusher_;
} using io::read; using io::putc; using io::write;
int main(int argc, char* argv[]) { FastIO();
int n, k; read(n, k);
FORW(i, 1, n, 1) read(a[i]);
/*
if (n <= 2000) {
FORW(i, 1, n, 1) {
FORW(j, 1, n, 1) {
if (a[i] == a[j]) continue;
if (a[i] % a[j] == k) cnt[i]++;
}
}
}
*/
/*
else if (sz(ss2) <= 2000)
{
for(map<int, int>::iterator it = ss2.begin(); it != ss2.end(); ++it) {
for(map<int, int>::iterator it2 = ss2.begin(); it2 != ss2.end(); ++it2) {
if (it->fi == it2->fi) continue;
if (it->fi % it2->fi == k) it->se++;
}
}
FORW(i, 1, n, 1) cnt[i] = ss2[a[i]];
}
else if (k == 0)
*/
{
FORW(i, 1, n, 1) exist[a[i]]++;
FORW(i, 1, n, 1) {
if (exist[k] && k < a[i]) cnt3[k]++;
if (a[i] >= k) {
int tmp = a[i] - k;
FORW(j, 1, sqrt(tmp), 1)
if (tmp % j == 0) {
int l1 = j, l2 = tmp / j;
if (a[i] % l1 == k && a[i] != l1 && exist[l1]) cnt3[a[i]] += exist[l1];
if (a[i] % l2 == k && a[i] != l2 && l1 != l2 && exist[l2]) cnt3[a[i]] += exist[l2];
}
}
}
FORW(i, 1, n, 1) if (a[i] == k) cnt[i] = cnt3[k]; else cnt[i] = cnt3[a[i]] / exist[a[i]];
}
FORW(i, 1, n, 1) write(cnt[i], ' ');
return 0; }
Compilation message
spiderman.cpp: In function 'bool io::read(A&)':
spiderman.cpp:46:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
46 | for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
| ^~~
spiderman.cpp:46:76: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
46 | for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
| ^
spiderman.cpp: In function 'bool io::read(std::string&)':
spiderman.cpp:50:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
50 | while ((c = gc()) == '\n' || c == ' '|| c == '\r'); if (c == EOF) return 0; x.clear();
| ^~~~~
spiderman.cpp:50:61: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
50 | while ((c = gc()) == '\n' || c == ' '|| c == '\r'); if (c == EOF) return 0; x.clear();
| ^~
spiderman.cpp:51:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
51 | while (!(c == '\n' || c == ' ' || c == '\r' || c == EOF)) x.push_back(c), c = gc(); return 1;
| ^~~~~
spiderman.cpp:51:93: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
51 | while (!(c == '\n' || c == ' ' || c == '\r' || c == EOF)) x.push_back(c), c = gc(); return 1;
| ^~~~~~
spiderman.cpp: In function 'bool io::write(A)':
spiderman.cpp:56:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
56 | if (!x) putc('0'); if (x < 0) putc ('-'), x = -x;
| ^~
spiderman.cpp:56:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
56 | if (!x) putc('0'); if (x < 0) putc ('-'), x = -x;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4772 KB |
Output is correct |
2 |
Correct |
7 ms |
3020 KB |
Output is correct |
3 |
Correct |
282 ms |
7068 KB |
Output is correct |
4 |
Correct |
819 ms |
10004 KB |
Output is correct |
5 |
Correct |
330 ms |
9936 KB |
Output is correct |
6 |
Incorrect |
942 ms |
13144 KB |
Output isn't correct |
7 |
Correct |
370 ms |
9924 KB |
Output is correct |
8 |
Correct |
375 ms |
10020 KB |
Output is correct |
9 |
Correct |
1076 ms |
12976 KB |
Output is correct |
10 |
Correct |
1068 ms |
12888 KB |
Output is correct |