QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599658#5144. Set of Intervalslouhao088WA 9ms5936kbC++232.6kb2024-09-29 08:25:202024-09-29 08:25:24

Judging History

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

  • [2024-09-29 08:25:24]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5936kb
  • [2024-09-29 08:25:20]
  • 提交

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);
	if(r1<l2)return (r1-l1+1)*(r2-l2+1);
    int res=0;
    res=res+(l2-l1)*(r2-l2+1);
	//cout<<res<<" "<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<endl;
    if(r2<r1){
        res=res+(r1-r2)*(r2-l2+1);
        r1=r2;
    }
    else res=res+(r2-r1)*(r1-l2+1);
    res=res+(r1-l2)*(r1-l2+1)/2;
    return res;
}
int ans;
void slove() {
	//cout<<work(1,3,3,4)<<endl;;
    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;
    }
    ans=0;
   // if (f[15]) {
		//cout<<"A";
        //ans =  work(l1, r2, l2, r1) ;
        //cout<<work(l1,r1,l2,r2)<<" "<<work(l1, r2, l2, r1) <<" "<< work(l2, r2, l2, r2)<<endl;;
   // }
  //  else {
	int F=0;
        for (int i = 1; i <= n; i++) {
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 2) & 1)) {
                ans =max(ans,work(l1, r1, l2, r2)); 
				F=1;
                //break;
            }
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 3) & 1)) {
                ans =max(ans,work(l1, r2, l2, r1)) ;
				F=1;
                //break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 2) & 1)) {
                ans =max(ans, work(l2, r1, l1, r2));
				F=1;
                //break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 3) & 1)) {
                ans =max(ans, work(l2, r2, l1, r1));
				F=1;
                //break;
            }
        }
  //  }
	if(!F)ans=work(l1,r2,l2,r1);
    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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5936kb

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: 5704kb

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

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
18821102290156188
113106465274673025
75195165925255965
5141989504048811
1256173734724260
207604390726385765
56483863859672889
37024984393194673
36132096841419954
22573394495301601
143688903920213372
166852999281224709
3932968549941246
63833225117266922
49459548807361176
70057738855...

result:

ok 10000 numbers

Test #4:

score: -100
Wrong Answer
time: 9ms
memory: 5852kb

input:

10000
3
1 1000000000
521067549 666980062
562319713 714009993
3
42407212 75107815
610219669 973789020
873806856 902158965
3
1 1000000000
673648508 809445815
599994567 757240668
3
92939611 410549965
597447135 678622426
676819188 811525072
3
230740729 455081734
606008912 926990742
615223886 822068791
3...

output:

174329051362239765
269965111370246655
187516336041444375
55036670648574626
166464628402586213
303666532800970347
176358932288144970
330593156050995465
3494098810090614
247444999637419584
38966336613806420
199454344726240709
138012413848667709
274043263510447662
200274422590053105
93863234313709315
7...

result:

wrong answer 4th numbers differ - expected: '122087055515083130', found: '55036670648574626'