QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454189 | #8528. Chords | ucup-team1525# | WA | 1402ms | 8120kb | C++20 | 3.0kb | 2024-06-24 17:23:54 | 2024-06-24 17:23:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
mt19937_64 rnd(time(0));
#define ull unsigned long long
struct dt
{
int l,r,len;
ull v;
bool operator<(const dt &a)const
{
return (len==a.len?l<a.l:len<a.len);
}
}a[N];
ull f[N*2];
int n;
inline void ins(int x,ull 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(int mx)
{
for (int i=1;i<=100;++i)
{
g[i]=rnd()%mx+1;
int q=min(n-g[i]+1,max(mx/2,20));
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=100;i;--i)
{
swap(a[g[i]],a[h[i]]);
}
}
map<ull,int> mp;
int in[N];
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();
while(mp[a[i].v])
a[i].v=rnd();
mp[a[i].v]=i;
// 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 i=1;i<=n;++i)
if (ask(a[i].l-1)==ask(a[i].r))
{
++ans;
in[i]=1;
ins(a[i].l,a[i].v);
ins(a[i].r,a[i].v);
}
while (clock()-bg<=2.9*CLOCKS_PER_SEC)
{
int x=rnd()%n+1;
if (!in[x])
{
int o=ask(a[x].l-1)^ask(a[x].r);
if (o==0)
{
++ans;
}
else
{
int tmp=mp[o];
if (tmp)
{
in[tmp]=0;
ins(a[tmp].l,a[tmp].v);
ins(a[tmp].r,a[tmp].v);
}
else
continue;
}
in[x]=1;
ins(a[x].l,a[x].v);
ins(a[x].r,a[x].v);
}
}
// int mx=max(1,n/4);
// 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();
// mx+=n/40;
// mx=min(n,mx);
// }
// }
// if (n==1)
// break;
// raodong(mx);
// 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: 1206ms
memory: 5948kb
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: 1090ms
memory: 5940kb
input:
1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1222ms
memory: 6084kb
input:
2 1 3 2 4
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1002ms
memory: 6016kb
input:
2 1 4 2 3
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1286ms
memory: 8120kb
input:
3 3 5 1 4 2 6
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 1402ms
memory: 8072kb
input:
4 2 7 1 6 3 8 4 5
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 1174ms
memory: 5896kb
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: 1350ms
memory: 6016kb
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: 1230ms
memory: 5936kb
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'