QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599655#5144. Set of Intervalslouhao088WA 1ms5844kbC++232.5kb2024-09-29 08:24:122024-09-29 08:24:13

Judging History

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

  • [2024-09-29 08:24:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5844kb
  • [2024-09-29 08:24:12]
  • 提交

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 {
        for (int i = 1; i <= n; i++) {
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 2) & 1)) {
                ans =max(ans,work(l1, r1, l2, r2)); 
                //break;
            }
            if (((zt[i] >> 0) & 1) && ((zt[i] >> 3) & 1)) {
                ans =max(ans,work(l1, r2, l2, r1)) ;
                //break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 2) & 1)) {
                ans =max(ans, work(l2, r1, l1, r2));
                //break;
            }
            if (((zt[i] >> 1) & 1) && ((zt[i] >> 3) & 1)) {
                ans =max(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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5844kb

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
0
0

result:

wrong answer 3rd numbers differ - expected: '26', found: '0'