QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718718 | #9431. The Quest for El Dorado | liliwa | TL | 4ms | 7964kb | C++23 | 3.6kb | 2024-11-06 21:15:58 | 2024-11-06 21:15:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
#define x first
#define y second
#define rep(i, a, b) for(ll i = (a); i <= (b); i++)
#define lep(i, a, b) for(ll i = (a); i >= (b); i--)
#define pll(x) cout << (x) << '\n';
const int N = 1e6 + 10;
ll n, m, k;
ll a[N], b[N], f[N], lg[N];
vector<pair<int, pair<int, int>>> e[N];
vector<int> clc[N], v[N];
PLL tr[N];
struct node
{
ll ty, d, ver;
bool operator > (const node& V) const
{
return d > V.d;
}
};
void solve()
{
cin >> n >> m >> k; lg[0] = -1;
rep(i, 1, n) e[i].clear(), f[i] = 0; rep(i, 1, m) clc[i].clear(), v[i].clear();
for(int i = 1, u, v, c, l; i <= m; i++) {cin >> u >> v >> c >> l; e[u].push_back({v, {c, l}}), e[v].push_back({u, {c, l}});}
vector<int> ish; vector<vector<vector<int>>> sua(m + 1);
rep(i, 1, k)
{
cin >> tr[i].x >> tr[i].y; lg[i] = lg[i / 2] + 1;
clc[tr[i].x].push_back(i), v[tr[i].x].push_back(tr[i].y); ish.push_back(tr[i].x);
}
sort(ish.begin(), ish.end()); ish.erase(unique(ish.begin(), ish.end()), ish.end());
for(auto u : ish)
{
int sz = clc[u].size(); sua[u].resize(sz + 1); rep(i, 1, sz) sua[u][i].resize(21);
for(int i = 0; i < sz; i++)
{
sua[u][i + 1][0] = v[u][i];
}
for(int i = 1; i <= lg[k]; i++) for(int j = 1; j + (1 << i) - 1 <= sz; j++)
{
ll v1 = sua[u][j][i - 1], to = j + (1 << (i - 1)), v2 = sua[u][to][i - 1];
sua[u][j][i] = max(v1, v2);
}
}
priority_queue<node, vector<node>, greater<node>> q; q.push({1, 0, 1});
map<PLL, ll> mp;
while(q.size())
{
auto [ty, d, ver] = q.top(); q.pop(); f[ver] = 1;
//cout << ty << ' ' << d << ' ' << ver << '\n';
for(auto to : e[ver])
{
if(to.y.x == tr[ty].x && tr[ty].y - d >= to.y.y)
{
//if(mp[{ty, to.x}] == 0 || mp[{ty, to.x}] < tr[ty].y - d - to.y.y)
//{
// mp[{ty, to.x}] = tr[ty].y - d - to.y.y;
q.push({ty, to.y.y + d, to.x});
//}
}
else
{
int yc = to.y.x, qs;
if(clc[yc].empty() || clc[yc].back() <= ty) continue; int sz = clc[yc].size();
int l = -1, r = sz;
while(l + 1 != r)
{
int mid = l + r >> 1;
if(clc[yc][mid] > ty) r = mid; else l = mid;
}
int x = r;
l = x, r = sz + 1;
while(l + 1 != r)
{
int mid = l + r >> 1;
int len = lg[mid - x];
int vl = sua[yc][x + 1][len], vr = sua[yc][mid - (1 << len) + 1][len];
if(max(vl, vr) >= to.y.y) r = mid; else l = mid;
}
if(r == sz + 1) continue;
//if(mp[{clc[yc][r - 1], to.x}] == 0 || mp[{clc[yc][r - 1], to.x}] < v[yc][r - 1] - to.y.y)
//{
// mp[{clc[yc][r - 1], to.x}] = v[yc][r - 1] - to.y.y;
q.push({clc[yc][r - 1], to.y.y, to.x});
//}
}
}
}
rep(i, 1, n) cout << f[i]; cout << '\n';
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1; cin >> T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 7964kb
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
Time Limit Exceeded
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...