CSES - APIO 2012 - Results
Submission details
Task:Kunai
Sender:Olli
Submission time:2019-03-16 17:38:48 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED30
#3ACCEPTED60
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1, 2, 3details
#2ACCEPTED0.07 s1, 2, 3details
#3ACCEPTED0.06 s1, 2, 3details
#4ACCEPTED0.07 s1, 2, 3details
#5ACCEPTED0.07 s1, 2, 3details
#6ACCEPTED0.07 s1, 2, 3details
#7ACCEPTED0.07 s2, 3details
#8ACCEPTED0.07 s2, 3details
#9ACCEPTED0.07 s2, 3details
#10ACCEPTED0.07 s2, 3details
#11ACCEPTED0.06 s2, 3details
#12ACCEPTED0.07 s2, 3details
#13ACCEPTED0.07 s2, 3details
#14ACCEPTED0.06 s2, 3details
#15ACCEPTED0.06 s2, 3details
#16ACCEPTED0.07 s2, 3details
#17ACCEPTED0.07 s2, 3details
#18ACCEPTED0.06 s2, 3details
#19ACCEPTED0.06 s2, 3details
#20ACCEPTED0.06 s2, 3details
#21ACCEPTED0.06 s2, 3details
#22ACCEPTED0.62 s3details
#23ACCEPTED0.49 s3details
#24ACCEPTED0.51 s3details
#25ACCEPTED0.61 s3details
#26ACCEPTED0.60 s3details
#27ACCEPTED0.68 s3details
#28ACCEPTED0.62 s3details
#29ACCEPTED0.49 s3details
#30ACCEPTED0.52 s3details
#31ACCEPTED0.64 s3details
#32ACCEPTED0.58 s3details
#33ACCEPTED0.68 s3details
#34ACCEPTED0.63 s3details
#35ACCEPTED0.51 s3details
#36ACCEPTED0.51 s3details
#37ACCEPTED0.62 s3details
#38ACCEPTED0.58 s3details
#39ACCEPTED0.68 s3details
#40ACCEPTED0.63 s3details
#41ACCEPTED0.49 s3details
#42ACCEPTED0.51 s3details
#43ACCEPTED0.64 s3details
#44ACCEPTED0.57 s3details
#45ACCEPTED0.70 s3details
#46ACCEPTED0.62 s3details
#47ACCEPTED0.51 s3details
#48ACCEPTED0.53 s3details
#49ACCEPTED0.62 s3details
#50ACCEPTED0.59 s3details
#51ACCEPTED0.68 s3details
#52ACCEPTED0.62 s3details
#53ACCEPTED0.51 s3details
#54ACCEPTED0.51 s3details
#55ACCEPTED0.65 s3details
#56ACCEPTED0.58 s3details
#57ACCEPTED0.69 s3details

Compiler report

