QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#531055#9228. ICPC Inferenceucup-team3161#RE 274ms55004kbC++173.4kb2024-08-24 18:05:522024-08-24 18:05:53

Judging History

你现在查看的是最新测评结果

  • [2024-08-24 18:05:53]
  • 评测
  • 测评结果:RE
  • 用时:274ms
  • 内存:55004kb
  • [2024-08-24 18:05:52]
  • 提交

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],bc[20],z[N],z1[N],z2[N],o[N],bt[M];ll ans;
vector<int> a[N],b[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) {for(;x<=up;x+=x&-x) ++bt[x];}
int qry(int x) {int res=0;for(;x;x-=x&-x) res+=bt[x];return res;}
int id(int x) {return upper_bound(o+1,o+o[0]+1,x)-o-1;}
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);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;i<=m;++i) if(a[i].size()==1) o[++o[0]]=f1(i,1);
	sort(o+1,o+o[0]+1);o[0]=unique(o+1,o+o[0]+1)-o-1;
	for(int i=1,x,x1,t,t1;i<=m;++i) if(!a[i].empty())
	{
		bool fl=a[i].size()==1;
		if(1ll*a[i].size()*(a[i].size()+1)/2<=o[0])
		{
			for(int j=0;j<a[i].size();++j) for(int k=0;k<=j;++k)
				b[i].eb(a[i][j]+k*20);
		}
		else
		{
			fill(bc,bc+20,0);b[i]=a[i];
			for(int j=1,l=0,r=0;j<=o[0];++j)
			{
				while(r<a[i].size() && a[i][r]<=o[j]) ++bc[a[i][r]%20],++r;
				while(l<a[i].size() && a[i][l]+l*20<o[j]) --bc[a[i][l]%20],++l;
				if(l<r) for(int k=0;k<20;++k) if(bc[(o[j]+k)%20]) {b[i].eb(o[j]+k);break;}
			}
		}
		sort(b[i].begin(),b[i].end());
		for(int j=0;j<b[i].size();++j)
		{
			x=b[i][j];ev[++tp]={-x,id(x)+1,-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<b[i].size())
			{
				x1=b[i][j+1];ev[++tp]={-x1,id(x)+1,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]={-f(i,1),id(f1(i,1)),0};
	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);}
	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: 34648kb

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: 3ms
memory: 34508kb

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: 129ms
memory: 48284kb

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: 182ms
memory: 47548kb

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: 77ms
memory: 43580kb

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: 38ms
memory: 42184kb

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: 274ms
memory: 47776kb

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: 195ms
memory: 53544kb

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: 0ms
memory: 34588kb

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: 187ms
memory: 45332kb

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: 0ms
memory: 34648kb

input:

3 199993 199995
165540 12988
2883 39410
66825 115392

output:

1

result:

ok 1 number(s): "1"

Test #12:

score: 0
Accepted
time: 123ms
memory: 49272kb

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: 273ms
memory: 55004kb

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: 0
Accepted
time: 47ms
memory: 43212kb

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...

output:

30079920

result:

ok 1 number(s): "30079920"

Test #15:

score: 0
Accepted
time: 0ms
memory: 34648kb

input:

24 16 200000
6 1
5 2
9 3
6 3
6 3
1 4
15 12
11 13
15 13
14 13
11 13
14 14
12 22
8 23
16 24
10 42
2 43
4 44
13 199998
13 199998
13 199998
7 199999
7 199999
3 200000

output:

1479

result:

ok 1 number(s): "1479"

Test #16:

score: 0
Accepted
time: 108ms
memory: 51344kb

input:

199998 140790 200000
20382 1
75175 1
1261 1
30469 1
8689 1
134949 1
10677 1
33222 1
42480 1
80518 1
111286 1
125548 1
78740 1
1530 1
98335 1
76194 1
56788 1
113516 1
101478 1
101211 1
112396 1
62315 1
119913 1
70262 1
16488 1
135245 1
24429 1
17435 1
61254 1
98349 1
11844 1
15041 1
11510 1
71156 1
6...

output:

1101885707898743

result:

ok 1 number(s): "1101885707898743"

Test #17:

score: 0
Accepted
time: 130ms
memory: 51396kb

input:

196811 51280 24
17192 1
25079 1
27464 1
39867 1
1832 1
17482 1
4693 1
4819 1
15064 1
39031 1
24107 1
29585 1
6585 1
33020 1
47567 1
13253 1
39048 1
1418 1
25729 1
45804 1
24904 1
14061 1
4574 1
28867 1
48344 1
9938 1
27903 1
16751 1
23071 1
21052 1
36834 1
45839 1
8894 1
8677 1
34756 1
19157 1
40181...

output:

134808013718613

result:

ok 1 number(s): "134808013718613"

Test #18:

score: 0
Accepted
time: 0ms
memory: 34840kb

input:

13 10 200000
10 1
10 3
10 3
1 20
7 21
5 22
9 62
8 63
3 64
4 199979
4 199979
2 200000
2 200000

output:

184

result:

ok 1 number(s): "184"

Test #19:

score: 0
Accepted
time: 0ms
memory: 34704kb

input:

1000 514 100
276 1
169 1
267 1
386 1
305 1
301 1
190 1
392 1
22 2
93 2
3 2
245 2
327 2
317 2
425 2
292 2
252 2
212 2
377 2
255 3
108 3
352 3
399 3
369 3
45 3
282 3
236 3
371 3
434 3
439 3
71 3
231 3
314 3
7 3
434 3
389 4
87 4
57 4
313 4
219 4
381 4
222 5
492 5
194 5
148 5
186 5
21 5
185 5
170 6
394 ...

output:

102673572

result:

ok 1 number(s): "102673572"

Test #20:

score: -100
Runtime Error

input:

200000 114052 200000
95 1
55490 2
61481 2
29754 3
104570 5
97903 6
89479 11
88722 13
54292 13
5540 16
31838 17
48936 19
112373 20
48291 20
90401 22
42152 23
30304 26
8433 28
66247 28
49887 32
80338 33
57507 39
65209 42
37033 45
9055 45
93908 49
11908 50
48143 51
108424 51
107522 55
106177 56
51263 5...

output:


result: