QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533989 | #9228. ICPC Inference | ucup-team3510 | WA | 47ms | 432212kb | C++14 | 4.4kb | 2024-08-26 18:17:04 | 2024-08-26 18:17:04 |
Judging History
answer
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
int n,m,L,l;
vector<int> e[200010];
inline int min1(int x)
{
return e[x][0];
}
inline int max1(int x)
{
return e[x].back()
+(e[x].size()-1)*20;
}
inline int min2(int x)
{
return e[x][0]+e[x][1];
}
inline int max2(int x)
{
return e[x].back()+e[x][e[x].size()-2]
+(e[x].size()-2)*20;
}
struct Block
{
int C,f[500],g[200010];
inline void init()
{
C=sqrt(n);
}
inline void add(int x,int v)
{
f[x/C]+=v,g[x]+=v;
}
inline int query(int x)
{
int ret=0;
for(int i=0;i<x/C;i+=C)
{
ret+=f[i/C];
}
for(int i=x/C*C;i<=x;i++)
{
ret+=g[i];
}
return ret;
}
};
struct Tree
{
int a[4400010];
inline void add(int x,int y)
{
for(;x<=l;a[x]+=y,x+=x&-x);
}
inline int query(int x)
{
int ret=0;
for(;x;ret+=a[x],x&=x-1);
return ret;
}
};
inline long long solve1()
{
static vector<int> E[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].size()<=200)
{
for(int j=0;j<e[i].size();j++)
{
for(int k=0;k<=j;k++)
{
E[e[i][j]+k*20]
.emplace_back(i);
}
}
continue;
}
static int f[20];
memset(f,0,sizeof(f));
for(int j=0,k=0,K=0;j<=
L+(e[i].size()-1)*20;j+=20)
{
while(k<e[i].size()&&e[i][k]<j+20)
{
f[e[i][k++]%20]++;
}
while(K<e[i].size()&&e[i][K]+K*20<j)
{
f[e[i][K++]%20]--;
}
for(int k=0;k<20;k++)
{
if(f[k])
{
E[j+k].emplace_back(i);
}
}
}
}
static vector<int> v[4400010],V;
static int f[4400010],F[200010];
for(int i=1;i<=n;i++)
{
if(e[i].empty())
{
continue;
}
if(e[i].size()==1)
{
v[min1(i)].emplace_back(i);
}
f[max1(i)]++;
V.emplace_back(max1(i));
}
long long ans=0,sum=0;
static Block T;
T.init();
for(int i=l;i;i--)
{
f[i]+=f[i+1];
for(int j=0;j<E[i].size();j++)
{
int t=E[i][j];
sum-=f[F[t]],T.add(f[F[t]],-1);
sum+=f[F[t]=i],T.add(f[F[t]],1);
}
for(int j=0;j<v[i].size();j++)
{
ans+=sum-T.query(f[max1(v[i][j])]);
}
}
return ans;
}
inline long long solve2()
{
static int f[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].empty())
{
continue;
}
f[max1(i)]++;
}
for(int i=l;i;i--)
{
f[i]+=f[i+1];
}
long long sum=0;
static int F[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].size()==1)
{
sum+=f[min1(i)];
F[min1(i)]++;
}
}
for(int i=1;i<=l;i++)
{
F[i]+=F[i-1];
}
long long ans=0;
for(int i=1;i<=n;i++)
{
if(e[i].size()>1)
{
ans+=sum-F[max1(i)];
}
}
return ans;
}
inline long long solve3()
{
static vector<int> E[4400010],v[4400010];
static int f[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].empty())
{
continue;
}
if(e[i].size()>=2)
{
E[max2(i)].emplace_back(i);
}
if(e[i].size()==2)
{
v[min2(i)].emplace_back(i);
}
f[max1(i)]++;
}
for(int i=l;i;i--)
{
f[i]+=f[i+1];
}
long long sum1=0,sum2=0,ans=0;
static Tree T;
for(int i=1;i<=n;i++)
{
if(e[i].size()>=2)
{
sum1+=f[min1(i)];
T.add(min1(i),1);
}
}
for(int i=l;i;i--)
{
for(int j=0;j<E[i].size();j++)
{
sum1-=f[min1(E[i][j])];
T.add(min1(E[i][j]),-1);
sum2+=f[1]-1;
}
for(int j=0;j<v[i].size();j++)
{
ans+=sum1-T.query(max1(v[i][j]))+sum2;
}
}
return ans;
}
inline long long solve4()
{
int cnt1=0,cnt2=0,cnt3=0;
for(int i=1;i<=n;i++)
{
cnt1+=!e[i].empty();
cnt2+=e[i].size()>1;
cnt3+=e[i].size()>2;
}
return (long long)(cnt1-1)*cnt2*cnt3;
}
inline long long solve5()
{
static int f[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].empty())
{
continue;
}
f[max1(i)]++;
}
for(int i=l;i;i--)
{
f[i]+=f[i+1];
}
long long ans=0;
for(int i=1;i<=n;i++)
{
if(e[i].size()==1)
{
ans+=f[min1(i)];
}
}
return ans;
}
inline long long solve6()
{
int cnt1=0,cnt2=0;
for(int i=1;i<=n;i++)
{
cnt1+=!e[i].empty();
cnt2+=e[i].size()>1;
}
return (long long)cnt1*cnt2;
}
inline int solve7()
{
int cnt=0;
for(int i=1;i<=n;i++)
{
cnt+=!e[i].empty();
}
return cnt;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>L;
for(int i=1,x,y;i<=n;i++)
{
cin>>x>>y;
e[x].emplace_back(y);
}
l=n*20+(L<<1),n=m;
cout<<solve1()+solve2()+solve3()+solve4()
-(solve5()+solve6()-solve7()<<1)<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 47ms
memory: 432212kb
input:
4 3 300 1 10 2 25 2 30 3 50
output:
6
result:
wrong answer 1st numbers differ - expected: '3', found: '6'