QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#531505 | #9228. ICPC Inference | ucup-team3510# | WA | 174ms | 710312kb | C++14 | 3.6kb | 2024-08-24 20:58:16 | 2024-08-24 20:58:17 |
Judging History
answer
#include<iostream>
#include<vector>
using namespace std;
int n,m,l;
vector<int> e[5000010];
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 Tree
{
int a[5000010];
inline void add(int x,int y)
{
for(x=x?x:1e9;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[5000010];
for(int i=1;i<=n;i++)
{
for(int j=0;j<e[i].size();j++)
{
E[e[i][j]+j*20].emplace_back(i);
}
}
static vector<int> v[5000010];
static int f[5000010],F[5000010];
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)]++;
}
long long ans=0,sum=0;
static Tree T;
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[t],-1);
sum+=f[F[t]=i],T.add(F[t],1);
}
for(int j=0;j<v[i].size();j++)
{
ans+=sum-T.query(max1(v[i][j]));
}
}
return ans;
}
inline long long solve2()
{
static int f[5000010];
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[5000010];
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[5000010],v[5000010];
static int f[5000010];
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[5000010];
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=5e6,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: 100
Accepted
time: 112ms
memory: 708904kb
input:
4 3 300 1 10 2 25 2 30 3 50
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 120ms
memory: 708916kb
input:
4 6 200000 6 1 6 1 1 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: -100
Wrong Answer
time: 174ms
memory: 710312kb
input:
191580 64997 56 24878 1 35060 1 24245 1 64330 1 9650 1 15423 1 34953 1 21456 1 36718 1 21395 1 17613 1 16995 1 45257 1 31277 1 20026 1 1870 1 25581 1 9997 1 54701 1 30752 1 32269 1 705 1 64186 1 58881 1 24614 1 55311 1 18259 1 58886 1 23296 1 17628 1 3411 1 37469 1 47951 1 12188 1 60720 1 54168 1 45...
output:
274503575264041
result:
wrong answer 1st numbers differ - expected: '274533940012863', found: '274503575264041'