結果

問題 No.1055 牛歩
ユーザー hitonanode
提出日時 2020-05-17 16:35:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 3,028 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 209,688 KB
最終ジャッジ日時 2025-01-10 12:42:36
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void No()
{
    puts("NO");
    exit(0);
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    cin >> A;

    vector<vector<int>> TS(M);

    int Q;
    cin >> Q;
    REP(t, Q)
    {
        int b;
        cin >> b;
        TS[b - 1].emplace_back(t + 1);
    }
    vector<pint> hist_prev{{{0, 0}}};
    REP(i, A.size())
    {
        priority_queue<pint, vector<pint>, greater<pint>> pq;
        for (auto x : hist_prev) pq.push(x);
        for (auto t : TS[i]) pq.emplace(t, -1);
        using P = pair<int, pint>;
        vector<P> hist{{0, {A[i], A[i]}}};

        int prev_now = (i ? A[i - 1] : 0);
        while (pq.size())
        {
            auto [t, x] = pq.top();
            pq.pop();
            if (x == -1)
            {
                auto [l, r] = hist.back().second;
                l--, r++;
                while (l <= prev_now) l += 2;
                hist.emplace_back(t, pint(l, r));
            }
            else
            {
                prev_now = x;
                int &l = hist.back().second.first;
                while (l <= prev_now) l += 2;
            }
        }
        vector<pint> hist_next(hist.size());
        IREP(i, hist.size())
        {
            if (hist[i].second.first > hist[i].second.second or hist[i].second.first > N) No();
            if (i)
            {
                chmax(hist[i - 1].second.first, hist[i].second.first - 1);
                chmin(hist[i - 1].second.second, hist[i].second.second + 1);
            }
            hist_next[i] = make_pair(hist[i].first, hist[i].second.first);
        }
        hist_prev = hist_next;
    }
    puts("YES");
}
0