QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533977 | #9228. ICPC Inference | ucup-team3510 | TL | 2273ms | 712596kb | C++14 | 4.1kb | 2024-08-26 18:03:41 | 2024-08-26 18:03:41 |
Judging History
answer
#include<iostream>
#include<vector>
#include<cstring>
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 Tree
{
int a[4400010];
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[4400010];
for(int i=1;i<=n;i++)
{
if(e[i].size()<=300)
{
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 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[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: 100
Accepted
time: 52ms
memory: 430488kb
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: 73ms
memory: 434192kb
input:
4 6 200000 6 1 6 1 1 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 158ms
memory: 517332kb
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:
274533940012863
result:
ok 1 number(s): "274533940012863"
Test #4:
score: 0
Accepted
time: 152ms
memory: 512276kb
input:
192309 96431 357 56446 1 42487 1 47313 1 71736 1 74439 1 19895 1 52024 1 66203 1 992 1 78744 1 9911 1 85130 1 73814 1 64499 1 92961 1 66255 1 88807 1 82217 1 36788 1 66999 1 35107 1 47933 1 34196 1 50534 1 83014 1 75035 1 30407 1 36014 1 7248 1 69915 1 57348 1 5356 1 37088 1 36455 1 29365 1 71376 1 ...
output:
868523468626161
result:
ok 1 number(s): "868523468626161"
Test #5:
score: 0
Accepted
time: 2273ms
memory: 712596kb
input:
200000 200000 200000 151464 4 1477 6 95966 8 121582 8 19239 11 668 13 109329 15 173254 15 153807 16 75865 16 123829 17 101156 17 8881 18 116717 18 124985 18 125918 18 132143 19 35899 20 90547 20 106065 22 176481 23 11727 23 527 24 77206 25 85757 25 169873 26 139187 26 5970 28 37134 29 199855 30 9598...
output:
149096043
result:
ok 1 number(s): "149096043"
Test #6:
score: 0
Accepted
time: 116ms
memory: 538868kb
input:
200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000...
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 222ms
memory: 536068kb
input:
200000 200000 200000 80855 2 16643 3 158423 4 160007 6 83405 9 148393 10 94889 10 146919 11 56648 12 60318 12 182241 13 144187 14 96195 16 72396 16 10048 17 32575 19 75743 21 49152 21 21380 22 64386 28 11608 29 49440 30 125557 35 170781 36 5487 37 104466 37 136650 37 84688 38 38173 40 122020 40 9383...
output:
689247584152428
result:
ok 1 number(s): "689247584152428"
Test #8:
score: 0
Accepted
time: 1174ms
memory: 638108kb
input:
200000 28000 200000 5152 1 5152 1 26010 1 12173 1 12173 1 12166 1 26010 1 24704 1 12173 1 24704 1 26010 1 12071 1 12173 1 12173 1 12166 1 26010 1 24704 1 12166 1 6044 1 24704 1 6044 1 12173 1 24704 1 6733 1 12173 1 12166 1 12173 1 12166 1 24704 1 12166 1 24704 1 12166 1 5152 1 12166 1 12166 1 26010 ...
output:
13273777158527
result:
ok 1 number(s): "13273777158527"
Test #9:
score: 0
Accepted
time: 55ms
memory: 438616kb
input:
4 6 200000 6 1 6 1 1 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #10:
score: 0
Accepted
time: 342ms
memory: 605524kb
input:
199999 200000 199995 22477 1 124061 1 102846 2 124061 2 124061 3 124061 3 124061 4 124061 5 59212 5 169893 5 124061 6 80004 6 112429 7 31273 11 124061 12 67631 12 124061 14 10017 15 124061 16 70773 16 124061 17 168853 18 88973 19 124061 19 61672 19 196994 20 48373 21 113531 22 92390 23 152850 25 998...
output:
150416508568041
result:
ok 1 number(s): "150416508568041"
Test #11:
score: 0
Accepted
time: 67ms
memory: 433780kb
input:
3 199993 199995 165540 12988 2883 39410 66825 115392
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 139ms
memory: 520708kb
input:
193973 65702 62 51610 1 53512 1 12563 1 56075 1 29395 1 42082 1 60371 1 17038 1 29443 1 33664 1 12471 1 34225 1 49958 1 54960 1 59860 1 33819 1 7499 1 34862 1 6704 1 52200 1 22803 1 7726 1 61422 1 51120 1 17203 1 11462 1 13292 1 20641 1 21050 1 28979 1 35347 1 55821 1 52326 1 50557 1 8296 1 53862 1 ...
output:
283586156841885
result:
ok 1 number(s): "283586156841885"
Test #13:
score: 0
Accepted
time: 187ms
memory: 528128kb
input:
199975 199975 100000 27676 1 116023 2 40052 2 154967 2 82099 3 2503 4 159303 5 136744 5 89330 6 117095 6 182013 6 131786 7 180992 7 73734 7 122549 8 16427 8 104713 8 46057 9 63743 9 160535 10 109106 11 135371 12 65002 13 194754 14 15088 15 144270 15 106306 15 84597 16 143308 16 67042 16 103147 17 15...
output:
1332840068163275
result:
ok 1 number(s): "1332840068163275"
Test #14:
score: -100
Time Limit Exceeded
input:
200000 312 200000 155 1 241 1 93 1 157 1 308 1 7 1 148 1 240 1 172 1 77 1 151 1 141 1 150 1 190 1 226 1 265 1 247 1 171 1 251 1 115 1 164 1 185 1 234 1 176 1 63 1 21 1 107 1 132 1 224 1 293 1 80 1 162 1 113 1 243 1 287 1 104 1 298 1 197 1 270 1 6 1 252 1 289 1 2 1 160 1 229 1 116 1 165 1 216 1 159 1...