input/code.cpp: In function 'll nextColl(ll)':
input/code.cpp:187:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0; j < del.size(); ++j) {
                   ~~^~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:342:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 1; j < ho[i].size(); ++j) {
                  ~~^~~~~~~~~~~~~~
input/code.cpp:390:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 1; j < ve[i].size(); ++j) {
                  ~~^~~~~~~~~~~~~~
input/code.cpp:430:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < hor.size(); ++i) {
                 ~~^~~~~~~~~~~~
input/code.cpp:434:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ver.size(); ++i) {
                 ~~^~~~~~~~...

Code

#include <iostream>
#include <set>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

unordered_map<ll, ll> ma;

const int N = 1e5 + 5;
const ll INF = 1e18;
const ll BO = 1e10;

set<pair<pll, ll> > s[3*N][4];


ll has(pll X) {
	ll t = X.second;
	if(t == 0) {
		return X.first;
	}
	if(t == INF) {
		return INF + X.first;
	}
	if(t == 1) {
		return X.first + BO;
	}
	return X.first - BO;
}

vector<ll> v[N];

ll miColl[N];
bool de[N];

void delet(ll i) {
	de[i] = true;
	ll x = v[i][0];
	ll y = v[i][1];
	ll d = v[i][2];
	ll indA = ma[has({x-y, -1})];
	ll indB = ma[has({x+y, 1})];
	ll indC;
	if(d%2 == 0) {
		indC = ma[has({y, 0})];
	} else {
		indC = ma[has({x, INF})];
	}
	s[indA][d].erase({{x, y}, i});
	s[indB][d].erase({{x, y}, i});
	s[indC][d].erase({{x, y}, i});		
}

ll nextColl(ll i) {
	if(de[i]) return miColl[i];

	//The time when arrow i hits something
	ll x = v[i][0];
	ll y = v[i][1];
	ll d = v[i][2];
	ll indA = ma[has({x-y, -1})];
	ll indB = ma[has({x+y, 1})];
	ll indC;
	if(d%2 == 0) {
		indC = ma[has({y, 0})];
	} else {
		indC = ma[has({x, INF})];
	}
	ll dA, dB, dC;
	dC = (d+2)%4;

	if(d == 0) {
		dA = 1;
		dB = 3;
	}
	if(d == 1) {
		dA = 0;
		dB = 2;
	}
	if(d == 2) {
		dA = 3;
		dB = 1;
	}
	if(d == 3) {
		dA = 2;
		dB = 0;
	}

	while(true) {
		pair<pll, ll> candA, candB, candC;
		candA = {{INF, INF}, INF};
		candB = {{INF, INF}, INF};
		candC = {{INF, INF}, INF};
		if(s[indA][dA].size() > 0) {
			auto it = s[indA][dA].lower_bound({{x, -1}, -1});
			if(d == 1 || d == 2) {
				if(it != s[indA][dA].begin()) {
					--it;
					candA = *it;
				}
			} else {
				if(it != s[indA][dA].end()) {
					candA = *it;
				}
			}
		}
		if(s[indB][dB].size() > 0) {
			auto it = s[indB][dB].lower_bound({{x, -1}, -1});
			if(d == 2 || d == 3) {
				if(it != s[indB][dB].begin()) {
					--it;
					candB = *it;
				}
			} else {
				if(it != s[indB][dB].end()) {
					candB = *it;
				}
			}
		}
		if(s[indC][dC].size() > 0) {
			if(d%2 == 0) {
				auto it = s[indC][dC].lower_bound({{x, -1}, -1});
				if(d == 2) {
					if(it != s[indC][dC].begin()) {
						--it;
						candC = *it;
					}
				} else {
					if(it != s[indC][dC].end()) {
						candC = *it;
					}
				}
			} else {
				auto it = s[indC][dC].lower_bound({{x, y}, -1});
				if(d == 1) {
					if(it != s[indC][dC].begin()) {
						--it;
						candC = *it;
					}
				} else {
					if(it != s[indC][dC].end()) {
						candC = *it;
					}
				}
			}
		}

		ll timeA = 2*abs(x - candA.first.first);
		ll timeB = 2*abs(x - candB.first.first);
		ll timeC;
		if(d%2 == 0) {
			timeC = abs(x - candC.first.first);
		} else {
			timeC = abs(y - candC.first.second);
		}
		ll mi = min(timeA, timeB);
		mi = min(mi, timeC);
		if(mi >= BO) {
			miColl[i] = INF;
			delet(i);
			return INF;
		}
		vector<ll> del;
		miColl[i] = max(miColl[i], mi);
		if(timeA == mi) {
			if(miColl[candA.second] >= mi || nextColl(candA.second) == mi) {
				del.push_back(candA.second);
			}
		}
		if(timeB == mi) {
			if(miColl[candB.second] >= mi || nextColl(candB.second) == mi) {
				del.push_back(candB.second);
			}
		}
		if(timeC == mi) {
			if(miColl[candC.second] >= mi || nextColl(candC.second) == mi) {
				del.push_back(candC.second);
			}
		}
		
		if(del.size() > 0) {
			del.push_back(i);
			for(int j = 0; j < del.size(); ++j) {
				miColl[del[j]] = mi;
				delet(del[j]);
			}
			return mi;
		}
	}
	return INF;
}

vector<pair<pll, ll> > hor;
vector<pair<ll, pll> > ver;

vector<pll> ho[N];
vector<pll> ve[N];

unordered_map<ll, ll> ano[2];
vector<ll> ys;
vector<ll> xs;


vector<ll> fin;
unordered_map<ll, ll> fina;

bool active[3*N];

const ll M = 524288;

ll tree[2*M];

void update(ll k, ll x) {
	k+=M;
	tree[k] += x;
	k/=2;
	while(k > 0) {
		tree[k] = tree[2*k] + tree[2*k + 1];
		k /= 2;
	}
}

ll sum(ll a, ll b) {
	a+=M; b+=M;
	ll su = 0;
	while(a <= b) {
		if(a%2 == 1) {
			su += tree[a];
			++a;
		}
		if(b%2 == 0) {
			su += tree[b];
			--b;
		}
		a/=2; b/=2;
	}
	return su;
}

int main() {
	ll w, h;
	cin >> w >> h;
	ll n;
	cin >> n;
	int ind = 1;
	for(int i = 1; i <= n; ++i) {
		ll x, y, d;
		cin >> x >> y >> d;
		v[i].push_back(x); v[i].push_back(y); v[i].push_back(d);
		ll a = x - y;
		ll b = x + y;
		ll A = has({a, -1});
		ll B = has({b, 1});
		ll C;
		if(d%2 == 0) {
			C = has({y, 0});
		} else {
			C = has({x, INF});
		}

		if(ma[A] == 0) {
			ma[A] = ind;
			s[ind][d].insert({{x, y}, i});
			++ind;
		} else {
			s[ma[A]][d].insert({{x, y}, i});
		}
		if(ma[B] == 0) {
			ma[B] = ind;
			s[ind][d].insert({{x, y}, i});
			++ind;
		} else {
			s[ma[B]][d].insert({{x, y}, i});
		}
		if(ma[C] == 0) {
			ma[C] = ind;
			s[ind][d].insert({{x, y}, i});
			++ind;
		} else {
			s[ma[C]][d].insert({{x, y}, i});
		}
	}

	for(int i = 1; i <= n; ++i) {
		nextColl(i);
	}


	int ind0 = 1;
	int ind1 = 1;
	for(int i = 1; i <= n; ++i) {
		ll x = v[i][0];
		ll y = v[i][1];
		ll d = v[i][2];
		if(d%2 == 0) {
			int inde = ano[0][y];
			pll pai;
			if(d == 0) {
				pai = {x, x+miColl[i]/2};
			} else {
				pai = {x - miColl[i]/2, x};
			}
			if(inde != 0) {
				ho[inde].push_back(pai);
			} else {
				ano[0][y] = ind0;
				ys.push_back(y);
				ho[ind0].push_back(pai);
				++ind0;
			}
		} else {
			pll pai;
			if(d == 1) {
				pai = {y - miColl[i]/2, y};
			} else {
				pai = {y, y+miColl[i]/2};
			}
			int inde = ano[1][x];
			if(inde != 0) {
				ve[inde].push_back(pai);
			} else {
				ano[1][x] = ind1;
				xs.push_back(x);
				ve[ind1].push_back(pai);
				++ind1;
			}
		}
	}


	ll FINALANS = 0;

	for(int i = 1; i < ind0; ++i) {
		sort(ho[i].begin(), ho[i].end());
		ll y = ys[i-1];
		ll be = ho[i][0].first;
		ll en = ho[i][0].second;
		for(int j = 1; j < ho[i].size(); ++j) {
			ll nBe = ho[i][j].first;
			ll nEn = ho[i][j].second;
			if(nBe > en + 1) {
				hor.push_back({{be, en}, y});

				if(be < 0) {
					if(en >= BO) {
						FINALANS += w;
					} else {
						FINALANS += en;
					}
				} else {
					if(en >= BO) {
						FINALANS += w - be + 1;
					} else {
						FINALANS += en - be + 1;
					}
				}
				be = nBe;
				en = nEn;
			} else {
				en = max(en, nEn);
			}
		}
		hor.push_back({{be, en}, y});
		if(be < 0) {
			if(en >= BO) {
				FINALANS += w;
			} else {
				FINALANS += en;
			}
		} else {
			if(en >= BO) {
				FINALANS += w - be + 1;
			} else {
				FINALANS += en - be + 1;
			}
		}
	}



	for(int i = 1; i < ind1; ++i) {
		sort(ve[i].begin(), ve[i].end());
		ll x = xs[i-1];
		ll be = ve[i][0].first;
		ll en = ve[i][0].second;
		for(int j = 1; j < ve[i].size(); ++j) {
			ll nBe = ve[i][j].first;
			ll nEn = ve[i][j].second;
			if(nBe > en + 1) {
				ver.push_back({x, {be, en}});
				if(be < 0) {
					if(en >= BO) {
						FINALANS += h;
					} else {
						FINALANS += en;
					}
				} else {
					if(en >= BO) {
						FINALANS += h - be + 1;
					} else {
						FINALANS += en - be + 1;
					}
				}
				be = nBe;
				en = nEn;

			} else {
				en = max(en, nEn);
			}
		}
		ver.push_back({x, {be, en}});
		if(be < 0) {
			if(en >= BO) {
				FINALANS += h;
			} else {
				FINALANS += en;
			}
		} else {
			if(en >= BO) {
				FINALANS += h - be + 1;
			} else {
				FINALANS += en - be + 1;
			}
		}		
	}
	for(int i = 0; i < hor.size(); ++i) {
		ll y = hor[i].second;
		fin.push_back(y);
	}
	for(int i = 0; i < ver.size(); ++i) {
		ll y = ver[i].second.first;
		fin.push_back(y);
		y = ver[i].second.second;
		fin.push_back(y);
	}

	sort(fin.begin(), fin.end());
	ind = 1;

	for(int i = 0; i < fin.size(); ++i) {
		if(fina[fin[i]] == 0) {
			fina[fin[i]] = ind;
			++ind;
		}
	}


	vector<pair<pll, pll> > even;
	for(int i = 0; i < hor.size(); ++i) {
		ll y = hor[i].second;
		y = fina[y];
		ll x1 = hor[i].first.first;
		ll x2 = hor[i].first.second;
		even.push_back({{x1, 1}, {y, INF}});
		even.push_back({{x2, 3}, {y, INF}});
	}

	for(int i = 0; i < ver.size(); ++i) {
		ll y1 = ver[i].second.first;
		ll y2 = ver[i].second.second;
		y1 = fina[y1];
		y2 = fina[y2];
		ll x = ver[i].first;
		even.push_back({{x, 2}, {y1, y2}});
	}

	sort(even.begin(), even.end());

	ll inter = 0;

	for(int i = 0; i < even.size(); ++i) {
		pair<pll, pll> p = even[i];
		ll type = p.first.second;
		if(type == 2) {
			ll y1 = p.second.first;
			ll y2 = p.second.second;
			inter += sum(y1, y2);
		} else {
			ll y = p.second.first;
			ll cha = 2 - type;
			update(y, cha);
		}
	}

	cout << FINALANS - inter << "\n";

}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
1000
395 147 2
312 997 3
575 326 1
...

correct output
351232

user output
351232

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
1000
613 767 3
847 338 0
65 684 2
...

correct output
341331

user output
341331

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
1000
545 235 1
751 441 2
393 441 0
...

correct output
2332

user output
2332

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
1000
508 691 1
88 522 2
594 543 2
...

correct output
91488

user output
91488

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
987 863
1000
337 215 1
426 724 0
314 667 2
...

correct output
304733

user output
304733

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
1000
134 885 1
99 920 2
853 166 1
...

correct output
50224

user output
50224

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
622691628 400169593 1
88321523 864579498 2
112795648 764418241 2
...

correct output
510718011549

user output
510718011549

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
434001832 559301213 3
434001832 429662335 3
406314803 401975306 0
...

correct output
2291715446

user output
2291715446

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
147530776 854510 0
356276711 182273622 1
892824604 150655760 0
...

correct output
88532373705

user output
88532373705

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
987285921 863112267
1000
470324395 497062190 3
442802251 378184556 2
119175366 201807368 0
...

correct output
455873598338

user output
455873598338

Test 11

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
909404004 181534702 2
484518608 606420098 1
218950493 871988213 2
...

correct output
27655301105

user output
27655301105

Test 12

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
773022132 211005023 2
999330973 728414009 3
788418382 315547103 0
...

correct output
481150067104

user output
481150067104

Test 13

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
50373611 409198926 0
450050051 9522486 1
450050051 329920540 1
...

correct output
2849288541

user output
2849288541

Test 14

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
541475743 439195694 1
704685352 411213621 0
541475743 919546919 3
...

correct output
82091697388

user output
82091697388

Test 15

Group: 2, 3

Verdict: ACCEPTED

input
987285921 863112267
1000
620654899 592269001 0
206328053 105131334 2
782084021 752936230 2
...

correct output
467023572658

user output
467023572658

Test 16

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
561552965 495764463 2
359727447 697589981 2
465263943 592053485 1
...

correct output
25388296783

user output
25388296783

Test 17

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
589070350 565712291 0
841681509 118453997 3
572166871 967138461 1
...

correct output
508058157318

user output
508058157318

Test 18

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
466098270 174395571 1
708125245 416422546 2
596968012 416422546 2
...

correct output
4246358023

user output
4246358023

Test 19

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
384004974 137019999 3
407193458 545911984 3
402045605 540764131 0
...

correct output
79305870521

user output
79305870521

Test 20

Group: 2, 3

Verdict: ACCEPTED

input
987285921 863112267
1000
449417196 662604888 1
48678588 632059056 2
565832510 404527588 0
...

correct output
463406908716

user output
463406908716

Test 21

Group: 2, 3

Verdict: ACCEPTED

input
1000000000 1000000000
1000
475820435 547875716 2
167693733 856002418 1
449458888 574237263 1
...

correct output
41055207693

user output
41055207693

Test 22

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
663138948 732069328 2
335193741 619561225 2
228849515 139776269 1
...

correct output
49941362127608

user output
49941362127608

Test 23

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
566759277 849622939 3
250197041 533060703 0
852403088 533060703 2
...

correct output
39994458607

user output
39994458607

Test 24

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
856953368 114383681 3
850373774 417536320 2
506532450 913767411 3
...

correct output
8477051419311

user output
8477051419311

Test 25

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
750078204 431759396 3
735927921 507211726 2
89989784 643673044 3
...

correct output
46150537505050

user output
46150537505050

Test 26

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
942 795 2
446 469 1
768 800 0
...

correct output
1054717

user output
1054717

Test 27

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
137117336 890747686 1
384041069 643823953 1
29726055 998138967 2
...

correct output
476523338176

user output
476523338176

Test 28

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
331703518 86776596 3
177544276 9601214 2
12598004 791367628 2
...

correct output
50126205700926

user output
50126205700926

Test 29

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
276411077 540284323 0
435323848 381371552 1
435323848 625003151 3
...

correct output
56095255153

user output
56095255153

Test 30

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
908028273 567997813 2
572250164 903775922 3
236472055 567997813 0
...

correct output
8253896297688

user output
8253896297688

Test 31

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
63453291 200913904 1
262979526 382364396 3
428521173 461559387 3
...

correct output
46229727046871

user output
46229727046871

Test 32

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
511 323 0
956 419 1
81 48 0
...

correct output
1055185

user output
1055185

Test 33

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
657870508 354607304 2
491838553 520639259 1
660690262 351787550 2
...

correct output
507526568312

user output
507526568312

Test 34

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
147751737 294000216 1
19894811 252157555 2
943830141 442958986 3
...

correct output
49957015480521

user output
49957015480521

Test 35

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
450108760 547507943 0
451372067 546244636 1
315061883 547507943 0
...

correct output
62352343214

user output
62352343214

Test 36

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
93427566 250549170 3
556201946 314045627 1
655446864 413290545 2
...

correct output
8258222391750

user output
8258222391750

Test 37

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
706589704 692508905 3
105330061 488033004 3
212269662 113150745 0
...

correct output
46221255626007

user output
46221255626007

Test 38

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
746 684 2
99 227 1
880 315 1
...

correct output
1056052

user output
1056052

Test 39

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
72121795 956404235 1
977020574 51505456 2
435320669 593205361 1
...

correct output
407410639854

user output
407410639854

Test 40

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
482034022 897612026 0
941070079 873435725 2
835704386 342496489 0
...

correct output
49919072427797

user output
49919072427797

Test 41

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
519936637 258601371 1
763550477 502215211 2
519936637 745829051 3
...

correct output
44497041760

user output
44497041760

Test 42

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
487637375 302473543 1
591230757 406066925 2
487637375 509660307 3
...

correct output
8307354131507

user output
8307354131507

Test 43

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
856920207 366456602 0
856141785 636238896 3
875178317 664279607 2
...

correct output
46179682182549

user output
46179682182549

Test 44

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
17 190 3
868 463 2
483 978 3
...

correct output
1056218

user output
1056218

Test 45

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
391529494 653705763 1
112895171 932340086 1
69191361 976043896 2
...

correct output
568892059623

user output
568892059623

Test 46

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
298082241 104835646 2
783420614 115992066 2
619452875 994087848 1
...

correct output
49997496156308

user output
49997496156308

Test 47

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
621949231 509438831 2
535984856 595403206 3
450020481 509438831 0
...

correct output
51467675232

user output
51467675232

Test 48

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
877374451 447747847 2
537306871 787815427 3
197239291 447747847 0
...

correct output
8314959264748

user output
8314959264748

Test 49

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
685682505 858051603 1
698492320 741907504 3
658926806 315870965 3
...

correct output
46246375985396

user output
46246375985396

Test 50

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
314 212 3
610 176 2
139 78 1
...

correct output
1056041

user output
1056041

Test 51

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
900809794 96891967 1
784333884 263748228 2
62490464 985591648 2
...

correct output
442226775128

user output
442226775128

Test 52

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
114130459 459542914 0
625771149 506032054 2
403201364 645679206 2
...

correct output
50026483129307

user output
50026483129307

Test 53

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
880347982 516662451 2
552033074 844977359 3
223718166 516662451 0
...

correct output
48456523650

user output
48456523650

Test 54

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
586976368 613454196 3
410434589 436912417 0
586976368 260370638 1
...

correct output
8303589567989

user output
8303589567989

Test 55

Group: 3

Verdict: ACCEPTED

input
987285921 863112267
100000
170295294 135611110 1
383193391 511391566 3
226423785 40312796 2
...

correct output
46287075850758

user output
46287075850758

Test 56

Group: 3

Verdict: ACCEPTED

input
1027 1039
100000
612 757 0
352 412 2
823 741 2
...

correct output
1055250

user output
1055250

Test 57

Group: 3

Verdict: ACCEPTED

input
1000000000 1000000000
100000
652150584 446262032 1
811568386 286844230 1
492561855 605850761 1
...

correct output
614169021291

user output
614169021291