/* -*- coding: utf-8 -*- * * 1508.cc: No.1508 Avoid being hit - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_Q = 100000; /* typedef */ typedef pair pii; typedef vector vpii; /* global variables */ int as[MAX_Q], bs[MAX_Q], vs[MAX_Q + 1]; vpii gs[MAX_Q + 1]; /* subroutines */ void splitg(int x, vpii &g) { vpii tg; for (auto p: g) { if (p.first <= x && x < p.second) { if (p.first < x) tg.push_back(pii(p.first, x)); if (x + 1 < p.second) tg.push_back(pii(x + 1, p.second)); } else tg.push_back(p); } swap(g, tg); } bool includeg(int x, vpii &g) { for (auto p: g) if (p.first <= x && x < p.second) return true; return false; } void printg(vpii g) { for (auto p: g) printf("(%d,%d) ", p.first, p.second); putchar('\n'); } /* main */ int main() { int n, q; scanf("%d%d", &n, &q); for (int i = 0; i < q; i++) scanf("%d", as + i), as[i]--; for (int i = 0; i < q; i++) scanf("%d", bs + i), bs[i]--; gs[0].push_back(pii(0, n)); for (int i = 0; i < q; i++) { vpii &g0 = gs[i], &g1 = gs[i + 1]; int l = -1, r = -1; for (auto p: g0) { int li = p.first, ri = p.second; if (li > 0) li--; if (ri < n) ri++; if (l < 0) l = li, r = ri; else if (r < li) { g1.push_back(pii(l, r)); l = li, r = ri; } else r = ri; } if (l >= 0) g1.push_back(pii(l, r)); splitg(as[i], g1); splitg(bs[i], g1); if (g1.empty()) { puts("NO"); return 0; } } //for (int i = 0; i <= q; i++) printf("%d: ", i), printg(gs[i]); vs[q] = gs[q][0].first; for (int i = q - 1; i >= 0; i--) { int x = vs[i + 1]; if (includeg(x, gs[i])) vs[i] = x; else if (x > 0 && includeg(x - 1, gs[i])) vs[i] = x - 1; else vs[i] = x + 1; } puts("YES"); for (int i = 0; i <= q; i++) printf("%d\n", vs[i] + 1); return 0; }