// plo #include <bits/stdc++.h> #include <cstdio> #include <iostream> //#define TEST using namespace std; #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() #define init_v(tab, n) fo(1, n) tab.pb(0) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) os << v[i] << " "; return os; } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef TEST #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) ; #define dbg0(x, n) ; #endif void przekierowanie() { #ifdef TEST freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } vector<vector<long>> tab; long n, k; vector<vector<long>> sasiedzi; vector<vector<long>> przedzialy; vector<long> ciekawosci; vector<ll> pom; ll wart_init = 0; void wczytaj() { tab.pb(*(new vector<long>)); for (long i = 0; i < n; i++) { long x; cin >> x; tab[0].pb(x); } tab.pb(*(new vector<long>)); for (long i = 0; i < n; i++) { long x; cin >> x; tab[1].pb(x); } } void init_sasiedzi() { fi(0, 2 * n + 2) sasiedzi.pb(*(new vector<long>)); fi(0, 1) fj(0, n - 1) { auto liczba = tab[i][j]; sasiedzi[liczba].pb(tab[1 - i][j]); sasiedzi[liczba].pb(tab[i][(j + 1) % n]); sasiedzi[liczba].pb(tab[i][(j + n - 1) % n]); } } void init_przedzialy() { fi(0, 2 * n + 2) przedzialy.pb(*(new vector<long>)); } void init_ciekawosci() { fi(0, 11) ciekawosci.pb(0); } void init_pom() { fi(0, 2 * n + 2) pom.pb(0); } bool czy_sasiedzi(long a, long b) { fi(0, 2) if (sasiedzi[a][i] == b) return true; return false; } int main() { FAST przekierowanie(); cin >> n >> k; dbg(n); dbg(k); wczytaj(); dbg(tab); init_sasiedzi(); dbg(sasiedzi); init_przedzialy(); init_ciekawosci(); init_pom(); for (long num = 2 * n; num > 0; num--) { auto max_delta = 2 * n - num; // dbg(max_delta); // przedzialy[num].pb(1); ciekawosci[1]++; fi(1, max_delta) { wart_init++; auto start = wart_init; // auto k = num; for (long z = num; z <= num + i; z++) if (pom[z] < start) { // cerr << "!1 z=" << z << endl; queue<long> kolejka; kolejka.push(z); // dbg(z); pom[z] = wart_init; // dbg(pom[z]); while (!kolejka.empty()) { auto x = kolejka.front(); // dbg(x); kolejka.pop(); fj(0, 2) { auto y = sasiedzi[x][j]; // dbg(y); if (y > num && y <= num + i && pom[y] < start) { // cerr << "!2\n"; pom[y] = wart_init; kolejka.push(y); } } } wart_init++; } // fj(num, num + i) dbg(num); dbg(num + i); dbg(start); dbg(wart_init); // cout << "(" << num << " , " << num+1 << ") = " << wart_init - start << endl; ciekawosci[wart_init - start]++; // dbg(pom[5]); // fj(num, num + i) { cerr << "pom[" << j << "] = " << pom[j] << endl; } } // if (num < 6) exit(1); } dbg(przedzialy); dbg(ciekawosci); fi(1, k) cout << ciekawosci[i] << " "; cout << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | // plo #include <bits/stdc++.h> #include <cstdio> #include <iostream> //#define TEST using namespace std; #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() #define init_v(tab, n) fo(1, n) tab.pb(0) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) os << v[i] << " "; return os; } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef TEST #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) ; #define dbg0(x, n) ; #endif void przekierowanie() { #ifdef TEST freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } vector<vector<long>> tab; long n, k; vector<vector<long>> sasiedzi; vector<vector<long>> przedzialy; vector<long> ciekawosci; vector<ll> pom; ll wart_init = 0; void wczytaj() { tab.pb(*(new vector<long>)); for (long i = 0; i < n; i++) { long x; cin >> x; tab[0].pb(x); } tab.pb(*(new vector<long>)); for (long i = 0; i < n; i++) { long x; cin >> x; tab[1].pb(x); } } void init_sasiedzi() { fi(0, 2 * n + 2) sasiedzi.pb(*(new vector<long>)); fi(0, 1) fj(0, n - 1) { auto liczba = tab[i][j]; sasiedzi[liczba].pb(tab[1 - i][j]); sasiedzi[liczba].pb(tab[i][(j + 1) % n]); sasiedzi[liczba].pb(tab[i][(j + n - 1) % n]); } } void init_przedzialy() { fi(0, 2 * n + 2) przedzialy.pb(*(new vector<long>)); } void init_ciekawosci() { fi(0, 11) ciekawosci.pb(0); } void init_pom() { fi(0, 2 * n + 2) pom.pb(0); } bool czy_sasiedzi(long a, long b) { fi(0, 2) if (sasiedzi[a][i] == b) return true; return false; } int main() { FAST przekierowanie(); cin >> n >> k; dbg(n); dbg(k); wczytaj(); dbg(tab); init_sasiedzi(); dbg(sasiedzi); init_przedzialy(); init_ciekawosci(); init_pom(); for (long num = 2 * n; num > 0; num--) { auto max_delta = 2 * n - num; // dbg(max_delta); // przedzialy[num].pb(1); ciekawosci[1]++; fi(1, max_delta) { wart_init++; auto start = wart_init; // auto k = num; for (long z = num; z <= num + i; z++) if (pom[z] < start) { // cerr << "!1 z=" << z << endl; queue<long> kolejka; kolejka.push(z); // dbg(z); pom[z] = wart_init; // dbg(pom[z]); while (!kolejka.empty()) { auto x = kolejka.front(); // dbg(x); kolejka.pop(); fj(0, 2) { auto y = sasiedzi[x][j]; // dbg(y); if (y > num && y <= num + i && pom[y] < start) { // cerr << "!2\n"; pom[y] = wart_init; kolejka.push(y); } } } wart_init++; } // fj(num, num + i) dbg(num); dbg(num + i); dbg(start); dbg(wart_init); // cout << "(" << num << " , " << num+1 << ") = " << wart_init - start << endl; ciekawosci[wart_init - start]++; // dbg(pom[5]); // fj(num, num + i) { cerr << "pom[" << j << "] = " << pom[j] << endl; } } // if (num < 6) exit(1); } dbg(przedzialy); dbg(ciekawosci); fi(1, k) cout << ciekawosci[i] << " "; cout << endl; return 0; } |