#include <algorithm> #include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define INT(x) int x; scanf("%d", &x) int a[100000][2], x[200000], y[200000], r[10]; bool u[100000][2]; inline bool con(bool u00, bool u01, bool u10, bool u11) { return u00 && u10 || u01 && u11; } int main() { INT(n); INT(k); REP(j,2) REP(i,n) scanf("%d", &a[i][j]); REP(i,n) REP(j,2) { --a[i][j]; x[a[i][j]] = i; y[a[i][j]] = j; } int n2 = n << 1; REP(p,n2) { REP(i,n) REP(j,2) u[i][j] = 0; int e = n, c = n; FOR(q,p,n2) { int xx = x[q], yy = y[q]; int xp = (xx + 1) % n, xm = (xx + n - 1) % n; if (!u[xx][0] && !u[xx][1]) --e; bool mirror = u[xx][1 - yy], pl = u[xp][yy], plm = u[xp][1 - yy], mi = u[xm][yy], mim = u[xm][1 - yy]; if (!con(0, mirror, pl, plm) && con(1, mirror, pl, plm)) --c; if (!con(0, mirror, mi, mim) && con(1, mirror, mi, mim)) --c; u[xx][yy] = 1; int v = max(c - e, 1); if (v <= k) ++r[v - 1]; } } REP(v,k) { if (v) printf(" "); printf("%d", r[v]); } }
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 | #include <algorithm> #include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define INT(x) int x; scanf("%d", &x) int a[100000][2], x[200000], y[200000], r[10]; bool u[100000][2]; inline bool con(bool u00, bool u01, bool u10, bool u11) { return u00 && u10 || u01 && u11; } int main() { INT(n); INT(k); REP(j,2) REP(i,n) scanf("%d", &a[i][j]); REP(i,n) REP(j,2) { --a[i][j]; x[a[i][j]] = i; y[a[i][j]] = j; } int n2 = n << 1; REP(p,n2) { REP(i,n) REP(j,2) u[i][j] = 0; int e = n, c = n; FOR(q,p,n2) { int xx = x[q], yy = y[q]; int xp = (xx + 1) % n, xm = (xx + n - 1) % n; if (!u[xx][0] && !u[xx][1]) --e; bool mirror = u[xx][1 - yy], pl = u[xp][yy], plm = u[xp][1 - yy], mi = u[xm][yy], mim = u[xm][1 - yy]; if (!con(0, mirror, pl, plm) && con(1, mirror, pl, plm)) --c; if (!con(0, mirror, mi, mim) && con(1, mirror, mi, mim)) --c; u[xx][yy] = 1; int v = max(c - e, 1); if (v <= k) ++r[v - 1]; } } REP(v,k) { if (v) printf(" "); printf("%d", r[v]); } } |