QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454078#8528. Chordsucup-team1525#WA 1ms5988kbC++201.6kb2024-06-24 16:21:032024-06-24 16:21:03

Judging History

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

  • [2024-06-24 16:21:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5988kb
  • [2024-06-24 16:21:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
mt19937 rnd(time(0));
struct dt
{
    int l,r,len,v;
    bool operator<(const dt &a)const
    {
        return (len==a.len?l<a.l:len<a.len);
    }
}a[N];
int f[N*2];
int n;
inline void ins(int x,int y)
{
    for (;x<=n*2;x+=x&(-x))
        f[x]^=y;
}
inline int ask(int x)
{
    int ans=0;
    for (;x;x-=x&(-x))
        ans^=f[x];
    return ans;
}
int g[N],h[N];
void raodong()
{
    for (int i=1;i<=n/20;++i)
    {
        g[i]=rnd()%n+1;
        h[i]=rnd()%n+1;
        while (g[i]==h[i])
        {
            h[i]=rnd()%n+1;
        }
        swap(a[g[i]],a[h[i]]);
    }
}
void roll_back()
{
    for (int i=n/20;i;--i)
    {
        swap(a[g[i]],a[h[i]]);
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d%d",&a[i].l,&a[i].r);
        a[i].len=a[i].r-a[i].l;
        a[i].len=min(a[i].len,n*2-a[i].len);
        a[i].v=rnd();
        // a[i+n]={a[i].r,a[i].l,n*2-a[i].len};
    }
    sort(a+1,a+1+n);
    int ans=0;
    for (int t=1;t<=100;++t)
    {
        int sum=0;
        for (int i=1;i<=n;++i)
            if (ask(a[i].l-1)==ask(a[i].r))
            {
                ++sum;
                ins(a[i].l,a[i].v);
                ins(a[i].r,a[i].v);
            }
        if (sum>ans)
        {
            ans=sum;
        }
        else
        {
            if (sum<ans)
                roll_back();
        }
        if (n==1)
            break;
        raodong();
        for (int i=1;i<=2*n;++i)
            f[i]=0;
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2
4 10
7 9
3 5
6 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

2
1 3
2 4

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

2
1 4
2 3

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5932kb

input:

3
3 5
1 4
2 6

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5968kb

input:

4
2 7
1 6
3 8
4 5

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

6
8 9
6 7
4 10
1 5
11 12
2 3

output:

5

result:

ok 1 number(s): "5"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

9
2 8
10 17
9 15
1 12
6 14
3 13
4 11
5 7
16 18

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 5988kb

input:

13
8 16
2 13
14 23
10 11
7 17
6 24
12 18
9 20
4 15
19 21
3 26
1 25
5 22

output:

5

result:

wrong answer 1st numbers differ - expected: '6', found: '5'