QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605348 | #8038. Hammer to Fall | yangrun | WA | 3ms | 12476kb | C++14 | 2.4kb | 2024-10-02 16:46:47 | 2024-10-02 16:46:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define mod 998244353
int qread() {
int res = 0, flg = 1;
char c = getchar();
while(!isdigit(c)) {
if(c == '-') flg = 0;
c = getchar();
}
while(isdigit(c)) {
res = (res << 3) + (res << 1) + (c ^ 48);
c = getchar();
}
return flg ? res : -res;
}
const int N = 1e5 + 10;
int du[N];
struct cmp{
bool operator()(pii a, pii b) {
if(a.fi != b.fi) {
return a.se > b.se;
} else {
return a.se < b.se;
}
}
};
vector<pii> vec[N];
priority_queue<pii, vector<pii>, cmp> prq[N];
map<pii, int> ma;
int n, m, q, lim;
int a[N];
int ord[N], waste[N];
void update(int u) {
int to, w;
for(int i = 0; i < vec[u].size(); ++i) {
to = vec[u][i].fi, w = vec[u][i].se;
if(du[to] < lim) break;
prq[to].push({u, w + waste[u]});
}
}
pii find(int u) {
if(du[u] < lim) {
int to, w;
int rt, rw = 0x3f3f3f3f3f3f3f3f;
for(int i = 0; i < vec[u].size(); ++i) {
to = vec[u][i].fi, w = vec[u][i].se;
if(w + waste[to] < rw) {
rt = to, rw = w;
}
}
return {rt, rw};
}
return prq[u].top();
}
pii op[N];
signed main() {
n = qread(), m = qread(), q = qread();
lim = (int)sqrt(1e5 + 10);
int u, v, w;
for(int i = 1; i <= n; i++) a[i] = qread();
for(int i = 1; i <= m; i++) {
u = qread(), v = qread(), w = qread();
ma[{u, v}] = ma[{v, u}] = w;
du[u]++; du[v]++;
vec[u].push_back({v, w});
vec[v].push_back({u, w});
}
for(int i = 1; i <= n; i++) {
//cout << du[vec[i][0].fi];
sort(vec[i].begin(), vec[i].end(), [](pii a, pii b)->bool{
return du[a.fi] > du[b.fi];
});
//cout << ' ' << du[vec[i][0].fi] << '\n';
update(i);
}
for(int i = 1; i <= q; ++i) ord[i] = qread();
pii nxt;
for(int i = q; i; --i) {
nxt = find(ord[i]);
waste[ord[i]] = nxt.se;
op[i] = {ord[i], nxt.fi};
update(ord[u]);
}
int res = 0;
for(int i = 1; i <= q; i++) {
//cout << op[i].fi << ' ' << op[i].se << '\n';
res += ma[op[i]] * (a[op[i].fi] % 998244353) % 998244353;
res %= 998244353;
a[op[i].se] += a[op[i].fi];
a[op[i].fi] = 0;
}
cout << res << '\n';
return 0;
}
/*
3 2 2
1 1 1
2 3 10
1 2 1
3 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11776kb
input:
3 2 2 1 1 1 2 3 10 1 2 1 3 2
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 11720kb
input:
2 1 10 5000 5000 1 2 10000 1 2 2 1 2 2 1 1 1 2
output:
550000000
result:
ok single line: '550000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12256kb
input:
10 10 10 5 14 99 14 18 4 58 39 48 60 2 4 4 6 9 56 10 8 34 7 5 96 1 3 26 3 7 92 6 8 4 5 1 72 7 6 39 7 2 93 8 8 9 10 2 2 5 9 2 3
output:
8810
result:
ok single line: '8810'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 12476kb
input:
100 500 10000 89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...
output:
1975964
result:
wrong answer 1st lines differ - expected: '609241', found: '1975964'