Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@Author: Ozhetov Arsen Nurlanuly
- #pragma comment (linker, "/stack:20000000")
- #pragma GCC optimize ("Ofast")
- #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <ext/pb_ds/detail/standard_policies.hpp>
- #define sz(s) (int)(s.size ())
- #define all(s) s.begin (), s.end ()
- #define rall(s) s.rbegin (), s.rend ()
- #define Unique(s) s.resize (unique (all (s)) - s.begin ());
- #define fi first
- #define se second
- #define endl "\n"
- #define debug(...) fprintf (stderr, __VA_ARGS__)
- #define Time clock () * 1.0 / CLOCKS_PER_SEC
- #define sqr(x) ((x) * 1ll * (x))
- #define lcm(a, b) ((a) / gcd (a, b) * (b))
- #define bit(x) __builtin_popcount (x)
- #define bitll(x) __builtin_popcountll (x)
- #define foreach(it, s) for (__typeof (s.begin ()) it = s.begin (); it != s.end (); ++it)
- #define rep(a, b, c) for (int a = b; a <= c; ++a)
- #define per(a, b, c) for (int a = b; a >= c; --a)
- #define _ ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie (NULL);
- using namespace std;
- using namespace __gnu_pbds;
- template<typename T1, typename T2>inline bool updmin (T1 &a, T2 &b) { return a > b ? a = b, 1 : 0; }
- template<typename T1, typename T2>inline bool updmax (T1 &a, T2 &b) { return a < b ? a = b, 1 : 0; }
- template<typename T>inline T gcd (T &a, T &b) { while (a && b) a > b ? a %= b : b %= a; return a + b; }
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const double PI = (double)(acos (-1.0)), EPS = (double)(1e-7);
- const int MOD = 1e9 + 7, PR = 15937, INF = 1 << 30, MXN = 3e5 + 17;
- const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
- inline int readChar ();
- template<class T = int>inline T readInt ();
- template<class T>inline void writeInt (T x, char end = 0);
- inline void writeChar (int x);
- inline void writeWord (const char *s);
- static const int buf_size = 4096;
- inline int getChar () {
- static char buf[buf_size];
- static int len = 0, pos = 0;
- if (pos == len)
- pos = 0, len = fread (buf, 1, buf_size, stdin);
- if (pos == len) return -1;
- return buf[pos++];
- }
- inline int readChar () {
- int c = getChar ();
- while (c <= 32) c = getChar ();
- return c;
- }
- template<class T>inline T readInt () {
- int s = 1, c = readChar ();
- T x = 0;
- if (c == '-') s = -1, c = getChar ();
- while ('0' <= c && c <= '9')
- x = x * 10 + c - '0', c = getChar ();
- return s == 1 ? x : -x;
- }
- static int write_pos = 0;
- static char write_buf[buf_size];
- inline void writeChar (int x) {
- if (write_pos == buf_size)
- fwrite (write_buf, 1, buf_size, stdout), write_pos = 0;
- write_buf[write_pos++] = x;
- }
- template<class T>inline void writeInt (T x, char end) {
- if (x < 0) writeChar ('-'), x = -x;
- char s[24];
- int n = 0;
- while (x || !n)
- s[n++] = '0' + x % 10, x /= 10;
- while (n--) writeChar (s[n]);
- if (end) writeChar (end);
- }
- inline void writeWord (const char *s) {
- while (*s) writeChar (*s++);
- }
- struct Flusher {
- ~Flusher () {
- if (write_pos)
- fwrite (write_buf, 1, write_pos, stdout), write_pos = 0;
- }
- } flusher;
- int n, k, a[MXN], ans[MXN];
- vector<int>g[MXN];
- int add[MXN * 4], t[MXN * 4];
- inline void push (int v, int tl, int tr) {
- if (add[v] != -1) {
- if (tl != tr)
- add[v << 1] = add[v],
- add[v << 1 | 1] = add[v];
- t[v] = add[v];
- add[v] = -1;
- }
- }
- void update (int v, int tl, int tr, int l, int r, int val) {
- push (v, tl, tr);
- if (l > tr || tl > r)
- return;
- if (l <= tl && tr <= r) {
- add[v] = val;
- return push (v, tl, tr);
- }
- int tm = (tl + tr) >> 1;
- update (v << 1, tl, tm, l, r, val);
- update (v << 1 | 1, tm + 1, tr, l, r, val);
- t[v] = t[v << 1] + t[v << 1 | 1];
- }
- int get (int v, int tl, int tr, int l, int r) {
- push (v, tl, tr);
- if (l > tr || tl > r)
- return 0;
- if (l <= tl && tr <= r)
- return t[v];
- int tm = (tl + tr) >> 1;
- return get (v << 1, tl, tm, l, r) + get (v << 1 | 1, tm + 1, tr, l, r);
- }
- void dfs (int v) {
- push (1, 1, n);
- ans[v] = t[1];
- int l = max (0, v - k);
- int r = min (n, v + k);
- update (1, 1, n, l, r, 1);
- for (auto &to : g[v])
- dfs (to);
- }
- inline void Solve () {
- n = readInt ();
- k = readInt ();
- memset (ans, -1, sizeof ans);
- rep (i, 1, n)
- a[i] = readInt (),
- g[a[i]].push_back (i);
- dfs (0);
- rep (i, 1, n)
- writeInt (ans[i], ' ');
- }
- inline void Clear () {}
- int main () { //_
- unsigned int FOR;
- asm ("rdtsc" : "=A"(FOR)); srand (FOR);
- #define HaveTestCase 0
- #define LightOjTestCase 0
- #ifdef _DeSeiSH_
- freopen ("Input.txt", "r", stdin);
- freopen ("OutputMain.txt", "w", stdout);
- #endif
- int T = 1;
- if (HaveTestCase) T = readInt ();
- rep (i, 1, T) {
- if (LightOjTestCase)
- writeWord ("Case "), writeInt (i, ':');
- Solve ();
- if (i != T) Clear ();
- }
- #ifdef _DeSeiSH_
- debug ("\ntime: %.6lf\n", Time);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement