QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388841#3397. 旅行Ecec243100 ✓679ms36168kbC++235.7kb2024-04-13 20:45:262024-04-13 20:45:27

Judging History

This is the latest submission verdict.

  • [2024-04-13 20:45:27]
  • Judged
  • Verdict: 100
  • Time: 679ms
  • Memory: 36168kb
  • [2024-04-13 20:45:26]
  • Submitted

answer

#pragma GCC optimize (2)
#include <cstdio>
#include <algorithm>
#include <queue>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define ls seg[p].lson
#define rs seg[p].rson
using namespace std;
const int N = 1e5;
const int C = 1e5;
 
const int BUFF_SIZE = 3 << 20;
char BUFF[BUFF_SIZE],*BB,*BE;
#define gc() (BB == BE ? (BE = (BB = BUFF) + fread(BUFF,1,BUFF_SIZE,stdin),BB == BE ? EOF : *BB++) : *BB++)
inline void read(int &x)
{
    char ch = 0;
    int w = 0;
    x = 0;
    while(ch < '0' || ch > '9')
        w |= ch == '-',ch = gc();
    while(ch >= '0' && ch <= '9')
        x = (x << 3) + (x << 1) + (ch ^ '0'),ch = gc();
    x = w ? -x : x;
}
 
struct segnode
{
    int sum,max;
    int lson,rson;
} seg[(N << 5) + 10];
int seg_tot;
int to[(N << 1) + 10],pre[(N << 1) + 10],first[N + 10],edge_tot;
inline void add(const int &u,const int &v)
{
    to[++edge_tot] = v;
    pre[edge_tot] = first[u];
    first[u] = edge_tot;
}
int f[N + 10],d[N + 10],siz[N + 10],son[N + 10],top[N + 10],rk[N + 10],id[N + 10],dfn_tot;
int a[N + 10],w[N + 10];
  
void dfs1(int p,int fa,int dep)
{
    f[p] = fa;
    d[p] = dep;
    siz[p] = 1;
    for(register int i = first[p];i;i = pre[i])
        if(to[i] ^ fa)
        {
            dfs1(to[i],p,dep + 1);
            siz[p] += siz[to[i]];
            if(!son[p] || siz[to[i]] > siz[son[p]])
                son[p] = to[i];
        }
}
  
void dfs2(int p,int t)
{
    top[p] = t;
    rk[++dfn_tot] = p;
    id[p] = dfn_tot;
    if(!son[p])
        return ;
    dfs2(son[p],t);
    for(register int i = first[p];i;i = pre[i])
        if(to[i] ^ f[p] && to[i] ^ son[p])
            dfs2(to[i],to[i]);
}
  
void insert(int x,int k,int &p,int tl,int tr)
{
    if(!p)
        p = ++seg_tot;
    if(tl == tr)
    {
        seg[p].sum = seg[p].max = k;
        return ;
    }
    int mid = tl + tr >> 1;
    if(x <= mid)
        insert(x,k,ls,tl,mid);
    else
        insert(x,k,rs,mid + 1,tr);
    seg[p].sum = seg[ls].sum + seg[rs].sum;
    seg[p].max = max(seg[ls].max,seg[rs].max);
    if(!seg[p].sum)
    	p = 0;
}

void remove(int x,int &p,int tl,int tr)
{
    if(tl == tr)
    {
        p = 0;
        return ;
    }
    int mid = tl + tr >> 1;
    if(x <= mid)
        remove(x,ls,tl,mid);
    else
        remove(x,rs,mid + 1,tr);
    seg[p].sum = seg[ls].sum + seg[rs].sum;
    seg[p].max = max(seg[ls].max,seg[rs].max);
    if(!seg[p].sum)
    	p = 0;
}
  
int getsum(int l,int r,int p,int tl,int tr)
{
    if(!seg[p].sum)
        return 0;
    if(l <= tl && tr <= r)
        return seg[p].sum;
    int ret = 0;
    int mid = tl + tr >> 1;
    if(l <= mid)
        ret += getsum(l,r,ls,tl,mid);
    if(r > mid)
        ret += getsum(l,r,rs,mid + 1,tr);
    return ret;
}
  
int getmax(int l,int r,int p,int tl,int tr)
{
    if(!seg[p].max)
        return 0;
    if(l <= tl && tr <= r)
        return seg[p].max;
    int ret = -0x3f3f3f3f;
    int mid = tl + tr >> 1;
    if(l <= mid)
        ret = max(ret,getmax(l,r,ls,tl,mid));
    if(r > mid)
        ret = max(ret,getmax(l,r,rs,mid + 1,tr));
    return ret;
}
  
