QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134177#4272. Phone Plansblackyuki6 683ms64176kbC++144.6kb2023-08-03 12:10:252023-08-03 12:10:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-03 12:10:29]
  • 评测
  • 测评结果:6
  • 用时:683ms
  • 内存:64176kb
  • [2023-08-03 12:10:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define pb emplace_back
#define lb(v,k) (ll)(lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (ll)(upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define popcnt __builtin_popcountll
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n,K;vi m(2);cin>>n>>m[0]>>m[1]>>K;
    if(K==0)dame(0);
    vvi cost(2);
    vvp nex(2);
    vvvi con(2);
    rep(tt,2){
        vector<PP> edge(m[tt]);
        rep(i,m[tt]){
            ll a,b,c;cin>>a>>b>>c;
            edge[i]=PP(c,a-1,b-1);
        }
        sort(all(edge));
        vi par(n);rep(i,n)par[i]=i;
        vvi gr(n);rep(i,n)gr[i].pb(i);
        for(auto x:edge){
            ll t,a,b;tie(t,a,b)=x;
            if(par[a]==par[b])continue;
            cost[tt].pb(t);
            a=par[a];b=par[b];
            if(gr[a].size()>gr[b].size())swap(a,b);
            nex[tt].pb(a,b);
            con[tt].pb(gr[a]);
            for(ll x:gr[a])gr[b].pb(x);
            for(ll x:gr[a])par[x]=b;
        }
    }
    vi cntA(n,1),cntB(n,1);
    map<P,ll> cntC;
    rep(i,n)cntC[P(i,i)]=1;
    ll a=0,b=0,c=0;
    vvi par(2,vi(n));rep(i,2)rep(j,n)par[i][j]=j;
    auto merge=[&](ll tt,ll i){
        for(ll x:con[tt][i]){
            ll A=par[0][x],B=par[1][x];
            cntA[A]--;cntB[B]--;cntC[P(A,B)]--;
            a-=cntA[A];b-=cntB[B];c-=cntC[P(A,B)];

            if(tt==0)assert(A==nex[tt][i].fi);
            else assert(B==nex[tt][i].fi);
            par[tt][x]=nex[tt][i].se;

            A=par[0][x];B=par[1][x];
            a+=cntA[A];b+=cntB[B];c+=cntC[P(A,B)];
            cntA[A]++;cntB[B]++;cntC[P(A,B)]++;
        }
    };
    auto unmerge=[&](ll tt,ll i){
        for(ll x:con[tt][i]){
            ll A=par[0][x],B=par[1][x];
            cntA[A]--;cntB[B]--;cntC[P(A,B)]--;
            a-=cntA[A];b-=cntB[B];c-=cntC[P(A,B)];

            if(tt==0)assert(A==nex[tt][i].se);
            else assert(B==nex[tt][i].se);
            par[tt][x]=nex[tt][i].fi;

            A=par[0][x];B=par[1][x];
            a+=cntA[A];b+=cntB[B];c+=cntC[P(A,B)];
            cntA[A]++;cntB[B]++;cntC[P(A,B)]++;
        }
    };
    ll l=0;
    while(l<cost[1].size()&&a+b-c<K){
        merge(1,l);l++;
    }
    ll ans=inf;
    if(a+b-c>=K)ans=cost[1][l-1];
    rep(i,cost[0].size()){
        merge(0,i);
        while(a+b-c>=K&&l>0){
            unmerge(1,l-1);
            l--;
        }
        if(l<cost[1].size()){
            chmin(ans,cost[0][i]+cost[1][l]);
            if(a+b-c>=K)chmin(ans,cost[0][i]);
        }
    }
    if(ans<inf)out(ans);
    else out(-1);
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 1ms
memory: 3464kb

input:

6 4 4 9
1 2 1
2 3 2
1 4 3
3 4 4
5 6 40
1 5 30
2 6 20
3 6 10

output:

33

result:

ok single line: '33'

Test #2:

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

input:

1 0 0 0

output:

0

result:

ok single line: '0'

Test #3:

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

input:

2 0 0 1

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

2 10 10 1
1 1 915886339
2 2 430624192
1 1 879808770
1 2 577221915
1 1 439429731
1 2 304911826
1 1 148009333
1 2 51122687
1 1 558282772
1 2 421196385
2 1 436692145
1 2 654020563
2 2 162573477
2 2 989531779
1 1 646687051
2 2 549037477
2 2 699532275
1 1 679375858
2 1 83352965
2 1 415698228

output:

51122687

result:

ok single line: '51122687'

Test #5:

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

input:

2 10 10 1
1 1 1000000000
1 2 1000000000
2 2 1000000000
2 1 1000000000
1 2 1000000000
1 1 1000000000
1 2 1000000000
2 2 1000000000
1 2 1000000000
1 2 1000000000
2 1 1000000000
1 2 1000000000
2 1 1000000000
2 2 1000000000
1 2 1000000000
2 2 1000000000
1 1 1000000000
1 1 1000000000
2 2 1000000000
1 2 1...

output:

1000000000

result:

ok single line: '1000000000'

Test #6:

score: 0
Accepted
time: 111ms
memory: 8308kb

input:

2000 0 200000 1199833
636 1231 120395621
689 1640 497332138
1861 1980 798839749
560 1283 560726905
1332 328 431171189
1203 1764 466367210
1102 347 317109768
1462 789 761470540
350 1093 551905741
1718 1047 548650524
51 546 56733461
58 1519 744207013
826 956 943929583
1969 207 238061756
99 47 99683567...

output:

9768257

result:

ok single line: '9768257'

Test #7:

score: -6
Wrong Answer
time: 105ms
memory: 8072kb

input:

2000 200000 0 1937051
1325 1770 628367155
105 1670 728177982
358 778 959944062
826 1691 651665248
1119 1906 382208628
1684 1232 677646622
807 265 902880211
1685 1660 405567549
1853 1982 988679307
1241 1054 385406922
862 1049 356441384
1837 673 443580113
1082 1795 738355567
1703 663 221254144
1792 84...

output:

-1

result:

wrong answer 1st lines differ - expected: '20263921', found: '-1'

Subtask #2:

score: 0
Wrong Answer

Test #53:

score: 5
Accepted
time: 638ms
memory: 55208kb

input:

200000 100000 100000 7628995
23677 113459 839167193
165893 15365 669621527
26287 109671 214795757
156871 136723 522277985
9957 100463 806718116
104783 161385 156110975
184577 92225 545172629
57373 130083 980035338
167231 49597 919886451
115601 24325 717233004
99413 141311 737488449
83437 62759 76873...

output:

502149991

result:

ok single line: '502149991'

Test #54:

score: 0
Accepted
time: 434ms
memory: 44768kb

input:

200000 200000 87 2694
197233 86229 181875035
85167 196363 328068482
177795 65479 693403443
119609 181977 588691030
115815 139981 486110961
92473 20483 199129328
166989 95385 210368646
98095 54673 357307451
122543 94377 907487846
46611 80735 71787832
158893 117071 521262491
92051 104395 365725125
142...

output:

11965880

result:

ok single line: '11965880'

Test #55:

score: 0
Accepted
time: 194ms
memory: 35500kb

input:

200000 103 199999 1593
75203 150269 64
68675 175215 100
176335 11837 94
33623 63279 56
16617 86741 63
167219 52783 58
6575 134399 1
144065 114171 2
32625 99459 50
35311 152509 36
132975 12211 8
175275 107903 23
17477 21319 95
157759 66683 71
34577 78339 26
154003 26703 18
187863 90945 74
116071 1089...

output:

7037526

result:

ok single line: '7037526'

Test #56:

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

input:

1 0 0 0

output:

0

result:

ok single line: '0'

Test #57:

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

input:

1 1 0 0
1 1 1

output:

0

result:

ok single line: '0'

Test #58:

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

input:

2 0 0 1

output:

-1

result:

ok single line: '-1'

Test #59:

score: 0
Accepted
time: 170ms
memory: 8212kb

input:

2 200000 200000 1
1 1 540311820
1 1 825820034
1 1 555157427
1 1 288420080
1 1 672135630
1 1 726777321
1 1 526670467
1 1 959728057
1 1 146842949
1 1 122695951
1 1 432194433
1 1 381185144
1 1 686598677
1 1 215624542
1 1 458312135
1 1 986262083
1 1 947920916
1 1 934427659
1 1 782364899
1 1 715992893
1 ...

output:

-1

result:

ok single line: '-1'

Test #60:

score: 0
Accepted
time: 179ms
memory: 8128kb

input:

2 200000 200000 1
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 10000000...

output:

-1

result:

ok single line: '-1'

Test #61:

score: 0
Accepted
time: 264ms
memory: 35524kb

input:

200000 0 200000 352487
135712 118584 670867088
72546 31680 1279343
123412 184392 678367510
125022 192330 57001931
134050 61434 212353526
6066 95972 717546833
47726 9232 949490922
166856 33998 986508808
166254 92344 143252836
82392 100980 919436840
84316 12292 753153826
192154 134452 832321404
144418...

output:

216679869

result:

ok single line: '216679869'

Test #62:

score: -5
Wrong Answer
time: 422ms
memory: 44136kb

input:

200000 200000 0 1089706
197033 84309 947754387
112807 60173 477333202
102607 132751 957665006
143619 102001 642146230
32419 155751 770317403
53835 4703 414754921
9463 17929 312775978
172373 41459 29632969
48451 142975 596586913
36019 180115 791609008
145487 162325 699635731
177243 94157 221311090
18...

output:

-1

result:

wrong answer 1st lines differ - expected: '245598855', found: '-1'

Subtask #3:

score: 6
Accepted

Test #103:

score: 6
Accepted
time: 1ms
memory: 3460kb

input:

1 0 0 0

output:

0

result:

ok single line: '0'

Test #104:

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

input:

2 0 0 1

output:

-1

result:

ok single line: '-1'

Test #105:

score: 0
Accepted
time: 84ms
memory: 7752kb

input:

2 10 200000 1
2 1 319832429
1 1 412617159
2 1 337734185
1 2 674652880
1 2 454610992
2 2 688717944
1 1 189208056
2 2 951221780
1 2 594191431
2 2 87592160
1 2 833491749
2 2 732961971
2 1 575969648
2 2 268359887
2 1 436382098
1 2 514959278
1 2 305446083
1 2 365989813
1 2 296840111
1 1 541558213
1 1 497...

output:

10104

result:

ok single line: '10104'

Test #106:

score: 0
Accepted
time: 95ms
memory: 7728kb

input:

2 10 200000 1
1 1 1000000000
1 1 1000000000
1 2 1000000000
1 2 1000000000
1 2 1000000000
1 1 1000000000
2 1 1000000000
2 2 1000000000
2 2 1000000000
2 2 1000000000
1 1 1000000000
1 2 1000000000
1 1 1000000000
2 1 1000000000
1 1 1000000000
1 1 1000000000
2 1 1000000000
1 1 1000000000
2 2 1000000000
2...

output:

1000000000

result:

ok single line: '1000000000'

Test #107:

score: 0
Accepted
time: 226ms
memory: 46856kb

input:

200000 10 200000 17900
199675 76237 290240030
50211 6922 761990536
92097 120746 607490
192856 130409 616541101
50427 80049 330957286
129588 180294 466199684
8674 110653 155297749
91380 156344 798960399
102127 40858 801752583
94673 105892 152356242
185676 6183 263664373
169026 112948 812501808
93517 ...

output:

75425485

result:

ok single line: '75425485'

Test #108:

score: 0
Accepted
time: 668ms
memory: 63232kb

input:

200000 10 200000 11791021341
90115 14234 985783971
123477 154651 628493605
123171 47179 220847663
8072 163826 30383173
174753 12792 15862638
172837 96919 880800330
92696 166466 443031361
85298 185851 999558577
23737 111350 809362300
24551 127050 920973896
121483 145215 67814677
78536 41919 475800490...

output:

949367959

result:

ok single line: '949367959'

Test #109:

score: 0
Accepted
time: 300ms
memory: 44832kb

input:

200000 0 200000 423432
117280 87297 405090778
161764 93979 279208002
169095 190396 237565477
5136 81072 251360373
177384 130645 595157997
5282 38206 898866303
150431 96891 829055730
18413 42187 599085995
75585 47004 557307885
92187 77157 349172549
63029 186638 993483250
37685 198246 538754012
119056...

output:

404806867

result:

ok single line: '404806867'

Test #110:

score: 0
Accepted
time: 37ms
memory: 23768kb

input:

200000 10 0 1583868
66186 49114 583417488
79347 122356 957296935
4161 178945 973881307
39875 85386 62804962
62164 81798 964069340
6410 188411 31431750
67426 6153 513781110
49101 116783 513947988
61043 89483 259723608
14116 90504 23294861

output:

-1

result:

ok single line: '-1'

Test #111:

score: 0
Accepted
time: 375ms
memory: 51484kb

input:

200000 10 200000 19999900000
47625 147346 8
147346 121067 9
97009 179826 2
155552 97009 1
179826 22149 3
15370 4310 5
135552 47625 7
121067 131030 10
4310 135552 6
22149 15370 4
92707 136627 90227
20274 369 174990
32793 164281 194588
56508 95231 92612
117675 125225 114617
42843 81551 39780
149173 15...

output:

199999

result:

ok single line: '199999'

Test #112:

score: 0
Accepted
time: 408ms
memory: 51892kb

input:

200000 10 200000 19999900000
45665 143462 7
22696 184210 2
38538 57388 9
184210 154285 3
125307 22696 1
149825 71332 5
143462 38538 8
154285 149825 4
57388 182077 10
71332 45665 6
163095 156887 174710
77920 77020 63954
85503 109613 119638
46319 118285 60934
66569 45264 83574
73519 101885 163357
1583...

output:

200000

result:

ok single line: '200000'

Test #113:

score: 0
Accepted
time: 380ms
memory: 50448kb

input:

200000 10 200000 19999900000
739 28876 199992
53663 1295 199998
43161 52504 200000
158247 739 199993
2816 184328 199996
52504 53663 199999
1295 2816 199997
52726 158247 199994
28876 8395 199991
184328 52726 199995
130045 124454 95456
117404 39359 188185
42676 84681 4828
105147 95150 194669
17107 579...

output:

199999

result:

ok single line: '199999'

Test #114:

score: 0
Accepted
time: 388ms
memory: 51132kb

input:

200000 10 200000 19999900000
19794 183474 199991
71973 145759 199999
167290 188987 199995
6730 167290 199996
92616 6730 199997
93098 157369 199993
145759 92616 199998
104691 71973 200000
157369 19794 199992
188987 93098 199994
4529 33398 169717
116172 158258 118532
69720 25407 140713
173220 192301 1...

output:

200000

result:

ok single line: '200000'

Test #115:

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

input:

200000 0 0 0

output:

0

result:

ok single line: '0'

Test #116:

score: 0
Accepted
time: 55ms
memory: 23824kb

input:

200000 0 0 1

output:

-1

result:

ok single line: '-1'

Test #117:

score: 0
Accepted
time: 45ms
memory: 23820kb

input:

200000 0 0 19999900000

output:

-1

result:

ok single line: '-1'

Test #118:

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

input:

200000 10 200000 0
146668 190255 646706475
71516 174249 65976309
173393 55930 434227341
38682 164404 792088710
68045 174249 105770742
190255 24008 378601596
68045 174249 584120597
68045 68045 891140070
71516 71516 121444300
24008 173393 638520585
42552 123134 440551564
172416 148702 205154389
80345 ...

output:

0

result:

ok single line: '0'

Test #119:

score: 0
Accepted
time: 217ms
memory: 45444kb

input:

200000 10 200000 1
18089 125148 634373061
26320 138377 746998187
125148 130407 287480602
136290 4926 478063834
136333 147458 29423436
26320 147458 334115471
4926 136290 505364255
18089 26320 866606210
11249 77957 605205962
136333 11249 440411926
170380 191070 819377443
150060 41355 635345633
143709 ...

output:

2407

result:

ok single line: '2407'

Test #120:

score: 0
Accepted
time: 211ms
memory: 46012kb

input:

200000 10 200000 4
131932 102405 14740950
95390 60349 599957231
62719 96049 468132040
96049 196778 435897371
147221 147221 710991146
69099 139866 753644389
130732 22961 374767514
118319 62719 793210617
14592 172623 872022637
131932 147221 588107750
133618 115753 634870732
69458 144612 651075961
8687...

output:

14977

result:

ok single line: '14977'

Test #121:

score: 0
Accepted
time: 209ms
memory: 47440kb

input:

200000 10 200000 92
26204 41682 132397613
11386 43267 432400482
26204 145442 188527020
124727 65248 170978952
26613 172005 567702196
146166 39798 679712885
146166 39798 953781917
124727 41682 826584416
146166 146166 117167249
65248 11386 787325743
764 17622 571020090
171608 112618 89050875
21593 172...

output:

473019

result:

ok single line: '473019'

Test #122:

score: 0
Accepted
time: 203ms
memory: 45668kb

input:

200000 10 200000 672
151843 72188 754208507
186567 155545 192251945
72188 173580 807040666
173580 155545 413157526
143249 143249 343025568
143249 182692 983484260
182692 21150 153868493
173580 155545 648383151
151843 182692 108954433
156381 14221 612434692
8027 76055 276048757
29885 107311 354554984...

output:

3501158

result:

ok single line: '3501158'

Test #123:

score: 0
Accepted
time: 219ms
memory: 45272kb

input:

200000 10 200000 5413
95488 104057 66278284
58623 58623 818395626
99093 124205 414738887
99093 158331 881420357
159736 67384 193983425
67384 58623 623301482
159736 141485 530044249
158331 146846 170069165
95488 158331 521843529
144566 99093 996200413
47960 153496 68751236
48094 54076 759978913
2873 ...

output:

25561771

result:

ok single line: '25561771'

Test #124:

score: 0
Accepted
time: 321ms
memory: 44832kb

input:

200000 10 200000 607219
117398 78777 25237306
122250 107989 217199414
100967 69009 323823567
78777 78777 653032486
43957 47258 709036359
107989 30352 736599336
152731 47258 974489271
69009 122250 631296609
69009 43957 982998301
164327 117398 451874824
78667 87007 949453372
176540 180070 825887209
29...

output:

424224418

result:

ok single line: '424224418'

Test #125:

score: 0
Accepted
time: 391ms
memory: 49568kb

input:

200000 10 200000 38942692
191843 87774 48763750
42448 181646 153085306
78078 10204 342154140
42448 45480 342538264
51194 78078 40436760
95235 39182 532944349
79153 79153 495283828
108632 141932 193232728
78078 121421 507359193
141932 108632 799596562
141888 166667 289423598
62108 182515 150884302
43...

output:

506971462

result:

ok single line: '506971462'

Test #126:

score: 0
Accepted
time: 578ms
memory: 56528kb

input:

200000 10 200000 3867596036
101129 178836 611548548
71053 23325 51723100
23325 197101 732184179
113289 40120 919460669
71053 12789 146285015
37966 23325 463373360
40120 12789 690404961
34895 40120 689138722
178836 12789 350156365
40120 23325 969795259
64088 12703 150877304
125299 69683 377982548
190...

output:

659435029

result:

ok single line: '659435029'

Test #127:

score: 0
Accepted
time: 683ms
memory: 63440kb

input:

200000 10 200000 19999900000
19948 93224 696463523
187941 81537 209135633
70892 81537 80053781
24348 139884 806003775
187941 73976 934692473
167817 167817 45539332
93456 24348 405608615
173940 167817 358543555
70892 73976 806171243
24348 173940 495263721
143061 46638 446762613
89043 9162 584904381
4...

output:

-1

result:

ok single line: '-1'

Test #128:

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

input:

200000 10 200000 0
51897 141304 64
125281 55107 6
160539 169899 18
55107 125281 75
134103 100791 22
134103 92211 69
169899 55107 78
125281 55107 78
110799 51897 127287266
169899 134103 85
137999 70531 886030502
126853 67828 763444764
6746 128867 630841156
131235 16144 483070630
75851 127161 25109450...

output:

0

result:

ok single line: '0'

Test #129:

score: 0
Accepted
time: 195ms
memory: 44456kb

input:

200000 10 200000 1
132839 73305 8
66415 66415 90
57701 174971 79
66415 174971 18
183186 132839 19
89931 89931 61
179694 73305 40
73305 174971 6
17869 89931 81
73305 132839 840562812
125249 112893 879029614
194877 19061 138829945
81475 120055 169500004
11311 70715 654559512
188750 172969 324123184
17...

output:

6

result:

ok single line: '6'

Test #130:

score: 0
Accepted
time: 228ms
memory: 46164kb

input:

200000 10 200000 4
56795 118439 74
7633 121769 207221193
94262 56795 99
122334 68618 65
121769 61460 35
133080 7633 56
56795 56795 74
122334 1833 1
121769 7633 90
94262 121769 15
196938 5748 486304794
154729 73605 706011974
117668 80031 609841298
38907 66933 976840777
25959 153246 121939463
65979 17...

output:

17

result:

ok single line: '17'

Test #131:

score: 0
Accepted
time: 205ms
memory: 45740kb

input:

200000 10 200000 69
34305 198290 43
134403 50880 28
12535 118969 9
149 189809 89
109244 162754 28
198290 118969 97
149 197773 24
198290 132425 73
189809 118969 801144804
162754 150623 98
95003 171197 415768639
173347 125597 919360137
113494 180067 594834693
115761 147604 588304425
142713 6816 887247...

output:

194836

result:

ok single line: '194836'

Test #132:

score: 0
Accepted
time: 210ms
memory: 44352kb

input:

200000 10 200000 199
177417 199866 318682817
99595 110745 97
127845 79799 47
81292 60018 18
199866 145887 94
184952 81292 22
127845 175345 47
110745 199866 53
184952 81292 67
48266 79799 28
85823 190048 384818214
194336 59792 244657121
39439 53627 108564530
89057 168528 347568658
156739 185153 88857...

output:

651529

result:

ok single line: '651529'

Test #133:

score: 0
Accepted
time: 211ms
memory: 44988kb

input:

200000 10 200000 2336
184617 52427 33
111293 52427 46
105785 111293 4
164129 27829 90
52427 52427 186174778
164129 34278 30
27829 27829 55
184617 52427 14
1326 164129 5
1326 176962 34
102771 139071 434244188
150738 199521 128736564
123841 108098 907689486
199383 58574 874299150
21239 153420 99504970...

output:

11153217

result:

ok single line: '11153217'

Test #134:

score: 0
Accepted
time: 321ms
memory: 47572kb

input:

200000 10 200000 519438
116130 101898 21
81936 54038 42
54038 64163 45
116658 171498 97
81936 101898 32
49315 179017 31
171498 64163 35
171498 81936 27
54038 132772 283198339
179017 49315 40
161198 165012 207070741
38350 46423 758311424
187878 183482 49180770
56851 130748 939913282
75920 162903 6556...

output:

422319245

result:

ok single line: '422319245'

Test #135:

score: 0
Accepted
time: 418ms
memory: 49352kb

input:

200000 10 200000 66643423
44513 44513 12
3503 77479 47
3503 24684 43
158230 121579 43
77479 158230 78
1119 44513 677352697
77479 24684 58
1119 69374 83
1119 77479 1
171086 42348 63
99622 122424 678349014
70595 36559 601320411
38950 94952 297745872
76915 181147 673313895
98967 29531 507080417
105881 ...

output:

516285768

result:

ok single line: '516285768'

Test #136:

score: 0
Accepted
time: 628ms
memory: 60640kb

input:

200000 10 200000 9835296767
77091 71557 61
77091 37679 44
77091 114986 100
181588 181234 946747104
120628 71557 75
71557 71557 74
120628 37679 17
2972 114986 37
181234 33702 12
71557 77091 96
120022 2014 373672414
199375 104181 330635751
105145 19370 967916951
93445 154353 560784836
69724 113303 854...

output:

860403485

result:

ok single line: '860403485'

Test #137:

score: 0
Accepted
time: 633ms
memory: 61512kb

input:

200000 10 200000 19999900000
198684 87285 36
10527 79494 35
36464 123562 54
60538 25496 49
38193 151136 72
60538 151136 36
22062 36464 34
22062 198684 17
22062 198684 53
36464 60538 564858326
23980 88045 888059354
75471 59269 951792068
126673 97202 674246525
176854 187902 347779968
189575 120710 136...

output:

-1

result:

ok single line: '-1'

Test #138:

score: 0
Accepted
time: 271ms
memory: 30468kb

input:

99991 10 199994 1200587363
7180 16144 89226268
24610 27853 784090381
5628 70613 111756823
42468 27836 372715094
29727 77918 223911677
35930 84754 884234966
39651 26307 210027899
87422 17822 965100919
97318 91132 991863731
30886 65782 144884689
76217 26846 447213471
20184 90114 782009979
7202 7202 62...

output:

1991460726

result:

ok single line: '1991460726'

Test #139:

score: 0
Accepted
time: 270ms
memory: 30384kb

input:

99997 10 199993 1199069062
76110 89727 992384512
23206 31555 610715512
29577 69916 785263595
41894 24032 103485118
74397 48107 462250182
36373 35577 325626106
60444 62133 996828881
2948 10534 278936261
60515 13347 288328099
44624 87005 256282562
44910 11716 66923121
10287 6928 10
76500 1822 1
88128 ...

output:

1996703346

result:

ok single line: '1996703346'

Test #140:

score: 0
Accepted
time: 275ms
memory: 30808kb

input:

99993 10 199992 1202254212
53981 1363 406301079
62188 46937 424399765
99402 62484 912983110
58640 93058 816626158
42729 33220 214785831
16039 49528 525960594
84424 45968 327603374
62753 65949 810964937
81834 3752 856237482
45236 88077 703262482
47286 53061 10
88564 45373 2
92111 33577 9
39564 87604 ...

output:

1912841674

result:

ok single line: '1912841674'

Test #141:

score: 0
Accepted
time: 267ms
memory: 31340kb

input:

99999 10 199991 1203333549
25284 66621 2126302
64346 38871 207331232
68432 36557 28459263
64526 52407 308956764
39502 54842 918103867
24691 33689 621737198
6278 51708 148666622
92982 39854 224082671
51430 33020 446493393
8609 68020 369472994
13443 41151 792063843
99729 53147 6
57851 66346 5
81071 69...

output:

1621434207

result:

ok single line: '1621434207'

Test #142:

score: 0
Accepted
time: 264ms
memory: 30784kb

input:

99995 10 199990 1203381974
93858 81578 812082680
44043 36941 196654074
41971 892 878002488
98645 2320 223299813
32071 92441 982957321
81448 16307 88222911
95168 85550 660103055
58738 68989 932257179
95748 40851 27536545
55386 79952 351808193
87731 43520 7
76608 33038 7
33350 40914 1
47880 86089 3
55...

output:

1932200532

result:

ok single line: '1932200532'

Test #143:

score: 0
Accepted
time: 262ms
memory: 30896kb

input:

99991 10 199994 1200930113
4842 67770 283061721
20851 74161 656597078
35915 32828 234390286
21084 87048 78464344
40688 567 210507677
26777 77790 873663699
31299 53619 718652950
84270 61656 885710495
30379 80442 359811261
49652 21904 469667241
20037 18935 2
92262 35026 528250358
94568 27870 230060998...

output:

1283015136

result:

ok single line: '1283015136'

Test #144:

score: 0
Accepted
time: 267ms
memory: 31080kb

input:

99997 10 199993 1202891556
18478 13442 560362647
80686 4459 191270057
98465 83044 370348787
62689 76504 981426034
47399 51107 442062386
76156 31176 494762561
57080 34219 148851218
63711 31431 44222492
63798 95008 940690107
50333 22276 672385714
39550 17141 4
34589 31733 8
18093 64701 7
65448 19755 1...

output:

1441247546

result:

ok single line: '1441247546'

Test #145:

score: 0
Accepted
time: 269ms
memory: 30380kb

input:

99993 10 199992 1198481428
58117 94840 740736212
85414 49787 662985037
42692 15237 879272699
91602 49689 165513247
96443 40045 72624742
62673 73227 152088607
8029 3143 537188318
41880 96050 521150877
15854 72248 150971171
36007 81140 265693408
74491 78045 8
23615 57969 9
73026 86679 801772339
64683 ...

output:

999847696

result:

ok single line: '999847696'

Test #146:

score: 0
Accepted
time: 270ms
memory: 31136kb

input:

99999 10 199991 1200882200
13258 42015 683121709
97263 83047 508739550
43513 76902 177620965
99103 54900 750592886
36304 66562 981946527
81556 64446 642835412
54198 24510 96066425
60283 60871 951723705
81968 35708 27719918
47846 42345 14875785
3760 64190 376263792
20533 85486 3
76749 10379 164456056...

output:

1508583135

result:

ok single line: '1508583135'

Test #147:

score: 0
Accepted
time: 283ms
memory: 30400kb

input:

99995 10 199990 1199509820
90475 63168 470796315
76906 57373 959999641
6043 15518 611376690
8080 12183 993250871
32349 77150 585630342
28921 47950 289663529
21085 42877 966329107
42266 35135 652530190
95635 33847 884626939
27182 38933 972213538
43929 95405 6
51390 5567 7
55702 55702 112406218
45247 ...

output:

1469612326

result:

ok single line: '1469612326'

Test #148:

score: 0
Accepted
time: 95ms
memory: 7804kb

input:

10 10 200000 4
4 9 321325765
9 1 437057496
6 5 985769268
3 9 50382707
9 4 616260423
2 8 570642446
5 4 105891394
8 4 898479132
6 4 21194991
10 9 160126166
10 4 126634623
8 3 616764966
6 3 193643546
3 6 976742333
5 3 206532267
5 9 339534940
2 5 68957761
3 2 338656904
4 3 209030635
8 1 413660186
6 4 17...

output:

11055

result:

ok single line: '11055'

Test #149:

score: 0
Accepted
time: 87ms
memory: 7720kb

input:

10 10 200000 20
4 4 395366511
5 8 382893539
6 10 734921426
4 1 480608782
1 3 140698066
1 8 275345561
9 9 818353946
7 10 722563406
8 4 403315816
7 3 428052136
9 6 365851244
2 4 136417674
1 9 221184959
10 10 657301036
10 4 780862366
5 4 420227323
2 6 250951556
8 5 710603299
4 5 802180680
3 1 725989581...

output:

56218

result:

ok single line: '56218'

Test #150:

score: 0
Accepted
time: 102ms
memory: 8040kb

input:

300 10 200000 12
158 273 808659230
102 35 507820985
170 272 203017365
289 129 122315598
170 137 940036704
263 263 548010497
289 172 433876938
263 129 104073946
137 102 274468171
272 272 108045360
164 57 104459600
75 260 345914842
164 133 103121843
115 219 172719623
240 202 326093473
43 277 24661061
...

output:

37079

result:

ok single line: '37079'

Test #151:

score: 0
Accepted
time: 110ms
memory: 7840kb

input:

300 10 200000 3526
3 201 649407852
97 179 793983104
176 201 109766918
88 130 642979450
176 33 527751678
97 140 728819427
176 3 691935221
97 140 844254278
59 176 10173621
59 198 295910606
100 13 591999205
276 147 959642104
103 156 279544444
88 268 673183712
11 50 679477490
178 167 193754627
134 143 8...

output:

885439

result:

ok single line: '885439'

Test #152:

score: 0
Accepted
time: 280ms
memory: 43796kb

input:

199999 3 199999 157505
131899 131899 121038207
78492 24185 788537289
116632 40406 784568458
185511 129310 767314798
51376 72237 579146077
24328 179828 841955884
174135 183337 366530487
13116 141076 512880711
176967 63206 153598548
36532 129034 588969313
49389 168370 454188410
3067 123598 203306371
3...

output:

306266673

result:

ok single line: '306266673'

Test #153:

score: 0
Accepted
time: 559ms
memory: 58396kb

input:

199999 4 199999 6947016393
40612 148109 997371971
134967 144753 510854619
162271 179843 808938622
188200 49534 756911179
17103 79943 239088038
82030 76059 523665726
33678 55856 199390684
182910 144316 745104020
60233 151657 956651453
60948 64516 535905852
141929 142738 232494743
50351 97972 37976623...

output:

754800722

result:

ok single line: '754800722'

Test #154:

score: 0
Accepted
time: 642ms
memory: 64176kb

input:

199999 5 199999 19999700001
47117 120852 940132990
1765 172575 689125947
1765 161815 568449078
89806 89806 164455745
34861 47117 290568041
149579 53706 763885240
25053 172888 645267817
145285 123816 22925532
61547 81596 585729464
122633 129413 452896022
174862 47042 482017495
120597 174583 743525680...

output:

-1

result:

ok single line: '-1'

Test #155:

score: 0
Accepted
time: 182ms
memory: 45052kb

input:

199999 6 199999 1677
104258 166054 19
101504 166054 53
68830 93374 65
166054 151410 16
145922 151410 86
68830 151410 62
86977 41289 44
18109 61358 78
85856 38506 35
30318 73191 20
125715 108222 40
7906 65451 29
128960 42088 79
33180 92662 39
835 111123 97
45915 84947 39
140077 149859 46
28611 80228 ...

output:

1

result:

ok single line: '1'

Test #156:

score: 0
Accepted
time: 463ms
memory: 56560kb

input:

199999 7 199999 3022023130
93862 12459 87
197095 54284 30
138491 12459 3
146624 169676 45
83465 147937 18
118062 54284 48
132418 175897 15
68485 7440 17
193831 117622 94
161569 168074 76
110839 16622 68
156150 99998 50
114603 1320 56
173855 50908 44
173651 64525 98
46701 32466 84
100453 27335 80
153...

output:

64

result:

ok single line: '64'

Test #157:

score: 0
Accepted
time: 310ms
memory: 40808kb

input:

200000 10 100000 5070918
43491 43491 39
102413 48280 41
191112 39650 21
43491 56371 90
123486 57685 61
191112 127146 81
127146 43491 45
194858 57685 6
102413 48280 63
183969 127146 19
114853 187622 592818998
23880 38803 866309656
159168 94973 182921889
12700 152040 605888341
97124 99493 193911122
88...

output:

994309314

result:

ok single line: '994309314'

Test #158:

score: 0
Accepted
time: 30ms
memory: 23792kb

input:

200000 8 87 6764
58199 178940 398283482
90018 134936 884790211
90018 35304 510188463
160878 177880 899791863
35304 24561 37085435
160878 178940 512659808
24561 24561 661205664
58199 24561 707748395
185561 127022 89
65334 173029 15
53986 45438 31
89818 139186 47
148119 24466 80
153186 135546 1
20066 ...

output:

-1

result:

ok single line: '-1'

Test #159:

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

input:

200000 9 103 1855
102649 8113 556125025
2417 22645 479236739
145556 159349 874101574
125704 2417 947240213
159349 16814 435825424
125704 159349 458608368
102649 125704 376755733
125704 167325 266275655
41973 161268 746376426
94793 866 15
129759 175440 93
157036 63464 26
65233 120770 50
153494 159437...

output:

-1

result:

ok single line: '-1'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%