QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454077 | #8528. Chords | ucup-team1525# | WA | 1ms | 5876kb | C++20 | 1.6kb | 2024-06-24 16:20:27 | 2024-06-24 16:20:28 |
Judging History
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 (n==1)
break;
if (sum>ans)
{
ans=sum;
}
else
{
if (sum<ans)
roll_back();
}
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: 3920kb
input:
5 1 2 4 10 7 9 3 5 6 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5876kb
input:
1 1 2
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'