int n,q;
int rt[C + 10];
int x,y;
char opt[5];
  
int main()
{
    read(n),read(q);
    for(register int i = 1;i <= n;++i)
        read(a[i]),read(w[i]);
    for(register int i = 1;i < n;++i)
        read(x),read(y),add(x,y),add(y,x);
    dfs1(1,0,1),dfs2(1,1);
    for(register int i = 1;i <= n;++i)
        insert(id[i],a[i],rt[w[i]],1,n);
    while(q--)
    {
        char ch = 0,*p = opt;
        while(ch < 'A' || ch > 'Z')
            ch = gc();
        while(ch >= 'A' && ch <= 'Z')
            *p++ = ch,ch = gc();
        read(x),read(y);
        if(opt[0] == 'C')
        {
            if(opt[1] == 'C')
            {
                remove(id[x],rt[w[x]],1,n);
                w[x] = y;
                insert(id[x],a[x],rt[w[x]],1,n);
            }
            else
            {
                a[x] = y;
                insert(id[x],a[x],rt[w[x]],1,n);
            }
        }
        else
        {
            if(opt[1] == 'S')
            {
                int root = rt[w[x]];
                int fx = top[x],fy = top[y];
                int ans = 0;
                while(fx ^ fy)
                {
                    if(d[fx] > d[fy])
                    {
                        ans += getsum(id[fx],id[x],root,1,n);
                        x = f[fx],fx = top[x];
                    }
                    else
                    {
                        ans += getsum(id[fy],id[y],root,1,n);
                        y = f[fy],fy = top[y];
                    }
                }
                if(d[x] > d[y])
                    swap(x,y);
                ans += getsum(id[x],id[y],root,1,n);
                printf("%d\n",ans);
            }
            else
            {
                int root = rt[w[x]];
                int fx = top[x],fy = top[y];
                int ans = -0x3f3f3f3f;
                while(fx ^ fy)
                {
                    if(d[fx] > d[fy])
                    {
                        ans = max(ans,getmax(id[fx],id[x],root,1,n));
                        x = f[fx],fx = top[x];
                    }
                    else
                    {
                        ans = max(ans,getmax(id[fy],id[y],root,1,n));
                        y = f[fy],fy = top[y];
                    }
                }
                if(d[x] > d[y])
                    swap(x,y);
                ans = max(ans,getmax(id[x],id[y],root,1,n));
                printf("%d\n",ans);
            }
        }
    }
}

詳細信息

Test #1:

score: 5
Accepted
time: 1ms
memory: 3764kb

input:

1000 1000
361 15
837 3
383 4
194 12
76 5
927 5
286 5
17 14
631 17
883 4
891 4
374 20
185 5
202 3
682 2
947 6
863 9
385 16
267 9
607 1
980 16
722 13
637 4
35 20
972 2
709 1
76 4
483 8
379 15
894 4
775 2
313 15
234 3
189 17
89 8
568 4
768 1
147 10
466 5
499 14
851 20
723 4
549 17
699 17
361 2
64 12
29...

output:

4152
10010
13107
1099
844
1562
1246
978
3883
985
6723
14174
983
978
1301
998
718
860
6357
742
964
964
2217
488
951
581
978
5443
3188
3812
1297
892
1310
978
2419
561
962
622
341
962
963
4225
997
825
57
977
651
8076
1249
1725
906
8287
854
5865
2623
892
980
7324
1149
900
648
1131
2579
900
4665
983
3229...

result:

ok 671 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 5696kb

input:

1000 1000
361 15
837 3
383 4
194 12
76 5
927 5
286 5
17 14
631 17
883 4
891 4
374 20
185 5
202 3
682 2
947 6
863 9
385 16
267 9
607 1
980 16
722 13
637 4
35 20
972 2
709 1
76 4
483 8
379 15
894 4
775 2
313 15
234 3
189 17
89 8
568 4
768 1
147 10
466 5
499 14
851 20
723 4
549 17
699 17
361 2
64 12
29...

output:

4152
10010
13107
1099
844
1562
1246
978
3883
985
6723
14174
983
978
1301
998
718
860
6357
742
964
964
2217
488
951
581
978
5443
3188
3812
1297
892
1310
978
2419
561
962
622
341
962
963
4225
997
825
57
977
651
8076
1249
1725
906
8287
854
5865
2623
892
980
7324
1149
900
648
1131
2579
900
4665
983
3229...

result:

ok 671 lines

Test #3:

score: 5
Accepted
time: 219ms
memory: 26028kb

input:

100000 100000
342 4
141 5
737 10
144 12
246 4
413 9
109 16
86 2
14 4
349 3
63 1
466 1
80 1
553 5
103 1
310 14
269 1
307 1
841 8
903 4
369 16
846 1
325 14
191 4
399 4
346 15
2 1
842 14
485 2
722 1
287 14
756 2
946 9
636 2
981 18
634 5
960 1
408 11
865 4
681 2
111 1
885 3
31 4
652 4
593 15
553 3
128 8...

output:

189473
95134
1000
1000
1867574
184949
471639
371104
1000
1000
543760
999
1000
995
1000
999
92799
999
4506441
575284
1000
1000
999
1000
99381
998
999
1718322
1000
4287039
999
1000
3795077
987
998
19434
3122892
999
2866852
281204
374354
239823
1000
999
1000
1000
2311722
3809117
1713414
1000
1000
978
2...

result:

ok 66690 lines

Test #4:

score: 5
Accepted
time: 218ms
memory: 26048kb

input:

100000 100000
453 4
364 12
758 12
222 20
88 2
163 2
537 4
448 3
365 15
640 4
839 1
597 20
170 19
609 20
81 4
290 4
523 2
417 3
142 2
785 1
328 19
808 4
931 15
155 3
412 2
512 8
714 2
990 2
20 2
219 12
27 14
427 2
581 15
83 11
682 2
50 6
310 14
797 1
228 1
345 1
645 19
980 8
342 13
763 16
400 5
234 4...

output:

1000
997
1000
477768
1000
311399
1000
1000
1000
1000
1000
689644
3188950
117326
324872
990
993
17037
1128763
1000
1000
3594244
16324
252549
3622010
1453290
5494437
1623455
214449
3148240
1000
79531
5244153
999
772830
438293
1000
1000
1000
1000
1000
5527792
307973
1211956
1000
857313
826839
761315
42...

result:

ok 66686 lines

Test #5:

score: 5
Accepted
time: 61ms
memory: 13616kb

input:

60000 80000
597 2
384 2
621 1
954 10
213 12
933 3
301 2
640 3
490 8
86 19
821 13
2 1
307 7
520 18
498 4
811 4
413 5
935 5
817 16
105 5
887 16
846 17
655 3
688 9
216 18
583 8
311 1
261 12
355 1
830 20
307 16
442 10
153 3
170 7
997 20
588 8
141 4
139 1
695 4
288 3
822 2
309 5
838 3
234 1
132 4
796 3
6...

output:

166985
13515
254913
3008
60146
103328
30301
806
28184
23624
129628
5147
55941
16691
8033
100288
41387
6798
30080
262726
110713
272653
14411
196538
40397
28704
2111
29821
105443
76882
136715
1583
2758
16147
68704
54416
33517
78483
18200
55549
228471
155528
180438
150424
157101
3827
66394
184160
18873...

result:

ok 53448 lines

Test #6:

score: 5
Accepted
time: 629ms
memory: 18580kb

input:

100000 100000
77 13
414 5
829 11
219 19
527 9
290 3
755 2
711 16
189 18
347 1
659 3
913 2
842 8
589 2
749 8
383 5
620 17
890 20
588 15
930 20
584 3
993 15
159 3
253 3
376 2
164 3
711 16
278 5
901 1
853 3
454 3
204 1
334 2
73 4
973 1
475 7
74 16
256 6
174 3
96 8
718 1
611 4
876 3
146 5
621 2
124 2
48...

output:

918
1000
1000
100352
11727
184847
118188
984
22223
996
133519
970
13422
154476
997
29127
1000
981
861
991
986
17980
988
984
170775
170303
1000
177899
979
222924
8778
993
40728
991
992
97395
114768
965
997
997
20560
36558
955
227002
1000
973
11836
25335
44545
998
999
33861
43329
14674
7783
974
30562
...

result:

ok 66688 lines

Test #7:

score: 5
Accepted
time: 629ms
memory: 19844kb

input:

100000 100000
8 8
591 4
903 17
590 5
652 2
823 1
70 4
512 2
404 20
844 1
616 2
328 2
763 5
836 12
554 4
964 2
195 13
714 5
725 4
210 2
69 4
894 3
270 4
112 7
856 12
353 15
214 1
48 7
609 14
512 2
695 15
65 20
921 1
8 5
496 4
726 14
33 7
31 6
271 6
958 14
736 2
574 2
587 15
415 14
580 2
833 4
782 18
...

