QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605344#8038. Hammer to FallyangrunWA 0ms12788kbC++142.4kb2024-10-02 16:45:572024-10-02 16:46:01

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 16:46:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12788kb
  • [2024-10-02 16:45:57]
  • 提交

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 <= n; 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: 0ms
memory: 12788kb

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: -100
Wrong Answer
time: 0ms
memory: 11072kb

input:

2 1 10
5000 5000
1 2 10000
1 2 2 1 2 2 1 1 1 2

output:

150000000

result:

wrong answer 1st lines differ - expected: '550000000', found: '150000000'