結果

問題 No.3319 Iwaijkstra
コンテスト
ユーザー areik
提出日時 2025-11-01 00:34:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 3,112 bytes
コンパイル時間 5,581 ms
コンパイル使用メモリ 282,196 KB
実行使用メモリ 28,648 KB
最終ジャッジ日時 2025-11-01 00:34:39
合計ジャッジ時間 11,602 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "atcoder/scc.hpp"
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using f64 = long double;
using mint = atcoder::modint998244353;


void _main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(18);
  _main();
}

i64 pow(i64 a, i64 n) {
  i64 res = 1;
  i64 x = a;
  while (n > 0) {
    if (n & 1) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}
p2 op(p2 a, p2 b) {return min(a, b);}
p2 e() {return {1e18, 1e18};}
p2 mpn(i64 f, p2 x) {return x.second == -1 ? x : (p2){min(f, x.first), x.second};}
i64 cmp(i64 f, i64 g) {return min(f, g);}
i64 idn() {return 1e18;}

p2 mps(i64 f, p2 x) {return {x.first + f, x.second};}
i64 cms(i64 f, i64 g) {return f + g;}
i64 ids() {return 0;}

p2 opx(p2 a, p2 b) {return max(a, b);}
p2 ex() {return {0, -1};}
void _main() {
  i64 n, m;
  cin >> n >> m;
  vector<tuple<i64, i64, i64, i64>> edge(m);
  vector<vector<el>> g(n);
  for (i64 i = 0; i < m; i++) {
    i64 x, l, r, c;
    cin >> x >> l >> r >> c;
    x--;
    l--;
    edge[i] = {x, l, r, c};
    g[x].push_back({l, r, c});
  }
  vector<i64> dist(n, 1e18);
  {
    atcoder::lazy_segtree<p2, op, e, i64, mpn, cmp, idn> seg(n);
    for (i64 i = 0; i < n; i++) seg.set(i, {1e18, i});
    seg.set(0, {0, 0});
    while (seg.all_prod().first != 1e18) {
      auto [d, i] = seg.all_prod();
      seg.set(i, {1e18, -1});
      dist[i] = d;
      for (auto [l, r, c] : g[i]) {
        seg.apply(l, r, d + c);
      }
    }
  }
  map<i64, vector<i64>> mp;
  for (i64 i = 0; i < n; i++) {
    if (dist[i] == 1e18) continue;
    mp[dist[i]].push_back(i);
  }
  vector<i64> ord;
  for (auto [x, v] : mp) {
    atcoder::lazy_segtree<p2, op, e, i64, mps, cms, ids> seg(v.size());
    for (i64 i = 0; i < v.size(); i++) {
      seg.set(i, {0, i});
    }
    for (i64 i = 0; i < v.size(); i++) {
      for (auto [l, r, c] : g[v[i]]) {
        if (c != 0) continue;
        i64 i1 = lower_bound(v.begin(), v.end(), l) - v.begin();
        i64 i2 = lower_bound(v.begin(), v.end(), r) - v.begin();
        seg.apply(i1, i2, 1);
      }
    }
    while (seg.all_prod().first == 0) {
      auto [d, i] = seg.all_prod();
      seg.set(i, {1e18, 1e18});
      ord.push_back(v[i]);
      for (auto [l, r, c] : g[v[i]]) {
        if (c != 0) continue;
        i64 i1 = lower_bound(v.begin(), v.end(), l) - v.begin();
        i64 i2 = lower_bound(v.begin(), v.end(), r) - v.begin();
        seg.apply(i1, i2, -1);
      }
    }
    for (i64 i = 0; i < v.size(); i++) {
      if (seg.get(i).first != 1e18) {
        cout << "Too Many\n";
        return;
      }
    }
  }
  vector<i64> dp(n, 0);
  dp[0]++;
  i64 ans = 1;
  for (i64 i : ord) {
    for (auto [l, r, c] : g[i]) {
      for (i64 j = l; j < r; j++) {
        if (dist[j] == dist[i] + c) {
          dp[j] += dp[i];
        }
        ans += dp[i];
        if (ans > 1e18) {
          cout << "Too Many\n";
          return;
        }
      }
    }
  }
  cout << ans << "\n";
}
0