QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#260399#5425. Proposition Compositiongrass8cowTL 1797ms25524kbC++144.4kb2023-11-22 07:35:282023-11-22 07:35:28

Judging History

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

  • [2023-11-22 07:35:28]
  • 评测
  • 测评结果:TL
  • 用时:1797ms
  • 内存:25524kb
  • [2023-11-22 07:35:28]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,U[301000],V[300100];ll ans[301000];
int fa[300100],sg[300100];
	int F(int x){if(x==fa[x])return x;return fa[x]=F(fa[x]);}
	void sol__(){
		for(int i=1;i<=n;i++)fa[i]=i;for(int i=1;i<n;i++)sg[i]=0;
		int c0=n-1,c1=0;
		for(int i=1;i<=m;i++){
			if(U[i]>V[i])swap(U[i],V[i]);
			int l=F(U[i]),r=F(V[i]);
			while(l!=r){
				if(sg[l]==0)c0--,c1++;else c1--;
				sg[l]++,l=F(l+1);
			}
			l=F(U[i]);
			while(l!=r){int fp=F(l+1);if(sg[l]==2)fa[l]=fp;l=fp;}
			ans[i]=1ll*c0*i+c1+1ll*c0*(n-1-c0);
		}
	}
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int col[301000],pre[301000],nxt[301000],sz[1200100],sc;
	int k1[1201000],k2[1200100];
	ll ns;
	int hg[301000];
	void build(int p,int l,int r){
		if(l==r){hg[l]=p,k1[p]=k2[p]=l;return;}
		int mid=(l+r)>>1;build(p<<1,l,mid),build(p<<1|1,mid+1,r); 
		k1[p]=(pre[k1[p<<1]]<pre[k1[p<<1|1]])?k1[p<<1]:k1[p<<1|1];
		k2[p]=(nxt[k2[p<<1]]>nxt[k2[p<<1|1]])?k2[p<<1]:k2[p<<1|1];
	}
	int ask1(int p,int l,int r,int x,int y){
		if(x<=l&&r<=y)return k1[p];
		int mid=(l+r)>>1;
		if(y<=mid)return ask1(p<<1,l,mid,x,y);
		if(x>mid)return ask1(p<<1|1,mid+1,r,x,y);
		int o1=ask1(p<<1,l,mid,x,y),o2=ask1(p<<1|1,mid+1,r,x,y);
		return (pre[o1]<pre[o2])?o1:o2;
	}
	int ask2(int p,int l,int r,int x,int y){
		if(x<=l&&r<=y)return k2[p];
		int mid=(l+r)>>1;
		if(y<=mid)return ask2(p<<1,l,mid,x,y);
		if(x>mid)return ask2(p<<1|1,mid+1,r,x,y);
		int o1=ask2(p<<1,l,mid,x,y),o2=ask2(p<<1|1,mid+1,r,x,y);
		return (nxt[o1]>nxt[o2])?o1:o2;
	}
	void up(int x){
		int p=hg[x];while(p>1){
			p>>=1;
			k1[p]=(pre[k1[p<<1]]<pre[k1[p<<1|1]])?k1[p<<1]:k1[p<<1|1];
			k2[p]=(nxt[k2[p<<1]]>nxt[k2[p<<1|1]])?k2[p<<1]:k2[p<<1|1];
		}
	}
	ll C2(ll x){return x*(x-1)/2;}
	void cut1(pi l,pi r){
		nxt[l.se]=r.se,pre[r.se]=l.se;
		up(l.se),up(r.se);
		int co=col[l.fi],S=sz[co],s2=0;
		for(int i=l.fi;i!=r.fi;i=nxt[i]){s2++;if(s2*2>S)break;}
		s2++,sc++;
		if(s2*2<=S){
			sz[co]=S-s2,sz[sc]=s2;
			for(int i=l.fi;i!=r.fi;i=nxt[i])col[i]=sc;col[r.fi]=sc;
		}
		else{
			s2=0;
			for(int i=l.se;i!=n+1;i=pre[i])col[i]=sc,s2++;
			for(int i=r.se;i;i=nxt[i])col[i]=sc,s2++;
			sz[co]=S-s2,sz[sc]=s2;
		}
		ns-=C2(S),ns+=C2(sz[co]),ns+=C2(sz[sc]);
	}
	void cut2(pi x){
		nxt[x.se]=0,up(x.se);
		int co=col[x.fi],S=sz[co],s2=0;
		for(int i=x.fi;i;i=nxt[i]){s2++;if(s2*2>S)break;}
		sc++;
		if(s2*2<=S){
			sz[co]=S-s2,sz[sc]=s2;
			for(int i=x.fi;i;i=nxt[i])col[i]=sc;
		}
		else{
			s2=0;for(int i=x.se;i!=n+1;i=pre[i])col[i]=sc,s2++;
			sz[co]=S-s2,sz[sc]=s2;
		}
		ns-=C2(S),ns+=C2(sz[co]),ns+=C2(sz[sc]);
	}
	void cut3(pi x){
		pre[x.se]=n+1,up(x.se);
		int co=col[x.fi],S=sz[co],s2=0;
		for(int i=x.fi;i!=n+1;i=pre[i]){s2++;if(s2*2>S)break;}
		sc++;
		if(s2*2<=S){
			sz[co]=S-s2,sz[sc]=s2;
			for(int i=x.fi;i!=n+1;i=pre[i])col[i]=sc;
		}
		else{
			s2=0;for(int i=x.se;i;i=nxt[i])col[i]=sc,s2++;
			sz[co]=S-s2,sz[sc]=s2;
		}
		ns-=C2(S),ns+=C2(sz[co]),ns+=C2(sz[sc]);
	}
	int ob[300100];
	void sol_(){
		n--;
		ns=C2(n);
		for(int i=1;i<=n;i++)col[i]=1;sz[1]=n;
		sc=1;
		for(int i=1;i<n;i++)pre[i+1]=i,nxt[i]=i+1;pre[1]=n+1,nxt[n]=0;
		build(1,1,n);
		for(int i=1;i<=m;i++){
			if(U[i]>V[i])swap(U[i],V[i]);if(U[i]==V[i]){
			ans[i]+=ns;continue;};V[i]--;
			vector<pi>o1,o2;
			while(1){
				int sb=ask1(1,1,n,U[i],V[i]),pr=pre[sb];
				if(pr>=U[i])break;
				o1.pb(mp(sb,pr)),pre[sb]=n+1;up(sb);
			}
			while(1){
				int sb=ask2(1,1,n,U[i],V[i]),nx=nxt[sb];
				if(nx<=V[i])break;
				o2.pb(mp(sb,nx)),nxt[sb]=0;up(sb);
			}
			sort(o1.begin(),o1.end(),[&](pi x,pi y){return col[x.fi]<col[y.fi];}),
			sort(o2.begin(),o2.end(),[&](pi x,pi y){return col[x.fi]<col[y.fi];});
			int i1=0,i2=0;
			while(i1<(int)o1.size()&&i2<(int)o2.size()){
				if(col[o1[i1].fi]==col[o2[i2].fi])cut1(o1[i1],o2[i2]),i1++,i2++;
				else if(col[o1[i1].fi]<col[o2[i2].fi])cut2(o1[i1]),i1++;
				else cut3(o2[i2]),i2++;
			}
			while(i1<(int)o1.size())cut2(o1[i1]),i1++;
			while(i2<(int)o2.size())cut3(o2[i2]),i2++;
			ans[i]+=ns;
		}
	}
