QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#597197#5144. Set of Intervalslouhao088#WA 6ms5976kbC++232.3kb2024-09-28 17:16:302024-09-28 17:16:30

Judging History

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

  • [2024-09-28 17:16:30]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:5976kb
  • [2024-09-28 17:16:30]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 100;
int n, L[N], R[N];
int ls[N], rs[N];
int zt[N], f[105];

bool cmp(int x, int y) {
    return x > y;
}

int work(int l1, int r1, int l2, int r2) {
    if(l1>l2)swap(l1,l2),swap(r1,r2);
    int res=0;
    res=res+(l2-l1)*(r2-l2+1);
    if(r2<r1)r1=r2;
    else res=res+(r2-r1)*(r1-l2+1);
    //cout<<res<<" "<<r1<<" "<<l2<<endl;
    if(r1<=l2)return res;
    res=res+(r1-l2)*(r1-l2+1)/2;
    return res;
}
int ans;
void slove() {
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &L[i], &R[i]);
        ls[i] = L[i]; rs[i] = R[i];
    }
    if(n==1){
        puts("1");return;
    }
    sort(ls + 1, ls + n + 1);
    sort(rs + 1, rs + n + 1, cmp);
    int l1 = ls[1], l2 = ls[2], r1 = rs[1], r2 = rs[2];
    for (int i = 1; i <= n; i++) {
        zt[i] = 0;
        if (l1 == L[i]) zt[i] |= 1;
        if (l2 == L[i]) zt[i] |= 2;
        if (r1 == R[i]) zt[i] |= 4;
        if (r2 == R[i]) zt[i] |= 8;
    }

    for (int i = 0; i < 50; i++) f[i] = 0;
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 15; j >= 0; j--)
            for (int k = 0; k < 4; k++)
                if (!((j >> k) & 1) && ((zt[i] >> k) & 1))
                    f[j | (1 << k)] = 1;
    }
    if (f[15]) {
        ans =  work(l1, r2, l2, r1) ;
        //cout<<work(l1,r1,l2,r2)<<" "<<work(l1, r2, l2, r1) <<" "<< work(l2, r2, l2, r2)<<endl;;
    }
    else {
        for (int i = 1; i <= n; i++) {
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 2) & 1)) {
                ans = work(l1, r1, l2, r2);
                break;
            }
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 3) & 1)) {
                ans = work(l1, r2, l2, r1);
                break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 2) & 1)) {
                ans = work(l2, r1, l1, r2);
                break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 3) & 1)) {
                ans = work(l2, r2, l1, r1);
                break;
            }
        }
    }
    printf("%lld\n", ans);
}

signed main() {
   // cout<<work(1,4,2,5)<<endl;
   // return 0;
    int t; scanf("%lld", &t);
    
    while (t--) slove();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1
1 1000000000
2
1 1000000000
1 1000000000
4
1 2
3 4
5 6
7 8
4
1 3
2 4
5 8
6 7

output:

1
499999999500000000
26
28

result:

ok 4 number(s): "1 499999999500000000 26 28"

Test #2:

score: 0
Accepted
time: 2ms
memory: 5796kb

input:

10000
1
778216842 910688403
1
513404058 890988011
1
1 1000000000
1
1 1000000000
1
758932694 848837772
1
516433381 715411928
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
652548522 898071173
1
1 1000000000
1
509357508 603420032
1
1 1000000000
1
657294869 887475066
1
1 1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 10000 numbers

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 3852kb

input:

10000
2
427286995 863604876
582970459 874563920
2
181948005 565025282
799528580 848659925
2
1 1000000000
716032287 836380611
2
383809946 544540272
520881396 990456979
2
156308569 178412791
731100211 963724967
2
426113388 802990296
556666621 560014605
2
1 1000000000
575838571 811122140
2
255734272 64...

output:

87849603321470913
-36170694013714021
230263230414266279
75195165925255965
-300321393616832750
32977435735183263
316367547533445965
56483863859672889
33048546281604648
36132096841419954
57797703310407226
307857554310722843
261703336965133219
-189539097952091163
63833225117266922
49431021159048792
-28...

result:

wrong answer 2nd numbers differ - expected: '18821102290156188', found: '-36170694013714021'