output:

982
141422
959
996
34576
25902
947
990
1000
971
36262
994
980
981
993
999
33263
40302
994
1000
84274
18595
15922
1504
917
29948
12110
998
916
993
937
996
40079
86718
993
40958
994
171949
204410
999
940
35907
42484
971
79792
96759
64230
27086
980
30173
136666
23186
35157
10100
153024
226948
968
63297...

result:

ok 66576 lines

Test #8:

score: 5
Accepted
time: 260ms
memory: 35188kb

input:

100000 100000
552 4
694 5
439 5
848 959
498 1
408 1
678 3
818 3
937 4
971 16
951 5
130 2
503 3
319 3
142 1
771 1
986 1599
227 1535
71 1506
353 1107
321 4
670 5
852 3
345 678
401 2
738 900
964 435
398 4
257 5
271 1
175 4
853 376
483 1465
18 5
355 2
408 1287
410 5
333 260
907 4
50 3
866 1475
27 3
930 ...

output:

2263169
4652
6816
943
9038
1000
4015
1000
995
2260
1000
2546145
6740
995
5970
2318582
2250587
999
2718951
955
12089
994
931
985
8356
943
2097392
6474
4423
4503
4888
981
4986506
15493
1000
2392290
890
3148461
4805847
2393042
2097
928787
1000
12362
1204009
2970691
1000
931
3534024
389
1000
1000
940
20...

result:

ok 66787 lines

Test #9:

score: 5
Accepted
time: 259ms
memory: 36168kb

input:

100000 100000
499 4
375 1
19 1547
424 98
546 1
992 5
316 3
876 252
793 768
433 3
134 4
232 1895
536 4
237 5
869 1500
184 1139
509 5
52 2
693 3
224 4
278 1
448 1785
948 257
495 3
868 4
142 1
124 3
252 5
474 2
290 1177
342 1625
713 5
243 1108
633 1848
117 4
593 333
249 2
649 5
938 1565
632 1541
598 14...

output:

1000
1000
1000
925878
904
1000
238160
3279
35257
680
816
3217
4227668
924
5312
992
9624
1000
10020
6832
860
976
2341132
1974
16509
1326178
942
1467439
1000
885
9776
1000
1000
1000
990
1038
968
959
886
2645
953
1367423
787
139543
1440032
954
952
924
393232
379
1000
853
3454498
1000
2141
905
1000
1132...

result:

ok 66690 lines

Test #10:

score: 5
Accepted
time: 679ms
memory: 18468kb

input:

100000 100000
791 1
659 10
918 2
287 2
17 4
466 4
87 3
761 3
691 4
619 3
751 10
20 2
306 5
322 9
381 4
819 8
314 2
638 4
470 4
556 2
575 10
881 4
554 4
310 5
978 4
643 10
577 7
917 3
228 1
193 1
425 8
330 1
632 4
112 7
67 3
643 3
347 8
560 6
753 3
903 5
394 4
909 4
78 4
57 5
633 1
431 3
668 1
683 4
...

output:

117320
59167
24345
38804
999
999
79815
38096
1000
995
17798
992
164261
127129
718
999
4190
8817
987
5115
997
999
1000
110264
75343
919
974
976
985
272578
101184
931
998
998
1000
982
198894
1000
52574
108579
999
1000
997
49334
65772
998
998
993
1000
999
999
305269
102883
69803
20205
1000
988
227866
2...

result:

ok 67081 lines

Test #11:

score: 5
Accepted
time: 665ms
memory: 18896kb

input:

100000 100000
765 3
511 9
590 1
887 1
316 5
648 5
43 2
185 3
527 10
291 7
154 7
633 3
575 4
242 6
564 4
36 2
220 5
683 1
139 2
746 3
509 5
154 10
559 5
573 1
387 10
45 3
488 3
832 4
106 2
86 10
711 5
661 1
585 5
971 6
351 5
458 3
641 8
107 2
434 7
267 4
169 5
55 5
801 6
518 1
685 10
69 4
872 8
854 1...

output:

100844
91536
186502
1000
1000
991
991
993
994
974
257113
202149
969
993
1000
1000
88711
325373
999
163125
996
996
164617
16852
1000
925
110699
978
101036
999
1000
46974
1000
137837
103842
9899
33091
999
939
54724
86119
177167
38677
58373
999
91808
23617
252019
990
997
23139
993
78020
61245
1000
1573...

result:

ok 66541 lines

Test #12:

score: 5
Accepted
time: 651ms
memory: 18424kb

input:

100000 100000
641 1
732 6
436 4
285 9
172 10
422 3
24 5
926 4
157 3
797 7
880 4
503 6
782 2
98 4
932 2
654 3
260 9
144 7
300 3
922 3
216 5
963 2
398 8
820 7
295 8
43 5
863 1
387 3
241 4
145 3
459 7
61 2
839 10
618 1
216 3
388 4
251 4
512 3
86 2
277 1
176 3
498 9
691 1
258 6
507 2
882 5
219 8
108 3
8...

output:

129499
964
997
976
989
45228
23348
998
213764
994
48127
47134
979
48158
83149
62291
988
998
199449
100514
29313
32396
210770
255780
291110
999
35598
136044
21419
203533
994
998
984
995
86486
998
2599
32691
72576
174196
1000
43289
985
29860
64561
360693
987
151418
992
166427
998
989
58729
39940
999
2...

result:

ok 66672 lines

Test #13:

score: 5
Accepted
time: 101ms
memory: 26304kb

input:

100000 100000
568 4
909 369
53 81
634 4
260 401
566 966
333 5
908 51
765 2
944 5
24 5
686 562
496 1
585 4
579 1
358 402
892 309
390 1
639 1
552 416
647 672
495 586
315 5
60 897
208 475
76 3
343 606
32 1
244 5
930 2
660 310
607 4
433 476
617 254
1 4
53 5
964 5
69 3
21 3
221 4
605 46
549 830
875 798
8...

output:

92185
64464
442
1404
6585
2073
971
626
9604
4699
1133
124811
828
401
65520
629
2472
108343
56671
136044
21207
52249
2624
78957
1100
1793
1498
117721
33808
113648
67995
18
5097
191574
1060
565
188470
813
46587
125346
1507
2148
32499
29973
101504
1491
1742
829
1472
1347
72146
151646
765
330
100551
220...

result:

ok 66862 lines

Test #14:

score: 5
Accepted
time: 100ms
memory: 25444kb

input:

100000 100000
567 365
186 443
407 5
501 5
681 357
413 63
430 2
445 184
402 2
968 4
285 1
951 170
94 2
142 3
967 3
275 164
427 4
445 1
950 77
246 2
437 3
661 5
782 3
231 134
491 1
452 149
202 4
646 1
882 1
280 5
95 224
233 5
456 44
982 1
207 281
733 161
433 4
980 4
370 5
969 2
623 4
451 231
797 3
335...

output:

1794
2734
115280
3992
729
49912
104122
14327
181143
113234
1754
2609
240853
1682
561
161433
19233
1157
1278
110849
1246
2635
1568
8957
1837
2593
88611
2721
42338
1718
10399
196749
1058
1383
368
3072
85409
1249
2087
59372
2008
842
146092
501
78567
84627
2231
2394
107450
175825
2458
1529
66632
87247
1...

result:

ok 66689 lines

Test #15:

score: 5
Accepted
time: 99ms
memory: 27788kb

input:

100000 100000
463 2
433 994
685 1922
863 1129
38 1838
476 2
242 2
171 5
580 9
75 4
870 2
998 1827
836 618
168 4
617 785
210 178
377 5
956 820
155 4
415 2
938 4
601 1609
188 4
918 5
729 1946
409 4
654 903
198 1943
612 1437
46 1
67 2
254 1417
971 1772
541 1041
670 3
332 5
882 1036
493 473
627 5
273 17...

output:

173656
2204
906
115878
1212
22358
1919
1169
12355
467
19299
282227
72610
937
91097
1259
72544
18561
1959
1762
596
1904
184691
1337
101469
94125
1532
120976
806
367900
1404
902
1903
3012
23145
112891
92924
2317
53244
2325
324819
686
50004
9129
134019
992
33064
32413
1296
657
189885
108953
1485
220251...

result:

ok 66599 lines

Test #16:

score: 5
Accepted
time: 96ms
memory: 28176kb

input:

100000 100000
76 5
347 4
526 4
551 1766
900 1790
500 3
904 1759
695 1532
913 2
988 431
349 3
468 467
895 4
133 4
118 4
110 4
288 1933
841 3
977 4
888 1
330 2
123 1084
307 1568
827 1551
288 789
576 721
645 106
365 1946
434 1219
321 1311
949 1746
550 4
857 1298
989 3
556 1
894 2
259 1464
44 1035
442 1...

output:

169
553
159487
1295
87175
857
2138
1471
53423
1332
2144
132630
673
2030
1213
94615
124021
121771
105489
70638
234059
1598
1430
117598
1248
1852
159467
1167
87507
956
79121
2012
292577
1272
126529
983
1738
65112
765
725
854
1349
108003
259161
623
39664
848
1272
1548
2214
1076
320275
190638
473
19031
...

result:

ok 66540 lines

Test #17:

score: 5
Accepted
time: 506ms
memory: 27440kb

input:

100000 100000
834 5
806 273
856 3
189 698
82 1
227 992
67 701
327 565
483 5
30 795
305 629
63 4
961 5
173 622
731 55
700 5
26 54
252 556
420 5
3 4
417 189
11 313
106 625
543 797
681 528
954 1
779 2
81 32
353 803
109 1
250 327
365 338
689 4
822 1
716 2
847 800
279 183
631 985
523 510
572 1
841 1
337 ...

output:

999
309347
283141
999
1569
788
1000
982
870
4112
87618
617
999
611
995
1000
942
1000
429
2079
243824
999
998
1000
1158
1527
184863
998
1000
827
995
263669
1000
11926
558
953
854115
1000
754951
636299
998
3069
165175
1550
976
892
625
1000
964
278
177831
794
947
658629
998
993
923
993534
137
987
994
5...

result:

ok 66626 lines

Test #18:

score: 5
Accepted
time: 569ms
memory: 27544kb

input:

100000 100000
287 2
106 5
293 3
214 4
69 418
642 3
285 1001
903 481
93 133
940 2
46 1434
408 3
274 3
342 842
190 4
474 425
728 1257
173 1390
372 4
160 2
421 3
694 1625
35 466
554 3
248 3
564 4
534 1
754 1143
466 1559
87 1
965 4
294 4
849 5
757 3
528 1647
671 1172
175 1
175 43
701 928
666 1859
821 1
...

output:

943
1000
136215
1000
1000
444
24272
1162
265776
148449
341
115029
2178
239
916
742
925
1574
476
994
75004
954
765
180557
39447
205
742
1056
715
48343
988
335
152930
1835
700
825
991
783
998
916
985
895
1000
968
165415
88363
14078
49159
1296
133750
296
1000
1000
1111
125884
216
1000
135978
996
1000
4...

result:

ok 66714 lines

Test #19:

score: 5
Accepted
time: 562ms
memory: 27352kb

input:

100000 100000
559 774
721 637
646 4
160 1126
278 2
792 510
828 945
23 1
883 2
441 87
968 4
965 413
125 38
706 1373
957 650
754 793
26 5
382 4
492 1158
95 1450
859 315
915 3
317 1
625 1269
33 1
59 438
249 1085
310 3
381 4
889 4
980 5
600 1346
512 196
502 5
587 708
405 167
700 4
80 1014
235 1267
305 1...

output:

543
1314
130570
75335
424
992
1147
120907
1872
992
387
999
14391
760
999
678
2492
565
812
615
82308
2398
998
1787
804
1113
99
936
977
268944
863
1000
302010
349
998
213
996
998
999
276
998
264290
613
1080
998
525
453
640
88049
414495
852
999
954
2230
720
79182
419
719
1230
691
975
111996
998
998
962...

result:

ok 66630 lines

Test #20:

score: 5
Accepted
time: 546ms
memory: 28032kb

input:

100000 100000
810 1795
267 1
841 1275
285 1
457 5
901 777
821 705
647 4
570 4
274 1608
541 1744
733 1370
535 322
680 3
643 1
815 1244
673 242
458 241
332 2
85 4
554 2
512 1715
741 3
383 5
198 1601
434 2
42 4
959 1
348 2
542 4
150 3
888 4
806 2
239 849
364 5
799 2
671 5
84 514
497 1056
650 1063
537 1...

output:

835
100800
112934
660
999
998
987
5102
927
989
787
918
316900
172685
998
981
690
403
965
325373
1841
883
963
49564
995
990
159814
998
995
70755
998
1131
121593
74482
652
1988
814
34823
1428
225744
996
47691
943
879
888
484
54739
811
390
897
207731
819
206172
1127
998
1050
995
998
763
928
323538
818
...

result:

ok 66548 lines