QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698133 | #9431. The Quest for El Dorado | Hojstyer | RE | 0ms | 3656kb | C++20 | 4.9kb | 2024-11-01 17:35:50 | 2024-11-01 17:35:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T>
struct ST
{
T MAX = 1e9;
vector<vector<T>> maxn;
vector<T> a;
const int m = 20;
vector<T> LOG;
ST() {}
ST(int n, vector<T> b)
{
a.resize(n + 1, 0);
a = b;
init(n);
}
void init(int n)
{
if (std::is_same<T, ll>::value)
MAX = 1e18;
maxn.resize(n + 1, vector<T>(m + 1, -MAX));
LOG.resize(n + 1, 0);
for (int i = 1; i <= n; i++)
maxn[i][0] = a[i];
LOG[1] = 0;
for (int i = 2; i <= n; i++)
LOG[i] = LOG[i / 2] + 1;
for (int j = 1; (1 << j) <= n; j++)
for (int i = 1; i + (1 << (j - 1)) <= n; i++)
maxn[i][j] = max(maxn[i][j - 1], maxn[i + (1 << (j - 1))][j - 1]);
}
void init(int n, vector<T> b)
{
if (std::is_same<T, ll>::value)
MAX = 1e18;
a.resize(n + 1, 0);
a = b;
maxn.resize(n + 1, vector<T>(m + 1, -MAX));
LOG.resize(n + 1, 0);
for (int i = 1; i <= n; i++)
maxn[i][0] = a[i];
LOG[1] = 0;
for (int i = 2; i <= n; i++)
LOG[i] = LOG[i / 2] + 1;
for (int j = 1; (1 << j) <= n; j++)
for (int i = 1; i + (1 << (j - 1)) <= n; i++)
maxn[i][j] = max(maxn[i][j - 1], maxn[i + (1 << (j - 1))][j - 1]);
}
T query_max(int l, int r)
{
int d = LOG[r - l + 1];
return max(maxn[l][d], maxn[r - (1 << d) + 1][d]);
}
};
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vector<vector<array<int, 3>>> adj(n + 1);
for (int i = 1; i <= m; ++i)
{
int u, v, c, l;
cin >> u >> v >> c >> l;
adj[u].push_back({v, c, l});
adj[v].push_back({u, c, l});
}
vector<int> a(n + 1), b(n + 1);
vector<vector<int>> pos(m + 1);
for (int i = 1; i <= k; ++i)
{
cin >> a[i] >> b[i];
pos[a[i]].push_back(i);
}
vector<ST<int>> seg(m + 1);
for (int i = 1; i <= m; ++i)
{
int r = pos[i].size();
vector<int> f(r + 1);
for (int j = 0; j < r; ++j)
f[j + 1] = b[pos[i][j]];
seg[i].init(r + 1, f);
}
priority_queue<array<ll, 3>> q;
vector<ll> dis(n + 1, 1e18), tg(n + 1, k + 1);
dis[1] = 0, tg[1] = 0;
q.push({0, -dis[1], 1});
while (!q.empty())
{
auto [nk, _, u] = q.top();
q.pop();
for (auto [v, p, w] : adj[u])
{
if (a[tg[u]] == p)
{
ll np = tg[u];
// tg[v] = tg[u], dis[v] = dis[u] + w;
if (dis[u] + w > b[np])
{
int j = lower_bound(pos[a[np]].begin(), pos[a[np]].end(), np + 1) - pos[a[np]].begin();
int l = j + 1, r = pos[a[np]].size(), now = -1;
while (l <= r)
{
int mid = l + r >> 1;
if (seg[a[np]].query_max(l, mid) >= w)
r = mid - 1, now = mid;
else
l = mid + 1;
}
if (now != -1 && (pos[a[np]][now - 1] < tg[v] || (pos[a[np]][now - 1] == tg[v] && dis[v] > w)))
{
tg[v] = pos[a[np]][now - 1];
dis[v] = w;
q.push({-tg[v], -dis[v], v});
}
}
else if (tg[u] < tg[v] || (tg[u] == tg[v] && dis[v] > dis[u] + w))
{
tg[v] = tg[u], dis[v] = dis[u] + w;
q.push({-tg[v], -dis[v], v});
}
}
else
{
int j = lower_bound(pos[p].begin(), pos[p].end(), tg[u] + 1) - pos[p].begin();
int l = j + 1, r = pos[p].size(), now = -1;
while (l <= r)
{
int mid = l + r >> 1;
if (seg[p].query_max(l, mid) >= w)
r = mid - 1, now = mid;
else
l = mid + 1;
}
if (now != -1 && (pos[p][now - 1] < tg[v] || (pos[p][now - 1] == tg[v] && dis[v] > w)))
{
tg[v] = pos[p][now - 1];
dis[v] = w;
q.push({-tg[v], -dis[v], v});
}
}
}
}
string ans;
for (int i = 1; i <= n; ++i)
ans += (tg[i] > k ? '0' : '1');
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
2 5 6 4 1 2 1 30 2 3 1 50 2 5 5 50 3 4 6 10 2 4 5 30 2 5 1 40 1 70 6 100 5 40 1 30 3 1 1 2 3 1 10 1 100
output:
11011 100
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1110 46 80 30 44 23 5 46 10 28 1 64 32 34 3 40 9 36 1 26 15 14 5 95 38 19 2 34 2 17 4 183 10 38 2 81 5 15 2 83 31 38 3 100 40 30 1 53 41 10 1 193 29 20 5 18 14 41 3 78 8 16 5 74 46 13 3 78 44 28 3 45 1 40 3 133 5 32 1 108 22 26 2 83 10 38 1 77 11 40 1 11 17 21 2 66 41 46 3 98 9 36 2 25 40 18 1 19 27...