結果

問題 No.1194 Replace
ユーザー tomatoma
提出日時 2020-08-22 17:44:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 2,741 ms
コンパイル使用メモリ 212,372 KB
実行使用メモリ 84,864 KB
最終ジャッジ日時 2024-04-23 11:34:20
合計ジャッジ時間 24,323 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1,470 ms
84,736 KB
testcase_08 AC 1,433 ms
84,736 KB
testcase_09 AC 1,468 ms
84,864 KB
testcase_10 AC 1,442 ms
84,864 KB
testcase_11 AC 1,423 ms
84,736 KB
testcase_12 AC 1,415 ms
84,736 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    ll N, M;
    cin >> N >> M;
    set<ll> vals;
    map<ll, vector<ll>> rev;
    rep(i, M) {
        ll B, C;
        cin >> B >> C;
        vals.insert(B);
        vals.insert(C);
        rev[C].push_back(B);
    }
    map<ll, ll> id2mp;
    for (auto val : vals)id2mp[val] = val;
    {
        auto itr = vals.end();
        do {
            --itr;
            for (auto next : rev[*itr]) {
                id2mp[next] = max(id2mp[next], id2mp[*itr]);
            }
        } while (itr != vals.begin());
    }

    ll res = N * (N + 1) / 2;
    for (auto[idx, val] : id2mp) {
        res += val - idx;
    }
    cout << res << endl;
    return 0;
}
0