void sol(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&U[i],&V[i]),ans[i]=0;
	if(n==1){for(int i=1;i<=m;i++)puts("0");return;}
	sol__();
	sol_();
	for(int i=1;i<=m;i++)printf("%lld\n",ans[i]);
}
int main(){
	int T;scanf("%d",&T);while(T--)sol();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 17904kb

input:

3
4 3
2 4
4 2
3 3
7 3
3 4
1 2
1 7
6 4
1 3
4 6
2 5
3 4

output:

6
5
6
21
24
10
15
12
3
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 48ms
memory: 17956kb

input:

45540
10 9
10 1
1 10
10 1
1 10
1 10
10 1
1 10
3 3
10 1
10 4
1 2
1 10
3 4
1 10
7 6
7 1
5 6
1 7
6 6
7 1
6 7
9 7
3 3
7 7
5 4
1 1
9 1
9 1
6 5
8 7
1 8
4 4
5 6
1 1
1 8
6 6
4 5
3 3
3 2
3 1
3 3
3 9
3 1
3 3
2 2
3 3
3 1
2 2
1 1
2 3
3 1
10 1
2 1
7 1
1 7
3 8
1 3
1 3
3 3
1 3
2 2
1 3
1 3
3 3
3 6
3 1
1 3
1 3
1 3
1...

output:

45
36
36
36
36
36
36
36
36
45
36
28
21
21
15
10
10
10
6
36
44
50
57
28
21
15
28
28
21
21
15
15
10
3
1
1
3
3
3
3
1
1
1
0
0
45
21
3
1
1
1
1
1
1
1
3
1
1
1
1
1
45
36
36
36
36
36
36
36
3
3
1
0
0
0
0
0
0
3
1
0
0
15
10
10
0
0
0
0
0
0
0
0
28
34
21
6
6
6
6
1
0
0
21
15
15
0
0
0
0
0
0
0
45
53
0
0
0
0
0
0
0
0
1...

result:

ok 249586 numbers

Test #3:

score: 0
Accepted
time: 54ms
memory: 17952kb

input:

2507
86 4
41 41
36 36
31 30
86 1
110 22
1 110
110 1
11 11
110 1
110 1
110 1
1 110
107 106
72 72
106 106
74 74
1 110
110 1
58 58
110 1
110 1
1 110
101 100
110 1
100 100
110 1
8 7
114 180
114 1
114 1
114 1
1 114
1 114
114 1
37 38
49 48
105 106
1 114
90 90
1 114
9 9
114 1
67 68
20 20
114 1
1 114
54 55
...

output:

3655
3740
3823
3570
5995
5886
5886
5886
5886
5886
5886
5778
5778
5778
5778
5778
5778
5778
5778
5778
5778
5671
5671
5671
5671
5565
6441
6328
6328
6328
6328
6328
6216
6105
5995
5995
5995
5995
5995
5995
5886
5886
5886
5886
5778
5671
5671
5565
5565
5460
5460
5460
5460
5460
5356
5253
5253
5253
5151
5151
...

result:

ok 249877 numbers

Test #4:

score: 0
Accepted
time: 40ms
memory: 20220kb

input:

3
82425 27858
30801 30802
1 82425
73850 73850
1 82425
65949 65949
82425 1
76026 76025
61936 61936
82425 1
82425 1
82425 1
6504 6504
82425 1
25155 25156
79743 79743
1 82425
69406 69406
29247 29247
18351 18351
23171 23170
29704 29703
82425 1
1 82425
82425 1
74918 74917
22395 22394
893 894
82425 1
391 ...

output:

3396899100
3396816676
3396816676
3396734253
3396734253
3396734253
3396651831
3396651831
3396651831
3396651831
3396651831
3396651831
3396651831
3396569410
3396569410
3396569410
3396569410
3396569410
3396569410
3396486990
3396404571
3396404571
3396404571
3396404571
3396322153
3396239736
3396157320
339...

result:

ok 116748 numbers

Test #5:

score: 0
Accepted
time: 85ms
memory: 24508kb

input:

1
250000 250000
248617 248617
1 250000
47808 47809
1 250000
1 250000
110493 110494
1 250000
66675 66676
141326 141327
250000 1
115279 115280
193218 193219
250000 1
77714 77715
1 250000
1 250000
212943 212943
223061 223060
1 250000
250000 1
1 250000
71059 71059
1 250000
246523 246522
1 250000
88700 8...

output:

31249875000
31249875000
31249625001
31249375003
31249375003
31249125006
31249125006
31248875010
31248625015
31248625015
31248375021
31248125028
31248125028
31247875036
31247875036
31247875036
31247875036
31247625045
31247625045
31247625045
31247625045
31247625045
31247625045
31247375055
31247375055
...

result:

ok 250000 numbers

Test #6:

score: 0
Accepted
time: 64ms
memory: 17980kb

input:

45364
9 7
1 8
9 8
8 9
8 2
9 8
2 8
4 2
10 2
2 10
1 10
10 7
8 9
4 4
10 10
1 10
2 9
9 1
6 8
6 7
6 2
5 1
1 5
5 5
1 5
2 3
5 1
10 1
2 10
9 6
1 8
2 9
2 1
9 8
2 8
8 1
1 4
1 1
1 1
1 1
1 1
8 1
2 2
3 7
3 2
2 2
3 1
2 3
2 3
3 3
3 3
5 1
4 2
3 9
3 1
1 2
1 2
2 1
2 1
1 1
3 2
2 2
3 2
3 2
3 1
3 2
3 6
3 1
2 2
2 2
1 3
3...

output:

36
29
28
16
16
16
8
45
29
45
53
61
36
18
16
8
15
5
4
4
4
2
2
45
36
17
16
15
15
15
0
0
0
0
28
3
4
1
1
1
1
1
10
3
1
1
1
1
1
0
0
0
3
1
3
3
3
1
0
0
6
36
30
12
8
8
3
4
5
5
1
0
0
0
0
0
6
5
6
1
0
0
0
0
0
0
28
32
19
20
11
7
7
21
17
17
12
4
3
2
1
1
21
11
7
6
3
3
1
2
1
1
28
25
20
21
22
22
23
11
1
1
28
1
1
0
0...

result:

ok 249141 numbers

Test #7:

score: 0
Accepted
time: 69ms
memory: 17988kb

input:

2517
14 35
2 13
14 1
14 14
1 14
7 7
1 14
7 7
2 14
9 11
2 4
2 13
11 12
14 2
13 1
14 1
13 2
12 11
2 14
1 13
12 11
1 14
4 5
2 14
14 14
13 13
10 9
14 2
1 14
14 2
13 2
14 2
7 8
6 6
1 1
13 1
51 125
30 30
40 39
25 24
51 1
1 51
40 40
8 7
50 2
2 50
7 9
50 1
30 30
47 49
14 16
2 4
1 51
1 50
6 6
1 51
4 4
50 2
2...

output:

91
58
58
56
56
56
56
55
37
23
23
17
17
17
17
17
17
17
17
17
17
12
12
12
12
11
11
11
11
11
11
7
7
7
7
1275
1324
1370
1176
1128
1128
1081
991
991
947
946
946
862
782
706
706
706
706
706
706
706
706
706
668
598
598
598
598
532
532
532
532
532
532
532
500
469
469
469
469
411
383
383
383
331
331
331
331
...

result:

ok 250000 numbers

Test #8:

score: 0
Accepted
time: 23ms
memory: 20204kb

input:

5
65849 4012
8907 8905
21927 21927
2 65849
2 65848
65849 1
1 65849
48863 48861
2 65849
7795 7795
65849 2
2 65849
65849 2
2696 2695
65848 2
41766 41765
2 65849
36403 36403
65849 2
32613 32613
26782 26781
60024 60024
44568 44570
5043 5043
52955 52954
15301 15299
65849 2
1 65849
27002 27000
22706 22707...

output:

2168012476
2168078322
2167880786
2167749099
2167683248
2167683247
2167551563
2167551563
2167551563
2167551563
2167551563
2167551563
2167485722
2167485722
2167419882
2167419882
2167419882
2167419882
2167419882
2167354043
2167354043
2167222369
2167222369
2167156533
2167024865
2167024865
2167024865
216...

result:

ok 52236 numbers

Test #9:

score: 0
Accepted
time: 127ms
memory: 24612kb

input:

1
250000 250000
97733 97731
132027 132027
196875 196877
1 250000
170476 170476
44407 44407
250000 1
249999 2
133959 133958
45337 45335
246071 246069
2589 2587
1 249999
172569 172570
2 249999
250000 2
244802 244804
79199 79199
1 249999
249999 1
213003 213003
84015 84014
92491 92492
124485 124485
1803...

output:

31249875000
31250124997
31250374986
31248875012
31248875012
31248875012
31248625017
31248125031
31247875039
31247375059
31246875083
31246375111
31246375110
31246125125
31246125125
31246125125
31245625159
31245625159
31245625159
31245625159
31245625159
31245375177
31245125196
31245125196
31244875216
...

result:

ok 250000 numbers

Test #10:

score: 0
Accepted
time: 64ms
memory: 18064kb

input:

45413
6 5
3 1
6 5
5 1
2 5
2 2
9 3
5 5
4 5
5 4
6 10
1 6
5 2
6 3
5 2
2 2
2 6
3 5
5 5
2 2
1 6
7 3
4 4
1 1
4 1
6 10
1 1
4 6
2 2
3 5
3 5
5 3
4 6
4 4
3 5
5 5
1 10
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
10 4
4 10
6 3
3 8
3 6
10 1
4 4
9 5
2 9
2 1
7 7
2 9
1 9
5 1
5 5
3 2
1 3
2 1
9 8
6 3
9 6
4 4
6 9
7 7
7 4
...

output:

15
15
5
2
2
36
43
49
15
6
2
2
2
2
2
2
2
1
21
27
27
15
18
21
17
18
20
21
23
25
27
0
0
0
0
0
0
0
0
0
0
45
31
26
28
45
36
29
29
22
21
10
3
1
36
29
31
30
32
28
29
4
1
2
3
4
5
6
1
1
0
0
45
52
43
37
34
34
36
35
37
21
16
12
11
12
13
12
13
10
10
8
8
9
10
11
1
1
36
28
8
45
32
26
27
18
16
17
17
2
1
10
8
2
1
0...

result:

ok 250000 numbers

Test #11:

score: 0
Accepted
time: 93ms
memory: 17964kb

input:

2446
12 162
6 8
8 9
11 8
3 10
9 8
2 5
10 1
1 4
7 8
10 12
1 5
10 4
2 11
7 4
3 9
10 5
8 3
11 1
4 10
11 6
7 10
12 8
11 9
4 3
6 1
8 4
2 2
10 12
7 9
12 12
7 9
8 11
4 4
11 11
6 10
8 5
8 5
11 8
8 2
5 7
9 9
2 2
10 4
6 9
12 8
7 1
1 6
12 10
1 8
5 11
4 3
6 8
4 5
3 7
4 8
12 7
1 11
2 9
6 8
12 7
8 5
9 3
11 3
9 3
...

output:

66
72
69
47
50
36
21
20
20
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 244825 numbers

Test #12:

score: 0
Accepted
time: 135ms
memory: 22596kb

input:

4
39845 77223
11304 11308
2 39838
6 39838
9 39836
39840 2
3 39844
5582 5576
11054 11055
39841 6
15426 15418
39837 3
18844 18851
5 39839
15992 16000
9 39844
39358 39355
9 39843
6 39843
7 39844
34287 34281
284 276
6614 6606
27606 27605
2870 2868
6 39845
39842 7
36916 36913
33317 33321
39836 3
39841 3
...

output:

793792090
793632766
793433634
793234527
793154851
792995480
792756580
792716766
792716764
792398302
792398300
792119695
792119694
791801352
791801348
791681980
791681980
791681982
791681982
791443280
791125074
790806932
790767167
790687639
790647775
790647775
790528490
790369459
790369460
790369461
...

result:

ok 250000 numbers

Test #13:

score: 0
Accepted
time: 181ms
memory: 24876kb

input:

1
250000 250000
237315 237325
161044 161036
137460 137451
247727 247730
38655 38653
23041 23049
5 249992
249997 2
178760 178760
198841 198847
10 249995
146224 146229
5 249999
8273 8274
249995 5
210583 210583
5 249996
249997 2
249998 9
81327 81318
3 249991
25090 25085
249991 10
48955 48955
249996 1
1...

output:

31249875000
31250124901
31250374702
31250624584
31250874485
31251124156
31239876513
31237626626
31237626630
31236126988
31234877294
31233627643
31233127625
31232877697
31232877699
31232877701
31232877702
31232877701
31232877697
31230628410
31230378490
31229128917
31229128919
31229128921
31228878902
...

result:

ok 250000 numbers

Test #14:

score: 0
Accepted
time: 109ms
memory: 17904kb

input:

2502
18 58
12 14
10 14
16 6
17 5
11 12
7 7
3 3
13 3
9 10
10 6
10 7
4 4
2 14
7 12
9 9
10 6
2 6
16 3
12 9
14 8
18 14
9 11
7 8
13 10
15 8
4 5
3 6
6 2
6 17
18 9
17 18
12 7
15 6
18 16
11 12
14 8
13 15
9 5
5 15
2 11
18 2
1 3
16 6
5 1
13 11
12 13
17 13
4 3
16 14
11 15
6 18
18 15
13 7
10 7
4 4
16 11
9 6
16 ...

output:

153
160
135
110
114
119
124
80
80
83
84
87
62
64
66
68
69
71
73
74
40
41
42
43
43
43
44
45
46
46
47
48
49
50
51
52
53
54
55
56
57
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4753
3942
3981
3590
3619
3639
3612
3584
3507
2005
2005
1721
1604
1225
1228
1227
1130
1120
1120
1120
1114
899
878
750
740
745
746
751
724...

result:

ok 250000 numbers

Test #15:

score: 0
Accepted
time: 134ms
memory: 18024kb

input:

102
4953 1459
24 4912
4916 160
4771 89
139 4945
4897 187
2648 2783
119 4844
2725 2891
3572 3737
695 880
316 258
45 4925
159 4883
199 4923
4847 52
1026 1185
193 4882
4449 4249
3997 4032
4860 10
163 4910
3344 3396
1738 1730
2418 2339
4304 4163
1874 1837
4884 106
4880 72
4809 86
2724 2895
67 4832
4820 ...

output:

12263628
11593112
10938335
10795386
10669759
10069175
10064737
9591474
8902465
8164161
7936078
7934952
7934417
7887382
7887046
7288919
7288879
6576510
6453096
6383660
6383579
6202896
6175177
5907542
5615612
5494824
5494607
5494244
5492889
5479786
5479452
5479335
5473146
5163189
4688416
4646510
46390...

result:

ok 250000 numbers

Test #16:

score: 0
Accepted
time: 153ms
memory: 20500kb

input:

4
21918 92931
82 21855
7116 7178
9491 9490
21730 78
43 21862
5666 5629
21015 20888
21890 82
5601 5698
104 21745
12125 12198
21860 87
20657 20742
147 21825
12995 13023
50 21817
21917 162
21740 43
9798 9869
5509 5678
21888 160
21916 38
21752 106
108 21891
11552 11750
52 21803
21741 67
17717 17606
193 ...

output:

240188403
238842403
238820836
236014166
235099375
234302197
231581828
230970546
229688956
229217918
227665570
227665545
225865230
224953966
224362956
224362226
223455542
223455528
221962867
220036366
220036331
219926847
219926348
219926283
215820989
215820261
215820130
213531015
212892565
212892184
...

result:

ok 250000 numbers

Test #17:

score: 0
Accepted
time: 192ms
memory: 24484kb

input:

1
250000 250000
111 249894
249917 58
218975 218775
249877 56
27879 27766
173773 173666
156284 156320
91013 90934
94 249845
87959 87909
249981 112
249935 1
249903 46
173989 173869
188 249834
13 249973
37722 37870
111 250000
47757 47909
249990 16
195 249827
249825 178
78173 78038
205733 205898
54532 5...

output:

31249875000
31230641849
31180725389
31175981911
31147793860
31121113976
31112138954
31092449843
31084475001
31072017689
31055776912
31042029658
31042029091
31012145750
30990487902
30990487150
30953665805
30948915873
30911122441
30911122252
30907641474
30907143405
30873597255
30832623630
30788949406
...

result:

ok 250000 numbers

Test #18:

score: 0
Accepted
time: 139ms
memory: 18072kb

input:

109
1078 1889
1007 282
178 79
751 816
125 68
1066 175
742 543
497 489
930 354
847 438
315 601
821 685
951 524
489 665
836 3
984 270
1062 332
344 978
550 22
580 703
895 626
1021 237
827 678
954 925
316 455
1059 524
679 727
945 945
254 123
1061 193
420 105
1054 522
484 402
251 359
770 922
704 785
284 ...

output:

580503
508981
466269
454941
317613
225953
222408
177191
154391
131150
126077
122805
120227
46277
44428
43793
43525
42262
40944
38303
35796
35665
35457
34877
34777
34425
34439
34093
33445
31803
31602
30607
30364
29378
28904
28824
27974
27919
27397
27111
27082
26766
26608
26498
26332
26334
26238
26190...

result:

ok 250000 numbers

Test #19:

score: 0
Accepted
time: 142ms
memory: 20424kb

input:

4
97869 79786
97622 3759
51039 48491
3746 96678
14109 12461
6629 4082
1371 93507
2333 97649
94628 1603
2356 93761
8368 12451
38763 36986
1521 96702
96912 1332
3645 4908
93548 3615
37535 42115
4122 94942
49098 48685
507 93973
38937 34664
61132 58080
96699 4317
94764 4828
54733 58221
24842 22743
96548...

output:

4789121646
4556452483
4469835648
4323624136
4104137856
3617965605
3614006620
3611540070
3611289472
3289052536
3151967461
3151934589
3148031619
3121667929
3121622977
2874678916
2874103923
2873223719
2793609996
2627852094
2420023828
2419909246
2419844884
2202720256
2071218632
2071009041
2070682619
182...

result:

ok 174605 numbers

Test #20:

score: 0
Accepted
time: 234ms
memory: 25524kb

input:

1
250000 250000
72499 76406
249218 4952
77574 76846
249739 244771
248750 3284
78949 74197
2272 247857
247357 1612
1772 246339
582 249942
17878 18405
245086 199
246304 4360
248683 3281
159052 160180
160056 163657
162450 161367
2701 248329
6867 3683
79691 76969
247219 2874
3917 248097
249343 4784
7903...

output:

31249875000
30310794213
30136347850
28963221739
28552818207
28125506134
27873333680
27708709360
27707034508
27401084011
27278376916
27182263647
27181584281
27181526168
26920153032
26126448743
26123856297
26123440645
25689764148
25521704629
25521513034
25521353948
25521233472
25521144124
24480414364
...

result:

ok 250000 numbers

Test #21:

score: 0
Accepted
time: 166ms
memory: 19752kb

input:

6
4504 68246
1935 1539
2647 2420
4176 1531
1242 3504
594 1855
2365 3008
1399 2440
4283 3866
1281 822
1552 2661
2794 4456
581 1251
1730 2010
1408 4014
1493 1085
3013 572
1497 1984
3285 2854
147 1562
2360 949
645 1199
241 813
2881 3772
2481 90
3258 907
2744 3523
616 4378
4440 1546
3893 1335
1605 3559
...

output:

10140756
10054744
8794251
7122287
5183727
4799432
4542354
4046722
3946754
3938771
3270727
3220521
3172274
3147819
3103926
3067076
3066285
2998096
1338676
1319848
1306113
1273350
1244923
991293
981245
972501
964495
963536
956950
944044
934765
927579
895626
889606
878145
873397
867276
859443
825217
81...

result:

ok 250000 numbers

Test #22:

score: 0
Accepted
time: 282ms
memory: 23436kb

input:

1
250000 250000
78728 18467
96029 29326
146284 226853
151138 242845
17298 237050
215585 165899
148360 57422
139200 46464
91709 101742
170802 7337
40205 201363
243742 181387
23836 188875
74041 226144
32715 104452
207839 16584
161154 155400
81599 152793
55837 102307
48013 239741
3124 20119
112705 1858...

output:

31249875000
29670966156
23421884677
20525501292
11512135494
10218883052
9555728650
9062131534
8792080512
6159442482
5656726770
5234028963
5111056603
5025690613
4906153517
4849400943
4797588259
4756408483
4740353947
4719895301
3717700639
3498872878
3469326746
3388194413
2780288653
2743462855
27262393...

result:

ok 250000 numbers

Test #23:

score: 0
Accepted
time: 305ms
memory: 22864kb

input:

1
250000 250000
98350 139819
117361 123481
47387 136547
40152 163109
32803 210394
39234 141097
223538 41000
173606 25779
201484 240798
106552 149426
164258 101032
32861 141545
202238 109711
64708 123868
195171 52486
201726 79996
132517 141751
72535 168680
218355 4746
149137 138248
129101 194905
1794...

output:

31249875000
31033741530
28815475466
25994000423
19276245666
19039617712
16394718112
14668835501
11007023197
10689107134
10663596622
10659731280
10588174792
9903595567
9705170724
9424485848
9388084308
9307939269
4743832141
4739039263
4715511748
4595009974
4583730433
3694188832
3688460299
3604351811
1...

result:

ok 250000 numbers

Test #24:

score: 0
Accepted
time: 299ms
memory: 23284kb

input:

1
250000 250000
47945 118382
42757 25501
200466 28665
153547 227037
8846 165216
165912 146621
172496 97140
208128 10321
183866 90543
45575 190028
213347 33638
83567 16117
178986 170414
60599 7118
126503 14585
157202 219073
124452 176526
41791 119637
181301 102458
238476 19252
175136 157698
133661 60...

output:

31249875000
30034576434
22336749083
15794380063
12026404059
11770870881
10395244087
10227981795
9758252597
9687286789
9570516481
9267659553
9226646997
8558983746
8389103100
8314234420
8291901130
8278012587
8187420860
5651981579
5644601692
5547629980
5484228508
5469130686
3807787358
3796677396
377786...

result:

ok 250000 numbers

Test #25:

score: 0
Accepted
time: 289ms
memory: 23956kb

input:

1
250000 250000
219096 227828
225541 45464
101569 208289
92599 90242
162552 230720
187252 123722
48344 238778
20167 127441
109452 93641
218652 159941
44465 200315
238229 8979
199822 18339
238111 13193
6254 81754
193527 113718
218621 25761
148135 152511
233081 14976
2840 3058
66378 106936
209301 2020...

output:

31249875000
29719041851
22578154126
22426063269
18528675447
17148925300
15509595247
10488629906
10035742564
9946315280
9817907605
7367841809
7344553091
7322010763
6377389024
6295228310
6190295317
6067242168
6049387584
5998710685
5707933786
5687485059
5663637988
5568376556
5000296228
4987029489
49579...

result:

ok 250000 numbers

Test #26:

score: 0
Accepted
time: 339ms
memory: 18208kb

input:

42
8581 8581
6435 1
6434 2
6433 3
4 6432
6431 5
6430 6
6429 7
6428 8
6427 9
10 6426
11 6425
6424 12
6423 13
14 6422
15 6421
16 6420
17 6419
6418 18
19 6417
20 6416
6415 21
6414 22
6413 23
24 6412
6411 25
6410 26
27 6409
28 6408
29 6407
6406 30
6405 31
6404 32
33 6403
34 6402
6401 35
36 6400
37 6399
...

output:

36812490
36795340
36784626
36773916
36763210
36752508
36741810
36731116
36720426
36709740
36699058
36688380
36677706
36667036
36656370
36645708
36635050
36624396
36613746
36603100
36592458
36581820
36571186
36560556
36549930
36539308
36528690
36518076
36507466
36496860
36486258
36475660
36465066
364...

result:

ok 250000 numbers

Test #27:

score: 0
Accepted
time: 939ms
memory: 21260kb

input:

10
17692 17692
1 13269
2 13268
3 13267
4 13266
5 13265
13264 6
13263 7
13262 8
13261 9
10 13260
13259 11
13258 12
13257 13
14 13256
13255 15
13254 16
17 13253
13252 18
19 13251
13250 20
13249 21
22 13248
23 13247
24 13246
13245 25
13244 26
27 13243
13242 28
13241 29
13240 30
31 13239
13238 32
33 132...

output:

156494586
156459211
156437106
156415005
156392908
156370815
156348726
156326641
156304560
156282483
156260410
156238341
156216276
156194215
156172158
156150105
156128056
156106011
156083970
156061933
156039900
156017871
155995846
155973825
155951808
155929795
155907786
155885781
155863780
155841783
...

result:

ok 250000 numbers

Test #28:

score: 0
Accepted
time: 1797ms
memory: 21460kb

input:

4
41764 41764
31323 1
31322 2
31321 3
4 31320
31319 5
6 31318
31317 7
31316 8
31315 9
31314 10
31313 11
12 31312
13 31311
14 31310
31309 15
31308 16
31307 17
31306 18
19 31305
20 31304
31303 21
22 31302
31301 23
24 31300
25 31299
26 31298
31297 27
28 31296
29 31295
30 31294
31293 31
31292 32
33 3129...

output:

872094966
872011447
871959252
871907061
871854874
871802691
871750512
871698337
871646166
871593999
871541836
871489677
871437522
871385371
871333224
871281081
871228942
871176807
871124676
871072549
871020426
870968307
870916192
870864081
870811974
870759871
870707772
870655677
870603586
870551499
...

result:

ok 250000 numbers

Test #29:

score: -100
Time Limit Exceeded

input:

2
108324 108324
81243 1
81242 2
81241 3
81240 4
81239 5
6 81238
81237 7
8 81236
9 81235
81234 10
11 81233
12 81232
81231 13
14 81230
81229 15
16 81228
17 81227
18 81226
19 81225
20 81224
21 81223
81222 22
81221 23
81220 24
81219 25
81218 26
81217 27
28 81216
81215 29
30 81214
81213 31
32 81212
81211...

output:

5866990326
5866773687
5866638292
5866502901
5866367514
5866232131
5866096752
5865961377
5865826006
5865690639
5865555276
5865419917
5865284562
5865149211
5865013864
5864878521
5864743182
5864607847
5864472516
5864337189
5864201866
5864066547
5863931232
5863795921
5863660614
5863525311
5863390012
586...

result: