QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454085 | #8528. Chords | ucup-team1525# | RE | 2266ms | 5956kb | C++20 | 1.8kb | 2024-06-24 16:26:34 | 2024-06-24 16:26:34 |
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<=30;++i)
{
g[i]=rnd()%(n/3)+1;
int q=min(n-g[i]+1,15);
h[i]=g[i]+rnd()%q;
// 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=30;i;--i)
{
swap(a[g[i]],a[h[i]]);
}
}
int main()
{
clock_t bg=clock();
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;
while (clock()-bg<=2.9*CLOCKS_PER_SEC)
// 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: 2266ms
memory: 5940kb
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: 1ms
memory: 5956kb
input:
1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -100
Runtime Error
input:
2 1 3 2 4