QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790353#9349. Exchanging GiftsPandaGhostWA 61ms3948kbC++171.6kb2024-11-28 11:01:412024-11-28 11:01:42

Judging History

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

  • [2024-11-28 11:01:42]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:3948kb
  • [2024-11-28 11:01:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPFI(x) freopen(#x".in", "r", stdin);\
                freopen(#x".out", "w", stdout)
#define REP(i, a, b) for(int i=(a); i<=(b); ++i)
#define REPd(i, a, b) for(int i=(a); i>=(b); --i)
inline ll rd(){
    ll r=0, k=1; char c; while(!isdigit(c=getchar())) if(c=='-') k=-k;
    while(isdigit(c)) r=r*10+c-'0', c=getchar(); return r*k;
}
const int N=1e6+10;
ll t, n;
struct seq{
    ll len, minval, minnum, maxval, maxnum;
}s[N];

seq merge(seq x, seq y){
    seq res;
    res.len=x.len+y.len;
    if(x.minval<y.minval) res.minval=x.minval, res.minnum=x.minnum;
    else if(x.minval==y.minval) res.minval=x.minval, res.minnum=x.minnum+y.minnum;
    else res.minval=y.minval, res.minnum=y.minnum;
    if(x.maxval>y.maxval) res.maxval=x.maxval, res.maxnum=x.maxnum;
    else if(x.maxval==y.maxval) res.maxval=x.maxval, res.maxnum=x.maxnum+y.maxnum;
    else res.maxval=y.maxval, res.maxnum=y.maxnum;
    return res;
}

int main(){
    t=rd();
    while(t--){
        n=rd();
        REP(i, 1, n){
            int op=rd();
            if(op==1){
                s[i]=(seq){0, LLONG_MAX/2, 0, LLONG_MIN/2, 0};
                int k=rd();
                REP(j, 1, k){
                    ll tmp=rd();
                    s[i]=merge(s[i], (seq){1, tmp, 1, tmp, 1});
                }
            }else{
                int x=rd(), y=rd();
                s[i]=merge(s[x], s[y]);
            }
        }
        ll len=s[n].len, mxnum=max(s[n].minnum, s[n].maxnum);
        ll ans=min(len, 2*(len-mxnum));
        printf("%lld\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3764kb

input:

2
1
1 5 3 3 2 1 3
3
1 3 3 3 2
1 4 2 2 3 3
2 1 2

output:

4
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 61ms
memory: 3948kb

input:

10000
100
1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...

output:

700
68
332
284
131
1048
194
667
704
0
484
252
35
351
1228
238
1025
354
383
571
4272
340
1044
199
448
190
0
69
841
546
247
883
138
1633
91
3308
2556
1280
488
618
407
381
383
2865
0
496
1202
53
0
415
662
380
41
18
91
505
818
603
241
764
1227
1802
176
187
817
1489
460
296
238
236
1028
0
606
1696
746
10...

result:

wrong answer 214th lines differ - expected: '40', found: '53'