Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(d) d.begin(), d.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef pair<int, int> pii;
- typedef long double ld;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- struct event {
- int x, type, ind;
- event(int _x, int _type, int _ind) {
- type = _type, x = _x, ind = _ind;
- }
- bool operator<(const event& other) {
- return (x < other.x || (x == other.x && type > other.type));
- }
- };
- int n, m;
- cin >> n >> m;
- vector<event> line;
- for (int i = 0; i < n; i++) {
- int x;
- cin >> x;
- line.push_back(event(x, 0, i));
- }
- vector<int> r(m);
- for (int i = 0; i < m; i++) {
- int L, R;
- cin >> L >> R;
- r[i] = R;
- line.push_back(event(L, 1, i));
- line.push_back(event(R, -1, i));
- }
- sort(all(line));
- multiset<pii> unused;
- vector<vector<int>> us(n);
- for (const event& i : line) {
- if (i.type == 0) {
- auto it = unused.begin();
- while (true) {
- if (it == unused.end() || (int)us[i.ind].size() == 3) {
- break;
- }
- us[i.ind].push_back((*it).second);
- it++;
- }
- }
- if (i.type == 1) {
- unused.insert({ r[i.ind],i.ind });
- }
- if (i.type == -1) {
- unused.erase({ r[i.ind],i.ind });
- }
- }
- vector<vector<bool>> dp(3, vector<bool>(n, false));
- vector<vector<int>> kid(3, vector<int>(n, -1));
- for (int i = 0; i < (int)us[0].size(); i++)dp[i][0] = true, kid;
- for (int i = 1; i < n; i++) {
- for (int j = 0; j < (int)us[i].size(); j++) {
- for (int k = 0; k < (int)us[i - 1].size(); k++) {
- dp[j][i] = (dp[j][i] || (dp[k][i - 1] && (us[i - 1][k] != us[i][j])));
- if (dp[k][i - 1] && (us[i - 1][k] != us[i][j])) {
- kid[j][i] = k;
- }
- }
- }
- }
- bool ok = false;
- int f = 0;
- for (int i = 0; i < (int)us.back().size(); i++) {
- ok = (ok || dp[i][n - 1]);
- if (dp[i][n - 1])f = i;
- }
- if (ok) {
- cout << "Yes\n";
- int i = n - 1;
- vector<int> ans;
- while (1) {
- if (i < 0) {
- break;
- }
- ans.push_back(us[i][f]);
- f = kid[f][i], i--;
- }
- reverse(all(ans));
- for (int i = 0; i < n; i++) {
- cout << ans[i] + 1 << ' ';
- }
- }
- else {
- cout << "No\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement