QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#530742 | #9228. ICPC Inference | ucup-team3161# | WA | 74ms | 36044kb | C++17 | 2.8kb | 2024-08-24 17:06:16 | 2024-08-24 17:06:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define eb emplace_back
const int N=2e5+5,up=5e6,M=up+5;
int n,m,c,tp,cnt[4],z[N],z1[N],z2[N],bt[M];ll ans;
vector<int> a[N];tuple<int,int,int> ev[M];
int f(int x,int y)
{
int t=a[x].size(),s=0;for(int i=1;i<=y;++i) s+=a[x][t-i];
s+=(a[x].size()-y)*20;return s;
}
int f1(int x,int y) {int s=0;for(int i=0;i<y;++i) s+=a[x][i];return s;}
void upd(int x,int w) {for(;x<=up;x+=x&-x) bt[x]+=w;}
int qry(int x) {int res=0;for(;x;x-=x&-x) res+=bt[x];return res;}
int main()
{
scanf("%d %d %d",&n,&m,&c);
for(int i=1,x,y;i<=n;++i) scanf("%d %d",&x,&y),a[x].eb(y);
for(int i=1;i<=m;++i) sort(a[i].begin(),a[i].end());
for(int i=1;i<=m;++i) ++cnt[min<int>(a[i].size(),3)];
ans=1ll*cnt[3]*(cnt[2]+cnt[3]-1)*(cnt[1]+cnt[2]+cnt[3]-2);
for(int i=1;i<=m;++i) if(!a[i].empty())
{if(a[i].size()==1) z[++z[0]]=f(i,1);else z1[++z1[0]]=f(i,1);}
sort(z+1,z+z[0]+1);sort(z1+1,z1+z1[0]+1);
for(int i=1,t,t1;i<=m;++i) if(a[i].size()==1)
{
t=lower_bound(z+1,z+z[0]+1,f1(i,1))-z;
t1=lower_bound(z1+1,z1+z1[0]+1,f1(i,1))-z1;
ans+=1ll*(z[0]-t)*(cnt[2]+cnt[3])+1ll*(z1[0]-t1+1)*(cnt[2]+cnt[3]-1);
}
z[0]=z1[0]=z2[0]=0;
for(int i=1;i<=m;++i) if(!a[i].empty())
{if(a[i].size()==2) z[++z[0]]=f(i,1),z2[++z2[0]]=f1(i,2);else z1[++z1[0]]=f(i,1);}
sort(z+1,z+z[0]+1);sort(z1+1,z1+z1[0]+1);sort(z2+1,z2+z2[0]+1);
for(int i=1,t,t1,t2;i<=m;++i) if(a[i].size()>1)
{
bool fl=a[i].size()==2;
t=lower_bound(z+1,z+z[0]+1,f1(i,1))-z;
t1=lower_bound(z1+1,z1+z1[0]+1,f1(i,1))-z1;
t2=upper_bound(z2+1,z2+z2[0]+1,f(i,2))-z2-1;
ans+=1ll*(z[0]-t-fl+1)*(cnt[2]-fl-1)+1ll*(z1[0]-t1+fl)*(cnt[2]-fl);
ans+=1ll*(t+t1-2)*(t2-fl);
}
for(int i=1;i<=m;++i) if(a[i].size()>1) ev[++tp]={f(i,2),f1(i,1),0};
for(int i=1;i<=m;++i) if(a[i].size()==2) ev[++tp]={f1(i,2),f(i,1),1};
sort(ev+1,ev+tp+1);
for(int i=1;i<=tp;++i)
{auto [x,y,op]=ev[i];if(op) upd(y,1);else ans-=qry(y-1);}
z[0]=z1[0]=z2[0]=0;
for(int i=1;i<=m;++i) if(!a[i].empty())
{z[++z[0]]=f(i,1);if(a[i].size()==1) z1[++z1[0]]=f1(i,1);}
sort(z+1,z+z[0]+1);sort(z1+1,z1+z1[0]+1);
fill(bt,bt+up+1,0);tp=0;
for(int i=1,x,x1,t,t1;i<=m;++i) if(!a[i].empty())
{
bool fl=a[i].size()==1;
for(int j=0;j<a[i].size();++j)
{
x=a[i][j]+j*20;ev[++tp]={x,x,-1};
t=lower_bound(z+1,z+z[0]+1,x)-z;
t1=upper_bound(z1+1,z1+z1[0]+1,x)-z1-1;ans+=1ll*(z[0]-t)*(t1-fl);
if(j+1<a[i].size())
{
x1=a[i][j+1]+(j+1)*20;ev[++tp]={x,x1,1};
t=lower_bound(z+1,z+z[0]+1,x1)-z;ans-=1ll*(z[0]-t)*(t1-fl);
}
}
}
for(int i=1;i<=m;++i) if(a[i].size()==1) ev[++tp]={f1(i,1),f(i,1),0};
for(int i=1;i<=tp;++i) {auto &[x,y,op]=ev[i];y=up-y;if(op) ++y;}
sort(ev+1,ev+tp+1);
for(int i=1;i<=tp;++i)
{auto [x,y,op]=ev[i];if(op) ans+=qry(y-1)*op;else upd(y,1);}
ans+=cnt[1];printf("%lld\n",ans);return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 30588kb
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: 0ms
memory: 28884kb
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: 74ms
memory: 36044kb
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'