QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605380#8038. Hammer to FallyangrunWA 2534ms738360kbC++142.4kb2024-10-02 16:55:432024-10-02 16:55:46

Judging History

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

  • [2024-10-02 16:55:46]
  • 评测
  • 测评结果:WA
  • 用时:2534ms
  • 内存:738360kb
  • [2024-10-02 16:55:43]
  • 提交

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 + waste[to];
      }
    }
    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[i]);
  }
  
  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: 12256kb

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: 2ms
memory: 11916kb

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: 2ms
memory: 11832kb

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: 0
Accepted
time: 0ms
memory: 12828kb

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:

609241

result:

ok single line: '609241'

Test #5:

score: 0
Accepted
time: 169ms
memory: 32072kb

input:

100000 100000 100000
134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...

output:

641103242

result:

ok single line: '641103242'

Test #6:

score: -100
Wrong Answer
time: 2534ms
memory: 738360kb

input:

448 100000 100000
411038009 847809848 901622409 143987890 230747977 330204397 58948994 635255827 124637955 446506876 693363517 282765360 687916399 598850473 404480258 958197468 332242997 7338874 321860348 37384562 440321061 434694843 935461053 803393359 852456369 428568442 233194935 663299156 907095...

output:

741520592

result:

wrong answer 1st lines differ - expected: '571525504', found: '741520592'