結果
| 問題 |
No.3319 Iwaijkstra
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-01 00:49:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,303 bytes |
| コンパイル時間 | 4,969 ms |
| コンパイル使用メモリ | 286,024 KB |
| 実行使用メモリ | 31,696 KB |
| 最終ジャッジ日時 | 2025-11-01 00:49:50 |
| 合計ジャッジ時間 | 26,584 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 WA * 29 RE * 3 |
ソースコード
#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;}
pair<i64, i128> op1(pair<i64, i128> a, pair<i64, i128> b) {return a.first < b.first ? a : a.first > b.first ? b : (pair<i64, i128>){a.first, a.second + b.second};}
pair<i64, i128> e1() {return {1e18, 0};}
void _main() {
i64 n, m;
cin >> n >> 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--;
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;
}
}
}
i128 ans = 1;
atcoder::lazy_segtree<pair<i64, i128>, op1, e1, pair<i64, i128>, op1, op1, e1> seg(n);
seg.set(0, {0, 1});
vector<i64> res(n, 0);
for (i64 i : ord) {
auto [d, cnt] = seg.get(i);
res[i] = cnt;
for (auto [l, r, c] : g[i]) {
ans += (r - l) * cnt;
if (ans > 1e18) {
cout << "Too Many\n";
return;
}
seg.apply(l, r, {d + c, cnt});
}
}
for (i64 i = 0; i < n; i++) {
assert(res[i] == seg.get(i).second);
}
cout << (i64)ans << "\n";
}