QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709293#9524. 1D Galaxyucup-team1004TL 49ms12020kbC++173.9kb2024-11-04 13:48:512024-11-04 13:48:51

Judging History

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

  • [2024-11-04 13:48:51]
  • 评测
  • 测评结果:TL
  • 用时:49ms
  • 内存:12020kb
  • [2024-11-04 13:48:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=1e5+10;
const ll INF=1e18;
int n,m,fa[N];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
struct ques{
	int t,i,id;
}o[N];
ll w[N],a[N];
int cur[N],oth[N];
int pre[N],nex[N];
ll pw[N],sw[N];
int d[N];
int tlas[N];
void getd(int i){
	if(pw[i]>sw[i])d[i]=-1;
	else if(pw[i]<sw[i])d[i]=1;
	else d[i]=0;
}
void swp(int y){
	int x=pre[y];
	int p=pre[x],q=nex[y];
	nex[p]=y,pre[y]=p;
	nex[y]=x,pre[x]=y;
	nex[x]=q,pre[q]=x;
	pw[y]=pw[pre[y]]+w[pre[y]];
	pw[x]=pw[pre[x]]+w[pre[x]];
	sw[x]=sw[nex[x]]+w[nex[x]];
	sw[y]=sw[nex[y]]+w[nex[y]];
}
int refind(int x,int t){
	if(oth[x]){
		int y=oth[x];
		if((t-tlas[x])&1){
			swp(a[x]<a[y]?y:x);
			swap(a[x],a[y]);
			tlas[x]=tlas[y]=t;
			return y;
		}else{
			tlas[x]=tlas[y]=t;
			return x;
		}
	}else{
		a[x]+=(t-tlas[x])*d[x],tlas[x]=t;
		return x;
	}
}
ll geta(int x,int t){
	if(oth[x]){
		int y=oth[x];
		if((t-tlas[x])&1)return a[y];
		else return a[x];
	}else{
		return a[x]+(t-tlas[x])*d[x];
	}
}
void remove(int y){
	int x=pre[y];
	fa[y]=x;
	w[x]+=w[y];
	nex[x]=nex[y];
	pre[nex[y]]=x;
	sw[x]=sw[nex[x]]+w[nex[x]];
}
int vcnt,val[N];
void update(int x){
	if(oth[x]){
		int y=oth[x];
		oth[x]=oth[y]=0;
		val[y]=++vcnt;
		getd(y);
	}
	val[x]=++vcnt;
}
priority_queue<tuple<ll,int,int,int>>q;
// (t,x,w1,w2) -t pre[x],x val[pre[x]]=w1,val[x]=w2
void push(int y,int t0){
	int x=pre[y];
	if(geta(y,t0)-geta(x,t0)==0){
		debug("push",t0,x,y,val[x],val[y]);
		q.push({-t0,y,val[x],val[y]});
		return;
	}
	if(d[y]-d[x]>=0)return;
	int v=d[x]-d[y];
	ll t=t0+(geta(y,t0)-geta(x,t0)+v-1)/v;
	debug("push",t,x,y,val[x],val[y]);
	q.push({-t,y,val[x],val[y]});
}
ll ans[N];
void print(int cur){
	for(int i=1;i<=n;i++)find(i);
	debug("fa",ary(fa,1,n));
	vector<tuple<int,int,int,int>>t;
	for(int i=nex[0];i!=n+1;i=nex[i]){
		t.push_back({i,geta(i,cur),w[i],d[i]});
	}
	debug(cur,t);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&w[i]);
	a[0]=-INF,a[n+1]=INF;
	iota(cur,cur+1+n+1,0);
	sort(cur+1,cur+1+n,[&](int x,int y){
		return a[x]<a[y];
	});
	iota(fa,fa+1+n,0);
	for(int l=1,r,las=0;l<=n+1;l=r){
		for(r=l+1;r<=n&&a[cur[l]]==a[cur[r]];r++);
		for(int i=l+1;i<r;i++)fa[cur[i]]=cur[l],w[cur[l]]+=w[cur[i]];
		nex[las]=cur[l],pre[cur[l]]=las;
		las=cur[l];
	}
	for(int i=0;i!=n+1;i=nex[i])pw[nex[i]]=pw[i]+w[i];
	for(int i=n+1;i!=0;i=pre[i])sw[pre[i]]=sw[i]+w[i];
	for(int i=1;i<=m;i++){
		scanf("%d%d",&o[i].t,&o[i].i);
		o[i].id=i;
	}
	sort(o+1,o+1+m,[&](ques x,ques y){
		return x.t<y.t;
	});
	for(int i=0;;i=nex[i]){
		getd(i);
		if(i==n+1)break;
	}
	for(int i=0;i!=n+1;i=nex[i])push(nex[i],0);
	print(0);
	for(int ot=1;ot<=m;ot++){
		int t0=o[ot].t,x=o[ot].i;
		for(;!q.empty()&&get<0>(q.top())>-t0;){
			auto [t,y,w1,w2]=q.top();
			t=-t;
			q.pop();
			int x=pre[y];
			if(fa[x]!=x||fa[y]!=y)continue;
			if(val[x]!=w1||val[y]!=w2)continue;
			x=refind(x,t),y=refind(y,t);
			// debug(x,y,t);
			assert(x!=y);
			int v=d[x]-d[y];
			if(a[x]==a[y]){
				debug("merge",x,y,t);
				update(y);
				remove(y);
				getd(x);
				update(x);
				if(pre[x]>0)push(pre[x],t);
				push(x,t);
				push(nex[x],t);
				if(nex[x]<=n)push(nex[nex[x]],t);
			}else{
				debug("cross",x,y,t);
				swp(y);
				update(x);
				update(y);
				getd(x),getd(y);
				if(d[y]==1&&d[x]==-1){
					debug("range",x,y);
					oth[y]=x,oth[x]=y;
					d[x]=d[y]=0;
				}
				push(y,t);
				push(x,t);
				push(nex[x],t);
			}
			print(t);
		}
		x=find(x);
		ans[o[ot].id]=geta(x,t0);
	}
	for(int i=1;i<=m;i++)printf("%lld\n",ans[i]);
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7864kb

input:

4 12
0 1
1 2
-1 3
2 2
0 1
0 2
0 3
0 4
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4

output:

0
1
-1
2
1
0
0
1
0
1
1
0

result:

ok 12 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 10268kb

input:

5 5
-4 5
-1 3
5 5
0 4
-4 2
0 3
3 1
5 5
1 3
3 3

output:

5
-1
1
4
2

result:

ok 5 lines

Test #3:

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

input:

5 5
3 2
1 3
0 3
1 5
0 5
7 1
1 4
1 5
8 5
10 3

output:

0
0
1
0
0

result:

ok 5 lines

Test #4:

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

input:

5 5
-3 2
-2 1
5 3
0 1
1 5
10 5
3 1
1 3
2 3
8 4

output:

1
0
4
3
0

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 10036kb

input:

5 5
0 5
-3 1
-2 5
-5 2
-3 4
6 1
7 3
2 3
6 1
8 1

output:

-2
-3
-2
-2
-2

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 9952kb

input:

5 5
-1 1
-8 4
0 2
4 3
5 1
1 3
10 5
4 4
4 1
9 4

output:

-1
-1
0
-1
-1

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 1ms
memory: 7924kb

input:

4 4
-5 4
1 0
2 3
-1 -2
1 1
1 3
0 1
9 2

output:

-4
1
-5
-2

result:

ok 4 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 9964kb

input:

4 4
-7 -2
10 1
9 2
-10 3
11 3
4 3
0 1
20 4

output:

0
6
-7
0

result:

ok 4 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 9972kb

input:

100 1000
4 77
6 -9
3 -9
6 0
-5 44
-1 -47
-2 -77
10 71
-3 -18
-10 78
-2 41
-3 18
-1 -46
-1 26
8 -72
-8 69
6 71
-5 -9
-3 6
8 64
-5 66
-2 -73
-4 49
-9 -10
2 74
10 65
9 68
10 15
6 -11
5 -18
-10 -79
9 -27
5 52
3 -71
-2 -77
9 -70
9 -30
9 66
9 8
-1 -7
7 67
-6 -17
-6 -8
-3 20
-10 75
7 41
6 -61
1 5
-5 66
-8 ...

output:

6
6
6
5
6
5
6
5
5
6
5
5
6
5
5
5
5
6
6
6
-1
5
2
5
6
6
6
5
7
5
6
6
5
6
6
6
5
5
5
5
6
5
5
6
5
6
6
5
5
5
5
8
6
6
5
5
5
5
5
5
3
5
6
6
6
5
6
6
6
8
6
5
6
-5
5
5
4
6
6
5
5
6
6
5
6
6
6
6
6
6
5
6
5
6
5
5
6
5
6
6
5
5
5
5
6
5
6
6
7
5
6
5
6
6
5
5
5
5
5
5
6
5
5
6
6
5
5
6
6
5
6
5
6
6
5
6
6
5
6
2
6
5
5
5
5
6
5
5
6
...

result:

ok 1000 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 9968kb

input:

5 50
-1 -4
1 4
-2 0
0 3
-2 3
13 3
13 2
6 4
4 1
15 4
0 5
7 4
11 2
1 1
2 1
7 1
6 1
2 4
14 2
3 3
4 1
14 4
3 1
10 3
0 3
2 1
14 3
6 3
8 5
11 5
11 3
7 5
9 2
6 5
7 4
8 3
15 3
0 4
15 1
6 5
9 2
6 4
1 5
0 3
2 4
6 4
9 5
0 1
8 1
11 1
5 2
6 2
8 4
3 5
0 3

output:

0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
-2
0
0
0
-1
0
0
0
0
0
0
-2

result:

ok 50 lines

Test #11:

score: 0
Accepted
time: 3ms
memory: 7960kb

input:

1000 1000
-631 10
954 2
-663 -9
996 4
479 9
160 -7
-479 -8
540 6
729 1
-280 10
-567 2
572 0
587 1
-592 2
806 3
-84 -9
-117 3
-958 1
-147 -4
-870 -3
44 4
709 -4
-889 10
263 1
-590 7
-242 -1
483 -7
79 -8
59 -7
-618 9
860 -9
110 -2
735 4
-797 -5
362 1
-357 -1
-54 -1
-381 5
-907 -3
-275 -8
798 -7
-150 -...

output:

-1011
-108
-1010
-666
1355
-375
-540
-100
1154
-178
754
-598
-1112
-1135
-509
6
-353
-57
-395
-1080
-555
974
-335
706
366
-37
-1250
-557
-1338
1466
-969
18
-512
-851
-1057
-926
-602
-513
-1403
1267
1121
-358
224
-675
-530
-250
-1206
-1292
102
1437
-697
-891
981
267
-75
-63
-589
1417
-89
-489
-845
34...

result:

ok 1000 lines

Test #12:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

1 1
-1000000000 -1000000000
1000000000 1

output:

-1000000000

result:

ok single line: '-1000000000'

Test #13:

score: 0
Accepted
time: 16ms
memory: 9572kb

input:

5 100000
4 0
4 0
0 -3
0 -1
-2 -1
2 3
0 2
7 2
2 2
9 4
6 1
1 1
8 1
3 1
8 3
1 4
5 3
6 2
0 4
9 3
8 5
0 1
5 4
7 1
8 2
1 5
6 1
7 5
2 4
3 5
10 2
9 2
2 3
10 3
10 2
8 4
6 5
7 5
9 4
3 1
7 5
3 2
10 1
4 3
7 2
1 3
3 3
0 1
5 3
2 3
0 2
5 5
6 5
9 4
4 5
10 1
3 3
5 1
6 4
10 4
7 3
6 3
0 1
8 5
2 5
2 1
5 3
4 1
8 2
7 1
8...

output:

2
4
11
6
9
10
5
12
7
8
1
5
10
0
9
-10
4
5
11
12
-3
10
-9
2
-5
14
13
2
10
14
8
-8
-9
9
7
-9
7
14
4
11
1
3
4
5
2
4
-7
-8
9
-6
14
3
9
6
10
7
6
4
-10
-4
6
5
8
12
11
12
5
9
3
5
4
2
-6
-5
2
10
0
13
4
13
0
7
9
6
14
-2
9
7
0
-5
9
10
1
-6
-12
4
5
2
10
8
5
-7
-4
12
2
5
0
3
1
10
5
3
10
4
7
7
14
10
10
8
4
-8
0
...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 16ms
memory: 9400kb

input:

5 100000
-1 4
5 -4
-2 -4
-1 -2
3 -1
9 1
5 2
8 3
1 2
5 2
7 2
6 5
3 3
10 2
7 2
6 2
3 2
4 2
2 1
6 3
8 5
7 3
2 5
9 3
2 4
3 4
9 1
9 5
5 5
4 1
9 5
6 4
3 3
3 5
3 5
8 5
7 3
5 5
8 3
4 2
10 2
2 4
3 2
4 1
6 4
6 1
10 3
3 2
10 5
9 2
0 3
7 1
3 5
0 5
5 1
3 2
4 3
4 1
5 5
8 5
1 1
6 3
1 3
6 4
7 5
6 5
0 5
4 1
9 1
8 3
...

output:

-10
10
-10
6
10
12
-3
-5
15
12
11
8
9
-3
-8
-5
-9
1
-11
-3
-4
-10
-6
-2
-5
-6
-7
-5
0
0
-5
-9
-2
-10
9
15
-3
8
-5
-7
-7
-12
8
-7
14
-2
-8
0
3
-6
8
-6
-5
-2
-5
-2
-8
-3
-7
-4
-3
3
-5
-10
-10
1
-4
13
11
-9
-10
-3
-2
15
1
-5
-12
15
9
8
-9
-3
0
12
-10
9
-2
-2
-11
-7
-6
-2
-11
-5
-3
6
14
-9
5
10
-10
-11
...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 12ms
memory: 11036kb

input:

5 100000
1 5
-1 4
3 -4
4 -2
3 5
8 1
8 1
9 4
4 3
7 2
0 5
10 3
5 4
4 5
4 2
4 1
9 4
4 5
5 2
0 4
1 1
10 2
4 3
10 3
3 1
1 2
7 5
1 4
2 1
6 5
3 5
8 1
10 3
6 5
0 4
8 2
0 5
3 4
1 1
7 5
3 4
6 2
2 4
6 2
4 3
0 4
4 5
9 3
10 1
0 4
3 4
0 3
5 1
0 5
6 1
4 1
8 1
2 1
8 2
4 4
7 2
5 2
1 3
4 1
3 2
7 1
1 5
9 3
1 2
5 3
6 4...

output:

-7
-7
-5
-1
-6
3
-7
-1
-1
-3
-3
-5
-1
-4
4
0
-9
-1
-7
-2
0
-4
3
-1
-3
0
-7
-7
-3
4
-7
3
1
0
-4
1
-5
2
-5
-1
4
-1
-6
-9
4
1
3
-4
3
-5
-3
-7
-1
-7
0
-6
-4
2
-3
-2
-6
2
-6
0
-2
-2
-2
1
-1
-1
-1
-2
3
-9
-1
-4
-6
-2
-8
-5
-5
3
-4
0
1
-3
-3
-7
2
-2
-3
-2
-6
-6
-3
3
-3
3
2
-9
-4
-9
-7
-2
1
-6
-2
-4
-5
0
-4...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 11ms
memory: 9728kb

input:

5 100000
-1 -3
1 -2
4 0
-1 -2
2 4
7 4
10 2
5 3
8 5
9 1
2 5
0 1
3 1
5 5
6 2
2 2
4 1
1 1
1 2
4 4
9 3
9 5
10 2
6 2
0 5
5 5
8 5
8 4
3 1
0 2
6 1
10 3
1 1
6 4
0 2
4 2
4 4
5 5
5 3
0 1
4 1
2 1
7 3
8 5
5 2
2 5
6 5
4 1
7 4
10 3
6 3
0 3
0 2
8 3
3 3
0 1
1 4
7 2
9 3
4 5
6 2
9 2
1 3
7 3
5 4
5 1
6 1
3 4
1 3
5 2
3 ...

output:

6
11
9
10
8
4
-1
2
7
7
3
3
0
2
3
13
11
11
7
2
7
10
7
2
1
5
14
0
5
1
5
3
7
9
-1
3
1
11
10
6
4
8
3
6
14
10
4
1
12
7
-1
0
8
13
6
7
10
5
11
4
4
5
2
5
6
5
6
2
4
6
0
3
8
6
12
4
7
4
-1
11
6
7
2
2
7
2
7
8
8
11
6
4
10
2
7
3
5
3
2
6
6
11
13
0
3
14
6
5
6
11
8
7
2
2
1
6
5
14
8
0
2
2
4
5
7
9
3
9
5
12
9
9
2
3
0
3...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 11ms
memory: 9412kb

input:

5 100000
1 5
0 2
2 3
4 -2
-2 -5
1 3
1 5
6 5
5 3
4 2
3 3
5 3
5 4
7 1
8 3
4 5
10 3
1 4
7 2
9 4
2 4
9 5
5 1
7 2
10 1
2 1
10 5
7 2
0 2
2 5
10 4
1 4
7 1
6 1
8 1
0 3
5 1
0 5
3 5
4 4
8 2
9 4
9 5
9 5
9 5
8 2
7 5
7 2
7 1
8 4
3 2
8 1
0 3
8 1
4 3
9 2
8 4
1 5
8 1
7 4
7 2
9 1
2 3
5 2
7 3
3 1
8 5
8 5
0 4
9 1
7 4
...

output:

1
-1
4
4
3
2
4
4
6
7
2
9
3
6
8
2
7
4
6
9
1
8
6
0
0
9
3
6
5
7
2
4
-2
1
3
7
8
7
7
7
7
5
6
6
7
2
7
2
7
3
8
7
-1
7
6
6
8
2
4
6
2
6
6
4
8
6
7
0
0
2
1
1
4
1
0
2
2
8
8
2
1
4
2
7
7
2
0
4
4
1
3
1
2
6
8
2
3
8
6
2
9
3
1
9
9
1
7
7
-1
6
4
7
7
7
0
2
0
7
8
6
2
3
7
2
0
9
7
2
0
3
-2
3
9
3
0
5
3
6
2
4
2
0
7
0
2
8
5
7...

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 8ms
memory: 11560kb

input:

5 100000
3 -5
1 3
-5 -2
2 5
-3 1
1 5
0 2
2 2
5 3
6 2
4 5
9 1
3 5
1 5
5 2
6 5
5 1
5 5
3 2
10 5
2 1
1 4
3 5
6 1
7 1
2 5
8 4
10 5
7 3
4 4
3 3
10 3
5 1
1 1
8 5
7 5
2 2
9 5
7 2
0 1
6 3
6 3
8 3
0 3
7 3
10 3
1 1
2 1
5 2
7 3
6 1
1 1
6 4
4 4
1 5
1 2
6 3
10 4
9 2
10 4
6 2
2 5
9 4
7 5
6 5
8 3
6 4
5 1
0 2
9 5
4...

output:

-2
1
1
0
1
-1
4
0
-2
0
1
0
0
0
5
1
1
0
1
2
-1
4
5
2
0
-2
5
0
2
3
2
1
4
2
3
1
1
3
-5
2
5
2
1
0
2
1
2
2
0
-2
2
1
6
4
6
1
-1
5
2
1
3
2
0
1
4
-1
-1
0
2
4
0
1
-1
1
3
2
6
0
2
0
3
1
4
1
5
4
1
3
1
3
0
5
2
2
3
-2
4
1
-1
5
0
0
2
-4
5
1
-2
2
5
3
3
-2
1
4
5
3
-4
1
-5
-3
0
0
0
-1
3
-3
3
1
1
1
0
-3
4
-1
2
3
2
3
3...

result:

ok 100000 lines

Test #19:

score: 0
Accepted
time: 19ms
memory: 11880kb

input:

5 100000
-5 5
3 1
-1 0
-4 -1
3 0
722464463 3
160153265 3
515887073 3
792161740 3
700363144 1
257871163 4
985882098 5
622391595 3
497814648 5
257689210 3
424536396 2
57303421 2
893685148 3
887126381 5
92312757 3
909180665 3
90045475 3
843939343 2
921025750 1
551022351 1
316367770 3
939526319 1
745326...

output:

-2
-2
-2
-1
-2
-1
-1
-2
-1
-1
-1
-2
-1
-2
-2
-2
-2
-2
-2
-1
-1
-1
-2
-1
-2
-2
-1
-2
-2
-1
-2
-2
-2
-2
-1
-1
-2
-2
-2
-1
-1
-2
-2
-2
-1
-1
-2
-2
-2
-1
-2
-1
-1
-2
-2
-1
-2
-2
-2
-2
-1
-1
-2
-2
-2
-2
-2
-1
-1
-1
-2
-2
-1
-1
-2
-1
-1
-1
-2
-1
-1
-1
-2
-2
-1
-1
-2
-1
-1
-1
-1
-2
-2
-2
-2
-2
-1
-1
-2
-2
...

result:

ok 100000 lines

Test #20:

score: 0
Accepted
time: 17ms
memory: 9264kb

input:

10 100000
0 -4
2 1
4 -3
-4 6
8 -7
-9 0
10 5
3 4
-8 3
-4 6
1 2
1 3
11 7
1 10
6 5
10 2
14 10
17 3
12 1
14 2
11 4
6 3
7 10
16 5
20 10
5 9
12 6
6 1
16 3
13 2
6 2
15 3
14 2
8 10
4 2
7 9
14 6
6 10
12 6
20 8
6 6
11 3
18 8
8 9
13 1
10 10
12 8
20 5
5 6
14 6
10 4
6 6
0 8
0 3
13 8
8 8
7 1
17 1
8 10
4 9
19 2
19...

output:

1
3
-1
-5
2
-8
-18
-13
-12
-12
-15
-2
-11
-8
-24
-9
-15
-6
-12
-11
-4
-11
-12
-12
-2
-11
-17
-10
-15
-17
-9
-7
-15
-12
-13
-14
-9
-12
-8
-17
-14
-9
3
4
-10
-5
-7
-17
-12
-8
-17
-23
-14
-18
-12
-5
-14
-17
-22
2
-16
3
-13
-9
10
-18
1
-7
-17
8
-19
-14
-11
-12
-18
-3
-14
-11
2
-4
7
-17
-4
-13
-13
-14
-1...

result:

ok 100000 lines

Test #21:

score: 0
Accepted
time: 12ms
memory: 8996kb

input:

10 100000
-3 -8
-8 -8
-7 10
3 -5
1 9
6 1
-2 10
10 5
-3 5
-1 -2
6 3
15 4
13 5
12 8
0 9
0 8
17 6
16 3
15 9
19 10
10 1
4 1
16 5
18 7
7 4
13 1
13 7
17 10
19 4
12 5
19 6
20 2
10 1
20 7
8 6
2 5
5 6
0 1
13 6
20 1
2 1
11 10
17 1
12 7
10 9
1 5
18 6
6 4
11 8
17 7
2 8
16 6
1 8
4 7
15 2
0 6
5 3
1 2
12 7
6 7
8 7...

output:

-1
2
2
2
-3
10
1
1
2
2
1
-1
1
2
2
2
1
2
2
1
1
2
1
2
2
-1
1
-3
1
1
-1
2
2
2
1
0
2
1
1
1
8
2
9
0
1
6
-2
-7
2
2
2
1
1
-2
1
1
2
1
2
2
2
-2
1
-1
-3
2
-1
0
1
0
1
2
1
5
2
2
2
2
2
2
2
1
1
4
2
1
2
2
2
1
1
3
2
1
2
1
2
1
2
1
1
2
-1
-1
2
0
5
1
1
1
0
2
3
2
2
1
1
2
2
0
1
2
2
2
-5
1
2
1
2
1
1
2
1
2
0
1
2
2
-6
-1
1...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 17ms
memory: 9684kb

input:

10 100000
-7 4
-1 6
-5 -5
10 -1
-10 2
-7 -5
-10 7
6 5
-5 -9
-6 -6
20 1
6 3
18 1
17 1
18 9
14 4
15 2
5 4
1 8
7 4
3 1
8 10
0 5
9 7
5 5
11 3
0 7
19 4
2 9
5 1
5 7
4 2
15 7
6 1
7 10
18 5
1 8
11 6
14 9
19 5
14 1
17 8
18 7
4 3
13 8
17 7
12 7
9 8
18 5
0 2
7 2
0 7
5 8
12 6
9 7
4 1
20 4
7 3
9 3
0 3
17 3
20 4
...

output:

-27
1
-25
-24
13
24
14
15
7
17
-10
-14
-10
-19
-15
6
-10
29
-3
-12
-15
3
-25
-13
-13
-28
7
-18
9
-29
-21
23
-28
-1
19
-27
-22
15
-28
-1
6
-10
11
-19
-19
-11
30
2
4
-5
12
30
-8
-23
-9
-1
29
-22
5
17
-29
-15
-12
-14
28
6
23
15
15
9
7
3
-21
-7
-23
-24
-16
26
16
-15
7
1
7
-20
10
-7
6
-23
20
21
-13
-14
-...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 13ms
memory: 9184kb

input:

10 100000
10 0
-5 10
-4 -6
7 3
-7 -9
-4 -7
-10 10
-7 -4
0 8
10 -2
20 9
5 7
19 3
5 6
7 9
14 3
9 5
15 2
1 9
19 1
9 4
7 4
19 3
12 1
20 9
12 6
20 7
4 1
10 2
6 5
20 10
5 4
2 2
13 8
19 8
9 8
1 5
12 6
15 6
5 1
0 5
20 1
3 5
4 6
16 7
8 10
13 6
13 3
18 7
0 10
16 6
18 10
17 10
17 5
12 8
15 6
1 2
17 4
17 10
12 ...

output:

20
-15
15
1
7
10
-16
-20
1
19
8
6
15
12
20
8
-30
6
-15
-13
20
4
-7
-20
-26
-16
-8
8
11
5
-7
20
-10
0
-26
8
9
9
-28
10
12
18
17
-24
-19
11
-6
16
17
12
-14
9
6
-23
5
-15
13
13
6
-15
16
18
14
8
-17
7
-29
13
11
5
-20
8
10
9
-9
2
1
4
7
10
-1
7
-12
-14
13
8
-15
3
-11
14
4
18
-10
-16
20
-19
10
-22
-13
10
2...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 13ms
memory: 9552kb

input:

10 100000
2 -9
3 -10
10 5
-4 7
3 10
8 7
0 7
-7 8
9 -6
9 7
0 5
18 6
16 2
10 7
13 6
2 7
3 1
20 8
9 4
11 8
2 4
11 9
17 6
3 1
18 10
6 2
2 6
2 5
13 3
3 10
7 9
11 8
10 1
16 8
18 4
17 2
18 7
14 6
12 3
12 9
4 1
1 9
1 9
17 6
18 3
20 2
18 3
3 7
4 2
8 4
13 10
2 5
12 10
5 6
7 4
15 1
3 3
2 7
18 2
15 6
10 3
5 7
1...

output:

3
0
0
0
-1
-2
-1
-1
-1
0
-2
0
-1
-1
-1
2
6
3
-1
6
2
0
0
-1
0
-1
0
0
0
-1
-2
8
8
-1
0
0
0
-3
3
0
0
3
-1
3
-1
-1
7
-2
0
-1
0
-3
-1
0
-1
-1
-1
0
-1
-1
0
3
0
3
0
-1
2
-1
9
8
0
-1
-1
-3
0
-1
0
-7
0
0
0
0
0
1
0
-1
-1
-1
0
-1
-1
0
-1
-3
-1
0
3
0
-1
0
-4
0
0
9
0
0
3
-1
-1
-4
-1
1
5
-1
4
-1
-1
3
-3
0
-3
0
0
...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 16ms
memory: 9084kb

input:

10 100000
-2 -1
2 -5
-10 8
-6 7
-7 3
-9 -8
-8 -8
-7 -1
-10 10
5 3
9 6
9 1
0 2
15 10
6 6
19 1
1 3
13 10
9 9
2 6
7 9
15 7
1 6
6 1
20 5
12 10
5 10
8 9
17 8
0 6
18 6
16 10
6 7
15 10
17 8
16 8
18 9
11 6
9 6
11 4
11 7
4 3
3 1
13 3
17 6
11 3
19 4
6 5
3 3
4 10
18 6
7 8
12 2
5 5
9 5
18 5
1 10
16 2
19 5
13 6
...

output:

-18
-11
2
-10
-15
-21
-11
-8
-19
-11
-17
-23
-10
-8
-25
-7
0
-18
-22
-9
-27
-11
-14
-10
-22
-21
-28
-20
-18
-17
-19
-14
-5
-23
-26
-21
-25
-11
-13
1
-27
-12
-10
-10
-14
-23
4
-14
-24
-22
-20
-27
-13
-15
-29
-22
-15
-10
-25
-22
-28
-21
-10
-22
-6
-18
-22
-21
-8
-8
-14
-21
-14
-15
-24
-17
-13
-13
-19
...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 14ms
memory: 11040kb

input:

10 100000
-1 9
7 2
-2 1
3 10
8 10
-6 -3
3 3
9 -7
-1 -2
-7 9
112 7
73 9
118 7
92 9
0 3
189 3
110 10
34 3
105 7
16 9
63 7
12 2
81 9
87 1
160 10
6 5
148 4
54 9
14 5
87 5
57 3
100 4
72 3
166 8
71 7
5 10
189 2
162 3
175 5
73 5
176 8
18 3
24 5
82 9
76 8
199 2
3 6
23 9
49 5
126 2
66 7
45 2
5 7
118 3
48 2
1...

output:

-2
-1
-2
-2
-2
-1
-1
-2
-1
-2
-1
-1
-1
-1
-1
2
-2
-2
-2
-1
-1
-2
-2
-1
-1
-2
-2
-2
-1
-1
-1
-2
-2
-2
-1
-2
-3
-1
-1
-1
-2
-2
-1
-2
-1
-2
-2
-2
-1
-2
-2
-2
0
-2
-2
-1
-1
-2
-1
-1
-1
-2
-1
-1
-2
-2
-1
-1
-1
-1
-2
1
-1
-1
-1
-1
-2
-1
-1
-2
-2
-4
-1
-2
-2
-2
-1
-2
-2
-1
-2
-2
-1
-2
-2
-2
-1
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #27:

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

input:

10 100000
-9 6
1 4
8 8
3 -5
4 -1
-6 0
1 8
-1 -1
-8 1
-1 -4
792434366 4
92102881 1
122696805 2
969313415 10
267007213 3
535748226 6
302806043 1
814393002 2
83864524 7
106160937 2
769231385 3
477853985 5
783986181 2
863038609 10
870475676 4
913155583 1
698243559 5
930099728 6
516688515 8
536420389 1
6...

output:

0
0
-1
-1
-1
0
0
0
0
-1
-1
-1
-1
-1
0
0
-1
0
-1
0
0
-1
0
0
-1
-1
0
-1
-1
0
0
-1
0
-1
0
-1
0
0
0
0
-1
0
-1
0
0
-1
0
0
0
0
0
0
0
0
-1
-1
0
0
0
-1
0
0
0
0
-1
-1
0
-1
0
0
-1
-1
0
0
0
0
-1
-1
0
0
-1
-1
-1
-1
0
-1
0
0
-1
-1
-1
0
0
-1
-1
-1
0
-1
0
0
-1
-1
0
0
-1
-1
-1
-1
0
-1
0
-1
-1
-1
-1
-1
0
0
0
0
0
0
-...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 18ms
memory: 11920kb

input:

100 100000
17 11
-42 -29
58 48
18 48
0 -57
-73 36
41 55
-38 -99
53 -100
-37 -64
-80 4
9 -11
17 99
-94 15
34 -98
34 -61
-45 -10
-47 25
16 -49
16 26
-23 -25
-71 -27
58 -27
-43 46
-12 -36
-70 -85
-76 13
36 56
15 -35
-78 -26
12 -51
-84 97
-63 -23
-93 71
-52 78
47 -29
-58 82
-8 -38
-8 60
23 -50
59 22
-50...

output:

-94
-51
-37
-72
1
-112
2
14
-62
-73
2
-73
-68
-56
-54
-28
-45
-65
-7
-50
-21
21
-40
-96
-80
-73
-108
40
-102
-74
29
-113
-69
-92
-72
78
-58
-14
-37
-77
-28
-93
-54
-13
75
-56
47
-88
62
-56
-10
-69
-115
-123
14
-100
-73
-52
-131
-122
7
-125
-73
-47
-99
-74
-125
-89
-76
44
-54
-85
-98
-74
-106
33
4
-7...

result:

ok 100000 lines

Test #29:

score: 0
Accepted
time: 15ms
memory: 9724kb

input:

100 100000
-1 62
-73 8
49 -3
83 -19
51 55
-28 21
-71 -17
-98 -83
30 -61
23 -88
-17 -78
37 42
85 -50
39 -80
62 -1
-61 -40
-14 73
-95 93
38 -94
86 89
10 91
45 73
79 -58
-3 100
-43 76
88 -74
85 1
-50 -42
71 -34
17 46
-1 -56
35 -59
11 -37
-46 -17
-36 62
41 -93
97 46
45 57
-49 59
-21 -90
-4 98
-80 -48
-5...

output:

-904
-685
-334
-574
-138
-372
7
-346
-864
-769
-966
-424
-79
-937
-677
-497
-885
-131
-263
-742
-448
-604
-843
-949
-768
-843
-680
-263
-655
-612
-471
-801
-839
-752
-22
-977
-90
-876
-77
-671
-781
-819
-884
-165
-382
-147
-402
-875
-514
-164
-174
-59
-932
-742
-709
-659
-435
-171
-410
-795
-906
-76...

result:

ok 100000 lines

Test #30:

score: 0
Accepted
time: 20ms
memory: 8924kb

input:

100 100000
20 35
-27 65
82 -72
43 14
91 41
40 99
20 32
96 -20
-20 -6
34 -81
-88 86
-37 -86
-25 -73
-37 -8
-81 37
-70 1
23 -81
87 -80
39 -33
81 -65
-2 65
99 -10
-38 -53
-80 44
-80 55
-33 31
-72 -40
90 -29
2 47
84 91
-60 -16
83 -100
71 93
12 20
16 3
81 -6
-65 88
-23 -78
53 -90
93 -10
-11 97
59 -60
-29...

output:

-3112
-7720
-8620
-1771
-7662
-4459
-1658
-1272
-9
-9909
-4563
-3582
-1879
-4361
-9807
-458
-2893
-2648
-5421
-380
-4630
-9118
-369
-7526
-2359
-2411
-1830
-2649
-8900
-7570
-1686
-4750
-7341
-7663
-3968
-1601
-3168
-9162
-3410
-2104
-7429
-1523
-3137
-5049
-6979
-1081
-2405
-9672
-4431
-5845
-6515
...

result:

ok 100000 lines

Test #31:

score: 0
Accepted
time: 21ms
memory: 10908kb

input:

100 100000
256155699 -547211095
-774345966 244576889
-489494512 -650843324
-216046407 936858375
-972216842 -994427050
406192309 616950876
69550216 305546853
14578662 -281359711
-183678722 -905559184
-646599996 -891956841
-921646468 677834276
655390404 187442412
-970539166 435720738
-408675181 -56111...

output:

-953694823
538115658
-945311783
-824680761
76415447
500252825
402098669
770070532
733844052
274519145
174329093
-27193765
-524187363
-947840006
-183672912
735929260
13405697
592004500
621473073
365423669
735935490
-913441540
-972219436
76415666
14582949
202399400
-278533900
41417664
149168518
621479...

result:

ok 100000 lines

Test #32:

score: 0
Accepted
time: 22ms
memory: 11904kb

input:

100 100000
744617759 158238326
340923698 -360072198
-991138470 -529277242
-199896385 -586829407
-148984877 -310206000
570899918 -740737853
-132209688 157071629
791203118 -821670121
204761796 679231292
900497734 395825676
63231449 -962828753
-648556788 -838850790
-767269417 -825933974
771859635 26616...

output:

-48307732
-607353993
951677097
483017978
955397673
-226366120
-226322194
-254790396
428396155
-21220357
771912311
-362170287
-199939924
173528991
-767251116
-563620453
340824963
568153528
-7081793
474455145
568202413
794156188
-132239964
433713221
-101885848
765688146
-900892201
89197107
63266605
-7...

result:

ok 100000 lines

Test #33:

score: 0
Accepted
time: 16ms
memory: 11820kb

input:

1000 100000
-434707201 -683661427
384781359 195621116
-951981420 781679258
-376074812 -581864278
428495470 482257122
-485361571 -231980232
318018358 546654220
755178326 -379948948
846857455 396009876
884142897 612544667
-830021241 124329110
-341821805 994936687
942683906 461913370
486906068 10143728...

output:

593580392
707881878
112696715
994093392
621249962
-273575528
72993016
881726697
348571700
-949352699
253246269
-120196549
400932945
-102612996
-190241830
549794901
-692235959
-881736891
800235674
975401539
-448302720
865442554
773904010
-995352295
-784611782
965589306
552963158
569880354
379631471
2...

result:

ok 100000 lines

Test #34:

score: 0
Accepted
time: 22ms
memory: 9624kb

input:

1000 100000
996999716 -34234903
400525215 -674912568
-55411236 222777222
-981748676 -408580972
-796406973 653686899
776754580 -948838675
9273709 955106065
554774087 449419555
-546907422 -190859901
-215040542 638122164
-967305902 64747929
-838776191 -11517133
425018184 -75393651
-268162808 533689787
...

output:

189789496
-757817007
-823093232
688388823
-327622928
526922189
-77145252
-125098514
759496
526926500
318655834
812773016
-604515294
-242449662
-788823122
507921972
-302596104
94285007
-992017072
880319426
569135406
144925975
456639566
626188103
463369829
456638677
-414922995
972068551
803213522
1250...

result:

ok 100000 lines

Test #35:

score: 0
Accepted
time: 24ms
memory: 9960kb

input:

10000 100000
451772880 -156086078
-950254772 927910017
891939666 -469915736
-860487758 -532719735
-567623395 -579566135
-482938321 -174746207
-72418614 609693111
530736894 468835873
-237259199 627247518
-995730942 -804582695
365316524 882959515
-808769910 -179962205
361830722 622888461
-48319332 235...

output:

-204527960
-378903070
62255589
852825025
-346701865
-950657488
490542991
534306652
483988290
-413237666
870710952
-210226764
635171030
935727328
-882351403
758421787
73536360
-586412042
814007077
470300624
-26222194
505354794
517257442
-741767895
-367426807
890150064
-982242426
117830210
58830549
-8...

result:

ok 100000 lines

Test #36:

score: 0
Accepted
time: 31ms
memory: 10104kb

input:

100000 100000
-4 3
-3 6
-1 2
-1 2
-4 10
5 -1
4 -6
2 -3
-5 -1
-9 5
-9 -9
0 -3
9 7
-6 9
9 -3
-4 10
2 -10
8 -4
4 -8
-3 5
-5 1
2 9
7 1
5 -2
-5 3
-5 -2
-3 2
-4 1
10 1
10 6
3 3
-5 -3
-1 10
1 -8
6 -3
6 -4
-3 -6
-1 5
0 2
-10 10
-7 2
-8 5
5 -8
1 -8
-6 -3
2 -4
9 6
3 -1
9 -6
-4 8
7 7
-4 6
7 -2
9 -9
8 5
-5 4
5 ...

output:

-73385393
-61734787
93333112
-61522813
-10397170
-26327062
17805567
-2799682
-23095102
-8937987
-28735369
-68867844
1972248
-3874404
-75612832
-17194657
-13848421
-24694779
-66719951
-61793164
-70026215
-42159667
-21987872
-63862344
11806371
-70847717
-34510812
-46274918
-90589299
-95205712
-5779112...

result:

ok 100000 lines

Test #37:

score: 0
Accepted
time: 49ms
memory: 12020kb

input:

100000 100000
9 944359534
-2 277227375
8 -773149008
8 628295871
-4 -821907488
-2 -188575447
-1 -929530780
0 448989146
-4 -581847871
-7 846839738
5 628096431
1 775236356
-3 -185562343
-4 -939766393
5 694969897
-4 -864927003
-10 -841934125
-9 114196285
3 323366808
-9 471555976
-3 -504782745
1 65348899...

output:

270365985
150639067
468932042
297078804
891055722
924219699
574873537
677775650
144747048
681510473
309408490
35892574
380081715
825222137
581732087
196491670
496169337
355766126
636839475
576364386
758553411
517150283
608493572
854896692
613406885
434294076
922734082
224861074
380454645
688705341
2...

result:

ok 100000 lines

Test #38:

score: -100
Time Limit Exceeded

input:

100000 100000
-296460011 10
-748228463 8
549227188 -8
-925202056 -7
727222945 5
592939595 -6
765262067 -1
921188558 6
-199556343 9
-574817362 9
400002615 6
993984094 -7
-330466551 3
300272045 -6
-927024342 -4
-221508167 -1
85469524 -4
-442213879 5
792956663 -7
-575779456 9
604558700 -5
167721540 1
1...

output:


result: