QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548625#1914. Falling Portalsisirazeev7.142857 44ms8532kbC++203.1kb2024-09-05 19:38:312024-09-05 19:38:31

Judging History

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

  • [2024-09-05 19:38:31]
  • 评测
  • 测评结果:7.142857
  • 用时:44ms
  • 内存:8532kb
  • [2024-09-05 19:38:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

const int N = (int) 1e5 * 2 + 10;

struct line {
    int k, b;

    line() : k(0), b(0) {};

    line(int _k, int _b) : k(_k), b(_b) {};

    int get(int x) const {
        return k * x + b;
    }
};

pair<int, int> intersectX(line a, line b) {
    int d = abs(__gcd(b.b - a.b, a.k - b.k));
    return {(b.b - a.b) / d, (a.k - b.k) / d};
}

long double intersectXinDouble(line a, line b) {
    return (long double) (b.b - a.b) / (long double) (a.k - b.k);
}

pair<int, int> ans[N];
deque<line> st;
int sz = 0;

void add_line(line k) {
    while (sz >= 2) {
        if (k.k < st[0].k || intersectXinDouble(st[0], st[1]) <=
                             intersectXinDouble(st[0], k))
            st.pop_front(), sz--;
        else break;
    }
    st.push_front(k), sz++;
}

void add_line1(line k) {
    while (sz >= 2) {
        if (k.k > st[0].k || intersectXinDouble(st[0], st[1]) >=
                             intersectXinDouble(st[0], k))
            st.pop_front(), sz--;
        else break;
    }
    st.push_front(k), sz++;
}

int sign(int x) {
    return (x >= 0 ? 1 : -1);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    int a[n], q[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> q[i], q[i]--;
    for (int i = 0; i < n; i++) ans[i] = {(int) 1e18, (int) 1e18};
    vector<int> ord(n);
    for (int i = 0; i < n; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return a[i] < a[j];
    });
    reverse(ord.begin(), ord.end());
    for (int i: ord) {
        line k = line(-(i + 1), a[i]);
        add_line(k);
        if (a[q[i]] < a[i]) {
            line t = line(-(q[i] + 1), a[q[i]]);
            int l = 0, r = sz;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if ((mid > 0 ? intersectXinDouble(st[mid - 1], st[mid]) : -1e18) <=
                    intersectXinDouble(t, st[mid]))
                    l = mid;
                else r = mid;
            }
            ans[i] = intersectX(t, st[l]);
        }
    }
    st.clear(), sz = 0;
    reverse(ord.begin(), ord.end());
    for (int i: ord) {
        line k = line(-(i + 1), a[i]);
        add_line1(k);
        if (a[q[i]] > a[i]) {
            line t = line(-(q[i] + 1), a[q[i]]);
            int l = 0, r = sz;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if ((mid > 0 ? intersectXinDouble(st[mid - 1], st[mid]) : -1e18) <=
                    intersectXinDouble(t, st[mid]))
                    l = mid;
                else r = mid;
            }
            ans[i] = intersectX(t, st[l]);
        }
    }
    for (int i = 0; i < n; i++) {
        if (sign(ans[i].first) < 0) ans[i].first *= -1, ans[i].second *= -1;
        if (ans[i].first == (int) 1e18 || sign(ans[i].first) != sign(ans[i].second)) cout << "-1\n";
        else cout << ans[i].first << "/" << ans[i].second << "\n";
    }
    return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 7.14286
Accepted
time: 0ms
memory: 3628kb

input:

4
3 5 10 2
3 3 2 1

output:

7/2
7/2
5/1
-1

result:

ok 4 lines

Test #2:

score: 0
Wrong Answer
time: 35ms
memory: 8532kb

input:

100000
472909419 819415545 354941190 517113826 307239833 831177800 578834772 704837117 326642977 846249751 997452224 322958397 143787473 278464288 864820832 175161120 545824609 549197171 224617065 387719870 938593011 671365566 982006335 210657906 552581470 851423470 973444746 978545568 66820178 6528...

output:

115672286/17641
191412323/35566
807478405/10247
82564959/16297
148851281/50439
243884009/47060
395571559/51586
50966299/35524
28278217/11043
239035736/17331
-1
128612227/16712
19096717/13006
20119164/2731
352098163/33145
270852785/68242
57793841/50474
-1
584540705/11904
586005511/1221
725018326/5265...

result:

wrong answer 1st lines differ - expected: '118375763/30533', found: '115672286/17641'

Test #3:

score: 0
Wrong Answer
time: 40ms
memory: 8032kb

input:

100000
315623747 979206700 183094144 181505867 2572616 772718102 942741911 19472958 458398376 484546774 348949045 306690702 414701395 131437507 43708479 224826052 238532133 327518511 70279102 323433367 124141008 73101443 605805888 102782315 282343812 345273900 201043659 430908518 243739589 724275027...

output:

157870696/8049
-1
-1
250410203/22465
974493012/7847
3867757/149
410128825/2427
772204432/46505
107346530/803
410196205/22307
920763383/42663
-1
129734587/30488
668767570/39487
982806454/43013
314313027/41899
93984043/9778
32820565/86973
-1
570052820/96873
347444258/48955
223004087/88854
-1
8507537/4...

result:

wrong answer 1st lines differ - expected: '130531/66524', found: '157870696/8049'

Test #4:

score: 0
Wrong Answer
time: 44ms
memory: 7052kb

input:

100000
1 4273 15397 29998 27927 48335 59992 44642 37593 89985 41136 43307 119975 48665 62351 149962 8744 116987 179946 98859 144057 209927 19516 41099 239906 183405 142896 269883 7437 83101 299858 174434 127933 329832 91448 39029 359803 174356 124036 389771 136441 166104 419738 196420 51865 449702 2...

output:

214487230/35559
88821503/17702
32033856/10529
33468604/86295
13665951/9628
75917/29913
140632343/20624
1618810/2273
68350042/8415
49022721/6184
86104909/77634
63320953/76028
45485815/97949
1584663/23942
91989118/27687
267807/89728
47243948/5883
22031462/10927
98104714/59561
22639911/87431
8633327/16...

result:

wrong answer 9th lines differ - expected: '136670087/16827', found: '68350042/8415'

Test #5:

score: 0
Wrong Answer
time: 42ms
memory: 8080kb

input:

100000
1 933326351 11431 29998 989129972 37227 59992 989874362 62527 89984 979798680 75881 119974 982112916 19608 149961 995611915 151806 179946 913593466 132088 209929 930585647 149041 239909 930246483 218498 269887 972955258 54548 299863 927767028 295901 329836 953302565 223592 359806 995522236 31...

output:

221281385/50982
434792405/14594
52985461/6135
943970452/35443
-1
959092712/59617
147900748/33431
924388661/11621
912916297/6703
5773989/53987
-1
1088062/161
177462577/24324
992916777/44299
916995273/8386
216526559/36312
454119101/2170
1073699/14360
56115974/10695
-1
191001215/35949
923060996/99949
9...

result:

wrong answer 2nd lines differ - expected: '401837273/42017', found: '434792405/14594'

Test #6:

score: 0
Wrong Answer
time: 37ms
memory: 7220kb

input:

100000
1 944663363 19033 29999 978821096 9085 59995 944910920 6257 89989 935899956 82545 119982 940520499 117973 149972 912135517 105359 179960 992861910 149037 209947 995445085 200979 239932 965159106 3211 269915 909296230 233961 299895 975484316 298245 329873 977094068 214362 359849 995636217 2225...

output:

2982983/44613
-1
162411978/68491
7391521/7630
-1
264626224/32479
13153700/88479
-1
4457716/1137
164044531/68157
-1
223786792/42439
62467229/83037
397365221/8477
603628/61
202494709/30804
402926655/18077
201626116/59143
8441109/1285
-1
390918461/99829
158467558/69177
-1
168981261/67147
46645302/24131...

result:

wrong answer 2nd lines differ - expected: '105551441/9703', found: '-1'

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

100
534473706 617535198 746655229 582822181 350704338 460330801 735571468 88013273 362424504 855094440 710187915 697682713 997401051 460972806 717634399 444280514 755460273 944591484 265200138 839544060 662809699 661469793 497227720 278087261 937000185 722532327 468846527 92827045 15385128 139854649...

output:

460073995/39
-1
-1
253499725/86
-1
476669384/19
-1
398395099/6
-1
-1
284359786/29
-1
47435537/1
-1
-1
-1
-1
-1
497874367/28
143606568/1
-1
-1
-1
-1
34722875/24
634976547/4
310765455/17
-1
65566322/1
848986912/17
-1
-1
-1
20170859/7
-1
-1
-1
-1
-1
-1
467262629/33
193267947/19
125372911/5
429893382/5
...

result:

wrong answer 2nd lines differ - expected: '499461693/79', found: '-1'

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 3604kb

input:

100
832359132 241086117 70268513 75641100 493265869 8969911 580115154 253097306 322151607 572536179 103433364 769475382 58915476 7943159 674934181 286336577 158800591 167266000 146088101 655190514 41590604 326590745 562776717 281254161 127537826 133491925 80685740 116325615 999795567 247078385 96567...

output:

-1
252179752/3
37201903/6
851541346/89
-1
312966442/25
-1
924154467/25
-1
866303642/3
89021968/17
-1
274426577/13
811758438/43
-1
3353383/1
671014573/36
444919577/16
444919577/16
3449937/1
-1
159323793/4
165725031/4
442582477/42
772096419/52
-1
215253893/84
320595457/43
-1
324107401/36
746698261/21
...

result:

wrong answer 5th lines differ - expected: '534493001/48', found: '-1'

Test #9:

score: 0
Wrong Answer
time: 1ms
memory: 3872kb

input:

2000
21505957 142018840 50835846 230286771 619214141 711966088 451418032 83312406 997278214 235672441 776998092 992475976 912444334 252212792 547270894 875994775 420249958 660039013 284835603 996966995 545404037 762620339 218177198 216536966 712712166 284586306 598975962 889965588 251816698 28540064...

output:

621739397/749
921652677/256
286668687/404
71254561/58
106942807/248
711646845/487
141060098/1665
55164507/397
-1
850163913/500
137708607/1814
31380388/87
387952260/151
234038969/1165
240553696/101
733902439/425
68749291/781
980811597/698
380689957/1946
-1
-1
-1
641507572/521
49017098/21
-1
375503455...

result:

wrong answer 2nd lines differ - expected: '68924125/851', found: '921652677/256'

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3948kb

input:

2000
797776435 328363264 380792931 830287509 570335429 882870824 429432401 710728673 945865610 940849228 403089500 796543599 901854446 712568094 68385691 346788092 179631402 72575296 680321593 139773675 517849401 190654156 839257552 981435241 992409916 887842045 919377993 677204575 940817503 5589288...

output:

23415607/251
404452001/160
214354369/1137
-1
-1
7828226/107
99003005/344
358269499/550
-1
14844185/572
128263937/513
522775648/961
51451233/98
462412059/1544
277500524/255
-1
721196575/1036
789793591/1474
66940831/480
912397890/889
110142397/776
48666785/1741
998417066/1379
-1
829308908/923
83289170...

result:

wrong answer 1st lines differ - expected: '103496945/1514', found: '23415607/251'

Test #11:

score: 0
Wrong Answer
time: 37ms
memory: 7024kb

input:

100000
40496370 324535254 49378557 776806467 392153838 609799230 999070315 9268041 50237542 87633903 878656049 864388090 896320175 129811364 229732659 323726790 766611509 83562791 105404287 304944654 412773020 198917959 443657299 415124223 512809649 256079123 986186956 2116823 811457832 528369347 63...

output:

909844125/74797
-1
-1
-1
159345167/5361
219357809/5499
-1
176270891/15211
356986812/4679
480772724/30785
-1
-1
-1
929073153/18593
592509570/84049
-1
-1
220155017/56091
26635342/10865
-1
8880563/8457
948531127/29560
717933577/14995
111898071/81098
27162307/4020
50779853/89491
-1
222162733/15486
-1
-1...

result:

wrong answer 2nd lines differ - expected: '224068850/13921', found: '-1'

Test #12:

score: 0
Wrong Answer
time: 33ms
memory: 7956kb

input:

100000
747693760 346580867 964846225 969980340 332880584 194631534 209614296 522099709 464443293 921495511 83514635 841823909 900939960 262364081 256636328 411285480 427902137 406071146 24620069 112056879 943629859 862303870 308874724 251885142 471236107 744614688 681975403 212603157 214491071 32304...

output:

-1
118249853/13726
-1
-1
116700267/4798
334404865/19093
84266082/12443
-1
157814263/21248
-1
794770271/18621
101556942/69605
-1
-1
220094888/82707
-1
-1
6301327/213
695854192/13619
760481305/46688
37667083/99254
-1
344991640/72689
230855749/85430
-1
124516913/10278
-1
118371753/12007
-1
191113364/22...

result:

wrong answer 1st lines differ - expected: '78195569/6188', found: '-1'

Test #13:

score: 0
Wrong Answer
time: 35ms
memory: 8012kb

input:

100000
97813451 955958588 478382047 254807140 430405236 587356632 581166185 416641725 298677059 255167178 707387178 995828332 1210912 419588635 497113506 472224137 683979366 992616764 280702107 282745359 832716627 830311108 1931725 972918653 684698510 654423087 966059769 427612303 261873029 35728741...

output:

127919159/46770
-1
488933697/827
498185472/2131
26291384/7555
16984427/2366
375723725/9357
90622325/10837
36115663/12304
-1
67612945/21223
-1
308404938/34405
3893485/11669
407950073/41963
445080473/8628
154809641/33303
1476844/181
-1
595287471/26000
-1
-1
906313941/78059
-1
872275922/21811
128187297...

result:

wrong answer 2nd lines differ - expected: '266183846/35305', found: '-1'

Test #14:

score: 0
Wrong Answer
time: 44ms
memory: 7024kb

input:

100000
822999751 128955399 431407947 917749297 190297412 252492617 150325783 759881331 829939635 283074122 899601042 159665057 607610844 489768568 320041755 787661887 373639719 710748050 188262807 366602165 732969261 932719233 208477147 358075812 125541209 536067868 278333698 201086482 537247556 180...

output:

180053156/2557
180095102/48691
349046335/85638
-1
72903083/19044
329825178/60235
813556168/80343
-1
-1
4759354/8409
10644649/85083
31000153/2537
-1
-1
-1
-1
-1
51367878/14297
130655890/25201
-1
-1
-1
555721319/11599
-1
-1
5774654/5491
586335121/54989
122703681/79912
107395469/55555
603553870/24223
2...

result:

wrong answer 1st lines differ - expected: '80903637/10393', found: '180053156/2557'