답안 #956845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956845 2024-04-02T14:29:25 Z shmax Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1748 ms 177016 KB
/*


         ~??:   :!?J???????????????! .????????~  !?!~?^~!:7:?!~7?. .????????^                                   .:^^^^^:...............::................::::::............:.. ....
         .YYY:    .^7JYYYYYYYYYY?!:  ~YYYYYYYYJ??: :J7^Y?~Y!~J! .7?JYYYYYYYYJ                                .::^^^~~^.................::^~~^:::...........:::^^^^:::::.......... ..:.
         .YYYJ.   ..  .::^^^^:..     .7JJYYJYYYYY7~?^ .?. !! .?!!JYYYYYYYYY?~                             .:^:::^^~~..................^~7!^:.................:::::^^::.............  ..:.
.:.      ~YYYY~  ~77:     .~~~:.       :7JYY?~^^JYYYJ?JJ!!?J??YYYY!^~!!~^:.                            .:::::^^~~!~::::^:::..........:!^................::^::::::::::::........   ....  ..:.
YYJ!.  .!YYJJY?   ..   ...?YYYYY!.   .!JYYJY?. .JYYJYYYYYYYYYYJJYY:                                 .:::::^^^~^^^^^^^^:...........:~~~:...::::..........:^!??7~^:.............  .   ....   ..:..
YYYYY??JYYYYYY?.......JYJYYYYYYYY?...7YYYYJJYYJYYYYJJJJYYYYYJJYYY!................................^^^:::^^^^^^^^^^::..............::...::........::......:::^~7?7~..............  ........    .^^:...................................................................................................
JJJJYYYYJJYJYY!......:YYYYJJJJJYYY^.:YYYYJYYYYYYY~7YYYYYJ?JYYYYJ~...............................^~~^^^^:::^^^^^^......^^^:...............::::.....::::::::^^::.:^7?~.............   ....::.  .  .^~:....................................................................................................
YYYYYYYYYYYYY7........!YYYYYYYJJYY~.^YYJJJYYYYYY!..:~7~:..:~7!^...   ........................:!7!~^^::::^^^^^^.....^!!^....................:~^::....:::^^^^^:::...:!?^.......  ..... .::.::.. ..  .:^:....................................................................................................
^:~JY!:~^.~?~..........:!?JYYYYYYY^.:YYYYYYYY?!:.................     .....................:!7!!^^::::^^^^~~.. .:!J?^.............:........::^~^:..::::::::^^:......:!!:.....    ..^^. :~.:^:. ...  .^^:...................................................................................................
   .^       ..............:^~!7?J?:..?J?7!~^:................     ...     ...............^!!~!~^:::::^^^~!^.  .!YJ~......::.......:.....:::::::^^:...::....::^::......^7~.        ..^!: .!::^:......  .^^:..................................................................................................
        :   .     .^!7????7~^:...........:^~7?????~.........    .    .:    ........... :77!!7~^^^:::^^~!7^.. .JP7....:.:^:.......::.....:::::::::~::.........:^:........~!.         .:7!:.7^:^^...::.   :~^:................................................................................................
      .:.. .      !YYYYYYYYYYYJ?^.....:?JJYYYYYY7:.   ..     .  ..  ..  ..............~7777?~^^^^^^^^!77^...:?5~......:^:........::......:::::..:^!::..........:^:.......^7:       ....!J~:?~:^^...:^..  .^^:...............................................................................................
   ::.     .::    :YYYYYJJYYJYY7..:^:..7YYJYYYJY?   .. ...   .      ..  ............:777777~~~^^^^^~7??~...:?J:......:^:.........^..............::^7::..........:^:.......:7^     ......^?77J!^~~:..:~...  ^~^:.............................................................................................
    :       .    ..!YYJYJYJYYJ~..!JYJ!:.~JYYYJYJ?~...    :  ...   ..    ...........~?7?7!7~~~~~~^^~7??7...:JJ.::.....^!..........~...............~.~!.:...........:^....   .7~    .......^??7J7~!!...~~...  ^~^:............................................................................................
     :.   .:.   ...?YYYYYYYJ!:.^JYYYYYJ~.:!JYY7.  .:.    .:    .....:..^77~~.....:!77J7!?~~!^~~^^!??J?:...JJ:^!......~~..........~:..............!:.?^.:...........:^.     ..!~   ........^??7?77?!..:7~...  :~^:...........................................................................................
     :..   .     ..^!7???!^:..!YYYYJYYYY7..:^77.    ......     ...:!JJ7JYYYY:...:77?J!!?~~!~^!~^~????!...JY:~7!:..:..!~..........^~............. ~~ :Y............. .:. ......!~  .........^??77777~..!?^.....:~^:..........................................................................................
                 ............~YYYYYJYYYYY~......   .  ..  .. .....~JYYY!!7?YJ?!^77JJ!!J!^!7~!!^~?????:..75^^777:.^..^!~.........::7............. ^J. 77.......    .. .:.::.....7: ..........!7777!!7^.~?7:......~^:.........................................................................................
       ....   ...............!YJYJYYYJJYY7..........      .........!JJ7:.:?YYYJ77JY!!J?^~7!~!~~?????7:.^P!^7!7?..~..!!!....::...^.!^.............:5: .5:.....     .....:^^^....:7. .........:!77!!!!7::?7~..:.:..~::........................................................................................
   ...............:^:...:^^...?YYYYJJYYY?:........................~JYYY??JJY!77?5Y!!?J~^~777!~7J????!~.5?^77777.^~.:7!!^...^....~:.7.........:....5~. ?Y..:.............^~!^....:! ..........^7!!~!!!~:7~!:.:::: .~^:.......................................................................................
  .~~:^7~......:~!YYYJ!?YYY7~:.^7!:.:~7^...........................^77~!YYJJ7~?P5!!?Y7^^~7?7~!J?77777^75~!777?7.7~.^7!!!:::!....^~.^!:......:~....P?..:P~.:7^.....:..:...~!?~^...~^ ..........~~~~^~!!^!^~^..^~!. :~::......................................................................................
 :YYYYYYYJ:... !YYJ?!~7!~?JYY7........:.........::.........   .    .....:~:~~?P5!!75J^^~~7?7!?J777777^P?!77!!?7:?^.^7!!!~^~7..^.:^^:!7:.....^!:..:GJ:..JY:.!Y^...:^^::~...!??~^...7.........:.:!^~~.^77!^:!..^!7:  :^::.....................................................................................
:?Y7!??!7YJ777!~JJ^~!~~~!!^?Y~.....::!YY?~....~?YY7::......  .  .  .......^~?P5!!!Y5!^^~!7?77Y?77777!?P777!!777^J^.~7!!!~~7?..7:.^:!^!~.....!7:..~GY:..~G!:.JY:...~!!7~~..:???7~..^7 ^.......:.!~^~~.:77^.!:.^7?~   ^^:.....................................................................................
J77~^7!~~!~7YYYYY~!7^. .^7!^JYJ^..:YYY!~~.~..~.~~!YYY^...   .   ..   ....:~75Y!~~75J^^^~~7?7YY777777!5Y?7!!!77?!J~.~7!!!~~7?^:?~.::.?~~.....!?^..7GY~::.PJ!^:5J:..^7!7J7^..~J??7!..!::!..:...:.^7^^!^.:!!:^^.!J?!    ^^:....................................................................................
!:7!~^^^!7~^JYJYY?^!!^:^!!^?YYJ^...77:::!77?7777:::!?....   . ...    ....~!57!~~!Y5~^^~~~??75?777!77!5J?!!!!7!??J~.~7!!!!!!?7~??:.~.~J~^...:77~..JGY!^~.?B!?^!P?:.:7!~??~..:?J7777::7.7!:.~...:.?~^^!:.:7~:^:77?7.  . :::...................................................................................
:!7~:  .^~7^^JYYYY?7~~7~~77JYY!......:!?77~^^~77?7:..........    .......~~Y~~~^^7P?^^^~~~?7J5!~!!!7!75?77!!!7!7JJ~.~?!!!!!7YJ77?!.^:^7?~^:.:77!:.PGY7^J.:PY~?^YY7^:^!!!Y7^.:~5?7777:!::7!^!7^.~:^?~~!!..~7::!?~!7.  .  ^^:..................................................................................
!~7!~:::~!!^JY7:::^YJJYJJY~:::...:^..!?7!:    .!7?7:.^:................^^J~:~^^^?5~^^~~~~?75Y~~!!!7~?J777!!7777??~.!Y~!!!!75Y7777^.^~!~~7^:~777~!BPJ?^P:.7Y7!7~G?!~~!!~~Y!::^?P!?!!7!!.!~!7??77!:77:^7^..7!~7!.^7:  :...^^:.................................................................................
J^~!!!!!~~!~JYJ. ..~J?!7?^.::..:7YJ.:7?7!.    .!7??:.JY?:.............:^!!:~^^^~YJ^^^~~~~?7P?~~!!!7~J?777!!7777??~.!G!~!!!75Y!!7J7::7!!:!!!!!!!!PP5J?^B!.!!J!!!?G!~~~::.~Y~:~~55!?~!7J.~~~~~!7J?:!?!.^7^.:7!7::~7^. ~:.: ^^^................................................................................
YYYJ^!77^?YYYYY:.^...^.::.~??~.:7YY~.~7?7!^:.^~7??~.^YY7:.............~^!.~~^^^~5!^^~~~~~7?G7~~~!!7~J?7777777!7J?!.!B7~~!!!YJ!!7J!~.!7!~^.?Y7!!?BJ577^BJ.~~~7~!!P5~~^....7J^~~!G??7^~J7:~^~~~~7J^^?7!.:!~.!7?.^7^!..?~ ^^ :~^:..............................................................................
!YYYYJ!7YYYY!:^::..::^. .^.:^...^JYY~.^~!J7??7?7~^.~YYY^.............^^~.:~^^^^75~^^~~~~~!?G!~~~!!!~J77777!7777YJ~.~G7~~!!!5?!!JJ!!^:7!!^^77JYJPP!57!~Y5:^~:~~~!7BJ~^:...:?7~~~YG!Y~^~J.~^^~~~~?~:?77~..7!!?7.^Y:!:^J^  ?! :~^:.............................................................................
 :~~^....^^^..^. :~7?!~ ::.......:^^:.. ^.~^:!.^  .:^::....~?~!!....:^^:.~~^^^^YY^^^^~~~!!?P~~~~!!!!J77?77777775J~.^P!~~!!75?!!5?!!!:^7!~7?!!!YBPJY7!~!J~^~.:^^^~?GJ~^:::.:7~~~!G7??^^J:^~^~~~~7~:~?77:..7YJ?:~Y::!?J:. .Y?..~^:............................................................................
   ...........:::.:~~^. :^..............77?!~?!7..........~JJ7JJ^...~^:.:!^^^^~P?^^^^~~~!!J5~~~~~!!757?777777775?!.^P!!~~!7P7!7P7!!!~:~7757!!^PP?YP5?!~!!^~..:^^^^?5?^::::.^~~~~YY~Y~^7!:~^~~~~!^::?77!::.?P5:~J..?J?:.. ~7Y~.^^^...........................................................................
   .............^.  .:.::...............:?J77JJ^..........^!?J77^..^^:.:^!^^^^!P7^^^^~~~!!Y5~~~~~~!?57?77777777P?!.^5~~~~!J5!!YP!!!!!~:~J5!~.?#7!!7?JJ!~7!^.  .^^^:!7?^::...^~~~!Y!7?^^J:~~~~~~~^:.7777^:~:YG:!?..?J7... .~^Y?.:~^:.........................................................................
   ..............::::........................:..............::.....~:..:~~^^^^?P!^^^^^~~!!5Y^~~~~~!?P7?77?77777P?~.^Y^^!~!YJ~!GJ~~~!~!~.77^.^GJ!!!!7!!~:!7!....^~~!!?YY7!!~~^7!!!Y?!?!^?~~~~~~~~^..~?77!.!7~G7?!..7?!.... ^^^?5~.^~:........................................................................
   ...............................................................^^:.::~~^^^~?5!^^^^^~~!!PY^~~~~~!JP??77J7777?P7~.^?:.^!!57~?B7~~~~~!!?::.:55!!!!!7!!^.:!J?!~^^^:7!^~!7~::^^^?!!???J7~7Y7~~~~~^^..:J777^.!JYGP^..7?!......!^:~YJ::~^:......................................................................
   ...............................................................~^:.::!^^^^~7P!^^^^^^^!!GJ^~~~~~~JG?7!?J7777?5!^.~7:..^J5~~5P~~~~~~!YG:..?P7!!!!!!7!^..^^^..   .:7!:^^~~::::~7^~!~!~!!GY~~^~^^^...J7!77^:~5PP^..7!7^.:.. :^^::757::~:.....................................................................
   ..............................................................^^^  :^!^^^^~7P!^^^^^^^!7GJ^~~^~~~?G??7Y?777!JY~^.~~....!?^?G?~^^^~~JB!.:^~!!7!!!!~7!^  .::.     ..!!^^::^^:::~7^7^~!^7GP!~^~::^...J?7~!7~^!PG!::7:7!.^:...:^^^:^JY~:^~:...................................................................
   ..............................................................~^: ..:!^^^^~?P7^^^^^^~!7GJ^^~^^~~?GJ?75777!!YY~:.~:... ^~7P5~^^^^~?GJ.:~??::!!~~!!7?^   .^:       .~~^^:.:^::.~7!!:!!~GG~~^^..:.. ?J!~:^7!~?GY!~?.~?:^^....:^^^::~JJ^:^^:.................................................................
   ..........................:::::............................  .~^:::.^~^^^^~JP7^^^^^^!!7G5~^~^^~~7BY7JP777!!5?~^^!!!~:.!!7Y7^^^^^7G5::77?J?!^~~~~!~Y7 .  .^.       .:^:~^.:~~::~?7.:!^YB~~^^..... 7Y!~^.:?YJYP??7.:?~~^!....:^^^:::~JJ~:^^................................................................
   .........................^: : .:.:........................   :~^....^~^^^^7YP?~^^^^^!!7GP~~~^^^~!GP?Y5777!JP?7^^~:...~!:.7^^^^:7P5^:J??!!YY!^~~~~~!5.    .:   ...::::^^^~^^^~^:^J7.:~~G^~^^..... ~5!^^::.^YPGJJ~.:^?!.?^....:^^^::::^?J!^^^:.............................................................
   ........................::. ..  :^........................   ~~^..:.^~^^^^JYGJ~^^^^^!!7PP!~~~^^~~PG?557??7Y?:::~:.  :~. :~^:::!5Y~~5?7!~!!YY^:^~^^^J^     .::^::^~7JY5PPGGGP5YJ7~7^.:~J^~^^..... ^5?~^^^!:.7GPJ::~:?~.~?. ...:^::^:::.:7?7~~^:...........................................................
   ................     ...:::. ...~............................!!~^::.~!^^^^YYGJ^~~^^^!?7PG7~~~^^~~JBJPP?7~!?~::^!.  .:  .~^:::JY!!?57!!!~~~!YY:.:~~^^~.     :^!YGB####BBBB##B#&#B#P?!^~7^~^^....  ^5?7~^:^J!:?GJ.^7:?~..?7.....^^::^:::..:!?7!!~:.........................................................
   ................     .....:::::::...........................:7!~:...^!^~^~5YGY^~~~^^~??PGJ~~~^^!~!G5P57!~7!^:^7~       ^^::^^^7JJ77~~~!!~~~~JJ...^~^^:   .!PBGY?5P55PGB#&B: :#&P!JGGGPY~~^^...   :5J?7^^::YJ!55.77:?~..~J7.....:^..::::....~7?77~:.......................................................
   ................................. .    .....................~7~!..:.~7~~~!PJBY^^~~^^~?J5G5~~~~^~!~5GP57~~!~::!7.      ^::::. ^7!7!~~~~^~~~~~~??. .:^^^. .!PJ~::YBGGBB#&&&B^.7&&&5:^5GGP5?~:.     .5Y???^::^JPJ5^J!^?^:..?J!.....::..:^:::....:!???7~:....................................................
   .................................   .  .....................7!^!^.:.~?!!~7GJB5^^~~~^~?55PP!~~~^:7~7BP57~!~^:~7:   ...~^~~^..^^. .^!~^^^^^^~~^^!!.. .:^^..:  .:^#&&&#BBBG#PPB&&&&&!:^PPY?J7~:..   .Y5????~^~7PG5YY~J?:^..^JJ!......::.:^:::......~7???!^..................................................
   ........................ ......... .  ......................?~:7^.::^?!7~J5Y#P^^!~~^~?5GPGJ^~~~^^7~5GP7~^^:^~~.::^~^!!^^^^^^.     .:^:..:^^^^^^^^..  .:^.   .^^B&&&BG5PBB#PP#BB#&~.:55~!^:..      ?5J?777!~7YGGBYJ57.^:..!JJ!......::.:^:::.......^!???7~:...............................................
   ......................       ...............................J^.!^.::^?7?!??PGG!^7~~~^?YGPG5~~~~^:!77G57~^^^^~!JPB#BG##B#BBB5^.       .:. ..:^^^^^^:.   .::   . ~&###Y7YBBGJJBBG#B.  ^^:!:...  ..  !5J?^!!~77?YGGYY5J.~^...7JJ!.......:::^^:::........^7???!^:............................................
   ....................  ..  . ...............................:J:.^~..:^??J77!GYPJ^Y!~!^?YBGPG!~!~~^^?7JP~:^^~JB&#B#BBBBGB#Y:!#&Y^        ..    .::^^^:..   ..     J#BG57!~!~!75PBB^   .::!. ..  ... ^5YJ^:77^!JJYG5P?J:!!....?JJ7...:^..:::^^:::.........:~7??7~:..........................................
   ......................       ...................  .   .....:J:.:!..:^??YJ!!B?YP^Y?!!~!YGGPGJ^!~^^^^??J^~!Y#&#J~PPPGG##&#! :#&B!.                 ..:::.          ?B57:.....^?P5^    .:^~  :.  ....:5YY!::?Y~~J5PGY~J:~!....:JJJ?:..:!^..:^^^^^^...........:!7??7~:.......................................
   ......................   ............. ........   . ..   ..:J..:~^.:^?JYJ~JB?J5!?Y77!!YPGGGP~!7~^^^^?77~?##G~:^####&&###BPB#&&P.                     ...          ~57:....:7J!...   ..!^ .^.  ::.::5YJ?^..75?~JGG!!J:^~.:...^YJJJ^...!?^..:^^^^^:............^!7J?7^:....................................
   ....................................    .   ....  . ..   ..:J..:.^::^!JYJ^PP?JYJ~P7?7!YPPPGG7~?!^^^^^7!!GBB7:::5&&&##GP5G#BB#G#^                                   .~^^^^^^^::...   .:!. .~. .^:.!^YY??7:..!YY~JP^J7:^7.:....~YJJJ~...~J7:.:^^^^^:..............^!7J?!^..................................
   ..................................   ..  .  ....       ....:J:.:. ^^^^YYJ?GJ?JJY~5Y7?!?GP55BY~7?~~^^^:!7YGB7:::^P&#GGB?JG#BY5G#!                                 ... ............  ..~^. :~...^:.J^YYJ??7^:.^J5~?!5^:~7:.:....!YJJY7...:JJ~..:^^^^:................:!??7~:...............................
   .................................   ..   .  ........ .......?:.:. ^~^:JYYP5?JJJY7!G???7PGPYGG~!J7~~^^:^?~!?J^^^. ~BBPPY77!^:^?P~                               ..................  ..!.. ^~...~:.5~?YJ?77?!:.:JY!5?.:!!::::..::!PJ?YJ^. .7J!^:.:^^^:..................:!??7~:............................
   ....................................  .     ................?:..::^^:^?5GG5JJYYYJ~YG?J?YGPY5G?~YJ7~^^^:^7~^:...    ~PP57.....!5^                              ..................  ..^....!~...~:.5~^YJJ?!7J?~::JJG~.~?!::^:::::.?G??J57. .^?!~^:.:^^:....................^!??7~:.........................
   ....................................    ........:^::~.......!^..::^:..~5GG5JYYYJJ?^PPJJJGG55PY~?P?!^^^^.^7~!:        ^7?~::^~~^...                            .................   ..^ . :7^...!^.Y7.JJJJ!~7JY?77PY::7!7:~7:::::^.PGJ7?YY^. .!!^^^:.::::.....................:!??7~:......................
   .............................................~::~.  ^^.^^.  ^~..^^^.:::5BGYYYYJ?J?~7BPYJYG5555~!P57~^^^^.~!^7^.    ....^^::.........                           ..............     .:  . ~7^:..!^.JJ.7JJJ?~^^75YJ5P^J!J?^~5~::::^:^GG5?7J57. .:~^::::.:::.......................:~7?!^:...................
   ............................................^^   ...   .~...:7..:^:.::?BBPYYYY?J?77!JGPYJPP555!~YG?!~^^^^.~^^7^..  ...................     ..                     .......        .:   ..77^:.:!~.?Y.~JJJJ7^~!!5Y5P5!!5?:~PY::::^^.7GGPJ77YY^. .^~^::^:.::.........................:~77!^.................
   .............................................~:   ^:  .^^....?..^^..:~PGBPYYYJ??77?G!YPPYYP55P7~?B57~^^^~~.^^~~:......................                                           .   ..:Y7^:.:7~:?5::JJJJJ~:!?7YPP7.~Y7:^5P7::^^^:.5PPG57!?Y?:...:^::^^:.::..........................:~77~:..............
   ............................................^~  ..  .. .!... !::^:.:^JGBPGYYY???77PG57Y5P55P55?^!GP?7~^^^!~.^^^~.....................                                           .    ..~57^:.:7!:?Y!.7JJJJJ^:~J?5P^.7Y!^~Y55^:^:^^.^GPPGPJ!!?Y~....:^^^^^::::...........................:~77~:...........
   .............................................:::~:  ~^::.....:~:^..:!YGPY55YJ?77!JG5P57?Y5P555J^~PP?7!~^^~7!.~^^~. .................                                           .    .:.J57^^.:77^?JJ.~J??JJJ~:^J5P!:YJ~!7JYPY:::^^^.7GPPPP5?!!??:....^^^^^::.:::...........................:~7!^.........
   .................................................::::.........~^: .^!PBJ5YYYJ77!7PP555Y??JY5GPJ~~5PJ!7~^^^!J!.!^^!: ..............                                            .    :7.:PY?^^::7?!??5^:J????JJ!::JGY7P7!J!JY5P?:::^^:.YP55555Y7!!?!.....^^^^::..:::............................:~7!:......
   ............................................................. ^!..~~YGP75YYJ?7!!YP555YJJJJJJ5GY~~Y5?!J!~^^~75~.7~:^:  .                                                           !J!.7GJ?~^::?J?J7Y7.7????J7?!^:YGGJ?YJ!YJJ5P!.::^^.:PP5555Y5J7!!!:.....^^^:::..:::.............................^77~:...
   ..............................................................^~ ^^?G577PYJJ7!!?P555YJJJJJJJY55!~Y5?!Y7~^^^!?P^:YJ??^                          ..      ..                       :???^:5PJJ~^^:?JYJ7?J.~????J!~77~!PP?YJ!5YJJJ5P~.::^:.!GP5J55YY5J7!!^.....:^^^::...::::............................:~77^.
   ..................................:?J?^~^....................:^:^^!PJ7!?PYJ?7!!Y555YJJJJJJ??J5Y!~J5?!?Y~~^^~7JG^:YJJY~                         ..                             .7J7??:7GYJJ!^^^?J5J77Y~:?777J?^!~!JJ5JJ7J5YYJ?YPP^..:::.?GPPJJ5YJJYJ7!~:... ..^^^:....::::.............................:!7
   ................................:7?JJJJYJ^...................^^^^~5?^?~JPY??7!?555YJJJYJ????Y5Y!^?5?7!57~~^^7?P5~^5J?Y7.                                                    :!??7777:YPJJ?7^~~JJ5J7!J?:7777?J~:7!^?YY!5J5JYYJ?YP5:..:::.YPPPY?JYJ?JYJ7!~:... ..^^:......:^:..............................
   ................................:?J?JJJJ?:..................:^~^^J7:!7~YP5?7775555J?JY??????YYJ!^?577~JY~~~^~7JY?^^5?7JJ^                                                 :^!7777!7!^5Y7J??~^~JYYJ7!7J:~?777J7^:7J!YJJ5Y5JJYY??YGY....:.:5PP55J7JYJ?JJJ7!~....  .:^:.....::^:............................
   ..................................~JY7!?!...................^!:^7!::?~~YP5?77?555J?JY?????7JYJ?7^7P77~757~~^^77Y!?~^YJ??Y?^.                                           .:^::~!77!!?^75?7J??!~~?PYJ7!!J~:?!!!7?!^:!JY?5Y5YJJ?YY??YGJ....:.:5PP5YY77JJ???JJ?7~....  .:^:.....::^:..........................
   ....................................:......................:~:^!~::^7~~JP5??7Y55Y??YJ??7777JY?77^!57!~~JJ!~~^!7?77?!^YJ7YJ??7~:.                                    .:^::::.~!!!!!7:J57!?J77~~7G5J7!!??:?!!!!7?7!^~YY5JPJJJ??YY??5G7......:5P5YJ5?!7?J?7??7?7~:...  .:^^.....:::.........................
   ...........................................................^:^!~:::~!^~JP5JJJ5YYJ?JJ?77777?JJ77?~~Y7!!^7J!7~^~7!?777!~YJJJ777777!!^:..                           .:^:::::...^!~~~~~~YJ7!7J7?~~7YGJ!!!7J^?!!!!!!!77!?5?YJJJJJ7?YY??5G!......:5P5YJYY7!7??777!!7?~....  .:^::....:::.......................
   .........................................................:::~!^:::.J~^~?P55YYYYY?JY?777777?J?!!?~~J?!!^!?777~~!!77!!!!7YYJ777!!!!777!!!~^::..                ..:^:::::.......Y5YJ?~!?J!~!???!!!!G5!!!!Y~J!~!!!7?JY5P5555GGGP5JJ5Y??5P~......:55YY?J5J!!7??777~~7?~....   .:^:.....::.....................
   ........................................................:::~!^:::.7J^^^7PPP55YY?JJJ7777!!7?J!!!7!^??~~~~7?~?7~!7!?!!~~!7YJ?!!!!!!!!!!!!!!77!!!:::....    ..::^::::::.........7GGGG~77J!^~!7??7~~7P7!!!Y7J!!7?Y5GGBB#BB##BBBG5JJYP5J?5P^......:55JY?75P?!!7?77?!^^!7^.....  .:::.....:....................
   .......................................................:.^!!^:::.~J?^^^7PPPPYYJ?JJ7!!!!!!7JJ!!!77^?J~~~^!?!!J7!7!7!~~~!!!JJ?7~~!!!!~~~!!!!!~!?::::::^^::^^:::::::............:PGG5:??J7!!!!7??~~~JJ~!~JJY7?JJYPGBB###G##B##BG5J?5GG5J5P^.:....:Y5??77YGY7!!77777~::~7^.....  .:::.....:..................
   .....................................................:..~!!^^^^:~7?7^^^!PPPPYJ?JJ?!!!!!!!?5!!~!!7^7J~~~^~!7~?J??7!7~~~~~!!!7J7!~~~~~~~!~~!7J5J:::::::::::::::.......... ......~GG5:??JJ!?~~77?7~~~Y!~!JJPPG5JJP####BGP5GBBBBB#BPY5BBBP55^.:....:YY7?7!JPGJ!!!777?7~::!7~.....  ..::......................
   ...................................................::.:!~~~:..:^~~J!^^^~5P5PYJ?J?7!!!!!~7YY~!~!!7~!J~^~^^~!~~JYJ?77~^~~~!!!~~7??!~~~^!!!7?5GBJ:::::::::::::.........      .....!GY:?~?Y7Y!.^!??7~~!J!!JJGBBG5B#BBBBGPPYJPGBGP5PGBG5GBBYJ5^.:.....JY77!!?5GP?!!!7777!^:^~!~:....   .::....:...............
   ..................................................:..~7^^~~  .^:^~J!^^^~JGPPJJ???!!!~~~!7J7~~~!!!~^?!^^^^~~!~!YYJ?!7^^~~!~~~~^^~777~~~775BBBB!::::::::............         .....~7:77JY?Y^...!7?7~~!77YYBBBB##PGBBP5PP?7JYPBBGYJJ55YGPJ7J5^.:.....7Y!!!!?5PG57!!!7777~^:^^~~:....   .:::...:.............
   ...................................................:!!^.:~: .:^:~~??^^^^7PGPJ???7~~~~~~!77!~~~!!!~^7?^^^^^~~~~!J5J!7!^~^~~~^^^^^^~~!!7??YGBB?::::..............              ...:^:77?5Y7.....~7J?!~!JPJYPGBPJJGBPJJ5P?!7JYYPBGJJJ??YP5J7?Y^.^.....~J!!~~7Y5GPY!!!!777!~^:^^~^:....   .::::.::...........
   ...............................................:..^7~:::^~. .^.~~~?J~^^^~JGPJ???!~~~~~~7!7~!~~!~!^:~7!^^^^^^~^~~755?7~^^^^~^^^^^:...:JY??YY~.................                  .:^:!!!PY:......~7?J?!!J7^~~~^!Y55JJ??Y??!7JY7JYYYYY?7YGPJ77Y~:^:....^7!~~~7JYPP5J!!!!777!^^^^^:::.....  ..::..:..........
   ................................................:!7^::::~~  ^.^~~!J77^^^:7PBJ??7~~~~~~!7^!~~^~~~!^^^!!~^^^::^~^~~~?Y5J~^^~^^^:......:JJ!~~..................                   :^^:^JYP!........~7~!??777~^^~YGGP7J?7?YJ?!7Y?!7YGGGGJ7YGPJ77J!:~:....:!!~~~7JYPPP5?!!!!!!!~^^^^...:.....  ..::.::........
   ............................................:..^!!^::^::~^ :::!~~??!Y!^^.~JBY77!~~~~~~7^^~~~^~~~~^^^^!~^^^^::^^^~~^^~Y57:.::. .......??~^~................                    .^^^^:J5~?:.......:~J^.~??77!^^~7??7J?!!JJY?!JJ77~JBBG777JPPY7!J7^~~.....~!~~~!JYYP5PY!!!!!!~^^^^:..........   .:::^:......
^. .............................................:~~~~::^:.^~::^.~~~777~?Y^^..75G77!^^^~~!!.!^~^~~~!^^^^:^7~^^^::::^^~~~^:^???::.........!7~^~:....                              :^^^^7~!7.!!::::::^:!GP!..^7???7~^~7?7~^^^~~~~!7!7!~7P?777!JPP?!!J?~!7. ...~!~~~!JJ7555Y7!!!!~~^^^^:..........    .:^^:.....
!^.:......................................... .^^^~~:.::..~~:^.^!~!7!!!~G7^^.:?GJ7!^^^~~7^^!^~^~~~^^^^:::~7!^.....:^^!~~~^.:!:^.........:?!^~:...                              .^^:^75J~?!:?^::::^^!~!YY~:...~7?J?YY!~~~~~~~~~~^^^^^^^^~7YYJ55Y77!?Y!7?: ...^!~~~!??^JJJJ!!!!!!~^:^^:...........   .:~~^....
^:.::........................................:~^^~^..^:...~^^.:7!!?7!!7:5P~^:.~?P7!^^^~~!:~~~~~~~:.......:~77~^:.:::^^7?!~~:..:::........~?~^~^                        .     .:^:^~?5Y^:7?!~?^::^^!BP7?!^~~:....^!7???7!!!~~~~~~~~^^^^^::~?PGG5?!7!?Y77J^....^!~~^!?7:7?7?~~!!!~~~^:^^:...........  .::~!^..
^..::.......................................~~:^~^..^:...:~~:.~7^!?!!!7~~G?~:..~?Y!~^~~7~:~~~^:::.....:::::^~!7!^:..:::!5J7!~^^~!~::::::::77^^^.                      .      :^::~J5?::^^~777J^^^!GP~7?~~!!7YY~:...::~!7???77!!!~~~~~~!!!!!7?7JY!~7!?5?7J!... ^!~^~!?!.!7!7~^~!!~~!~::^^:........... .:.:!7^
...:....................................:::!^:^~~..::....^!~.:?~^?!!!!!?:YJ!^...~??~^~~7^^~^....:..:::::::::^^:~77!~::::^J5?7777???!^::^~~!?7^^^.                    .     .:::^!Y5!::::^^:^~7J~^5P!~?5J777JJ7~~~^:......::^^^~~~~~!!!!!!77~^::~7~~7!?5J7J7:.. :~~^~!7^ ~7~7?!^^!!~!!^.:^:.............:..:7
.  ....................................::^~::^~~..::.....~!:.7!:!?!!!!?J^^Y~!:...~?7~~!!::.........::.....:::^^^^~!7??7!~^!???5J?77777~:.::~?7^^:                  .:.    .^:::75Y^..:::::^^^^:7BP7~~!J!!!!~~^~~~~~~^^^^::........:::^^~~~^::....^^~7!75J!?J~....~~^~!!. ~!~75Y!^~!~~!~:.^^:............:. .
^^:...................................::~~.::~~:.::......~~ :7:.?!~!!7J^~:7?^!.  .~!~~7^:......:...^.......::.:^^::^^~7?JY?!!7PB?7?7777!:.. .::^^^.               ::  ...::^^^?GY:.........:^::^!~~!~~J~~^::...:::::::::::::::^^^^^^^^^:::.........:~7!7Y?!7?7:. .^~^~!~. ^!~!5Y7~!7!~~!^..^:............:.
!~:..................................:^!^.::^!:.::.......!..!^.~7~!!!J7.^~:?~^~.  .^~^!:...........:............::..::::^~?J?!!??J5YYY?77^.      .^:....       .::.  .  :^::^5B?.....    ....7G~......^:........              ....^::::::.....  ....:~!!7J7!~7?!:. :~^~!^..^~^!5Y!~!7?!~!~..:^:...........:.
^.   ...  .....:.:::................:^!:.:::~^..^:......:~ :~..7~~!!J?~.^^^:?~^~^. .:~~:..     ........................::^^^:^!!77JJ7~::^~^..      ..:::.    ...      .....:5G^          .  ?G!...:.................. ..... ....:JG5P!......~^.    ..:~!!!?!~~~!?!: .~^~!: .^~^!YY7~~!??!~!^ .^^:..........:
:. ..     :^...   .^^::.............~!..::.~~..^:.......^:.^:.~!~!!J??::^^^^~?^:~!:  .~!~:.  .........           .............::!!^~!!~^^^^^:::...    .^^::..         .   :5J.         ....^~:                          ........YB#PGG.     ~55?.     :~!~!7!~^^~!7!..~^~~. .^~^~!!!~~~7J7~!~. :^^..........
~^^.      ::::     .^:^............!J..::.^~:.::........:..:..7~~~7?77.:^^^^^!?^:^!~. .:!!~:.      .:.          ............ ....~J:.^^^~!~^^^^::^..:^~!!~!~.            ~57          .:...          ....                       ..^7Y5?      J55!..    .^7~~7~^^^^~7?~:^^~~. .^^:^^^~!!~~?J!~!: .:^:........
?7^::.....:^:.    .:::^...........75:.::.:~^.::....... .: .:.~~~~!?!7~.^^^^^~^!7^^^!~:. .^!!^:.    .:.       ....              . .JY..:......::^^~77!!!^...^!~.        .?5^         .:.. .......::^^^..                            ^YY5:     !557 ...    ^7~~!~^^:^^~7?!!^~^ ..^::^^:^^~~~7J?!!^...^:.......
??77!^:::^~^:....::::::..........!P~.::..~~..::.. .... :.....!~~~?!!7:.^^^^~^^^~!^^~ .... .^~^^^:.  ..                    ....... :PJ..^..........:~~~^^^:..:!7^.     :JJ.         .:..............                               .:JY5!     ^55J   ....  :!!~!~:^:^^^~77!~~: ..^..^^^^^:^~!?J7!~...:^:.....
 .~777!~^^^^::^::::::...........^57..^:.^~:.::. . .....:... ^~~~77~!7..^:^^~^:^~~~~:    ... .^~:::^:::              ...............~GJ.:^...........^^^:^^:::.^7~:   ^5?         .:....:::...            .....                    .:?55?     :55Y      ... .~~~!^::::^^^!7!~^. ..^..^^^^:::::!JJ!~:...^::...
.  ...::::........:::..........:5J:.::.:~~..^:... ... :: ...!~~!?~~!!.:^:^^^^:::~~7:      ... .^~^..^~^.       .....................^7. ...  .       :^:::..:::^7!:.7G~        ..:.::^~^..         ...::^!~:.                     ..?55J     :YYY.        ....^~7^^:::^^^~!!~^...:^..^^^^.::..:7J7!^...:^:..
!!^::::::.......:.::::.........?Y~.::..^~:.::........:?... ^!^~7!^!!!.::::^::::::~~~^:..  ..... .:~^..^^~^.  .................   .    ^?. ..          ^^..:  .::^7!!P:       ...:::^^:.       ...::::.....      ..               ..:?5YY.    :YYY.           ....^^^::::^^^~~~^...^:..^^^::^:...:7J!~...:^^.
777!~~^^^::::::.:::^:::.......:J7:.^:..~~.:^:.......^?7....~~~!7^~!!!.:::^^.:::::^7~!!!~~^^:.......:~^:..:!~:..............           .Y?  ..         .~^... ...:!?!^        .::::..    ......:::...           .......         ....:75YY.    ^BGY.             ..  .:::::^^^^~~^...^..:^^:.^:.....:!7!:...^^
?77!!!~~^^^:::::^:::::........!7!.:^..^~:.::.......~!J~ . .!^~7~^~!7!.:::::.::.::~~^~!!!!~~^:.........^~^.:^~!^..........              .7?. ..         .!:......!5!!!.      .::......::^:......           ....::..          ......::?5YY.    7B#5                .   .^^::^^^^^~^...^..:^^::^.......:~!^...^
J??7!!!~~^^^:^^^::::.........^7!^.::..~~..^:.....:~~7J^ . ^~^!!^^~!7!.:::::.::.::~..:^~~~~~~~~^:.......:^~~:.:~!^.....                   !5^ ..         ~!.. .:JJ. .!:   ..:..::::::.........      ....::^^^^~:.    .............::^Y55J      :?!                 ..  :^^::::::^~^..:^..^^::^:........^!~...
YJ??77!!~^^^^^:::... ........^77::^:..~^.:^.....:~:~!J: ..!~~!^^^~~7~.::^::.::..:!:  ..:^^:^!!!~~^:..:!:..:~!^:.~!:                       ~J. ..        ..   ^5!    :^   ...:.....  ...........:..:......::..     ..............::^~5557                            .  ^^^::::::^~^..^: :^^^^:.........:!~:.
JJJ??7!~~^^^^::.............:^7!.^^..:~^.::....^^.:!!?.. .!^!~^^~~~~^.::^^:..:..^!!.    .::....:^^!7??~.....^!7~::~^.                       .!...          .7J.     .^   .7Y:    .........::::...      ...     ..:^^^^^^^^^~~!?JY5PGGY5^                             . .^^:::::::^~^..~..^^^^^...........~!^
?!!??!~^^^:.................^:?!:^^..:~:.::...^^..:!!7.. :!^!~^^~~~:^.:.^^:..:..~^:::......:.....^~7?!!!~:....^!7!^~!.                     :JP55Y7!:      ~Y!       :.  ^5P^    .:::::::::..         ...    ..:~~~~~~~~!!!777J#B####GYY.    YJ^                       . .^^:.:::::^~:.^^..^^^^:...........^!
!!7!7~:^:..................:^:?!:::..^~:.::..~^...~!!7.. ^~~!^^~~~::~...^^:..:..~^..:~~......:.:^^~~....:^~^.. .^7?!!7:                   757::?5?~?Y~..:??.        :.:JBG?7:    ....             ........:::::::::....::::^!?BBB###G5!    :P#5.                       . .^^:.:::::^^:.~:.:^^::............:
7~!!7?!^:..................:::?~:^:..^~..::.~:..:.7~!7...!~!~^^~~:::^...^^^.....~^^^...^^:....::::~...    .:^:.  .^!77?.                 ^P7    .7?~~Y5??:       .:^YGGPYJJPB?                  .......:^^:..    ............^PBBB##BP:    YGG~                         . .:::.:::::^^::~..^^^::...........
J7!~~7JJ^::................:::?~:^:..^~..:^~: .:.:7~!?. .!~7~^~~:::..:..^^~.....~~:......:::....^^....       .::... .^77.                !5~     .~?JJPG7     .~YG#BGJ^...:!BG.                .....:^::.            .........^GBB#BBP:.. ^55Y                           ..  .:::::::^::^^.:^^:::...........
YY7~~~!77~^:...............:.:?!:^:..:~:.^^:..:: ~7~!?. .!~7^^!^:::..^..:^!....::........ .:^^^~~.......        ....  .!!:               ^5J.  ....~??JYBG!:^YB#BP?^.      ^BG.              .::::::.                 .......:.^GB#GP!....Y55!                            .    ^^:::::~::^::^^^:::..........
5YJ!~~~!7?7^:..............:..7!:^:..:^::^:..::..!!~!?. .!!7^!^:::...:..:^~^..:!.............:~7^...   .....      ...   ~!~              .^!?77!!7Y5!~~7P##B##5!.          !GY                                         .......:.!B#GY:.. ~5YY.                             .    :^::^:^^.^^:^^^::::.........
555?!!!!!!?J555?~:.........:..~!:^:..:^^^^:.:.. .!~~!J. .!77!~^:^:...:...^~~...^~:..... ...:::~^......      ...     ..  :.^!              .:..^!7~~~~!Y#G7^!BBPY!^:..     :55:                                         ..........J#GJ....Y55!                               .     :^^^:~^:^:^^^^:::.........
5P55J77777?J5G#B5YJ~::.....:..:!^^:...^^::::... :!~~!J: .~7?!^^:^:....:..^^~....^:...   ..:.:^~....                 .   .. :!             :~!~^:....:?G!   :5B^^!7??Y555YYGG:                                           .........:BG!....5BG7                                .      .^^:~:^^:^:^^::^........
Y55YJ!:...:^~!J~^~?5J7^:.......~^^^..:^^::^:....:!~~!Y^ :~?7~^~^::....^..^^~:..:^.... ...:.:^^:....                 .   ::  .~          ...:^.      ^B!  ...~B? ..:..::^~!~.                                             .........?P^....?BBY                                 ..      ^^^^:~:^::^^:::.......
???7.           .~!!Y557:::....^~^^::^:^^^::....^!~~~J~ :~7~~^^^:::....:.:^~~..^:.......:::^^^....                 .    ~.   :.          ...        ?B:..    5B.  .                                                       ........:Y:..:.7PB5                               .  :.      :^~:^^^^::^::::......
Y7:       ..    ..7!~~JBY^.::...~^^^^:.:^:.:....~~~~~J7 .!!~^::^^:::...:..^~^:.^.......::.::::...                      .:     .      .....          JB:      :BY                                                           ........7:..::Y555.                                 .^.      :~~^~:^::^^::^:.....
?      .:~:.......:^~~~7GG! .~:.:~^^^..^^^.:.. .!~~~~?J..!7~^:::^^:::.....:^^^.:..:...:::.::^....                     .:             ...           .J#~       ~#7  .                                                        .......^:...:JBGP.                                  .^.      .!^!^^:::^^.:^.....
    .....      ...  ..:~!P#J ~57^^^^:.^^.:^:....!~~~~7Y:.77~::^..^^:::..:.:^~^~:..::::::...:^...                     ..             ..            . :BP        7B~                                                          .......:^....!#BB^                                   .^...... ..::^^:::^::^:....
..           .........::!!P#^ ~5Y~^^^^^...^:.. :7~~~^7Y~.7J^::^...:^:::..:.^~^^...::::::....:....                                  :.           .    ?B~        ?B~                                                          ......:^.....75G7...                                 .::::...      .::^^::::...
         ...          ..^!!P7  7557^^^:....... :7~~~^!Y~.!5~:::....:^^::....~~^...::::......:....                                 ..           .     .J5^        7B!                                                         ......:J...... ..                                     .^^^::::.       ..::::..:
      ...         ........~!!   J5Y::^^......  :?!~~~~!^:^57:^:......:^::::.^!:....::.......:....                                ..                   .?5^        ~P7                                                        ......^B:.....                                         .^:^:^^:.        ...^::.
   ..          ...     ..:!7!^  ^55?  :^:.:..  ^?!~~~~^^^.J?^::........^:::::!.............:::...                               ..          .           !57        ^5J.                                                     .......7#?......                                         .:::......   ...   .^^:
  ..        ...           :~7!^ .GP5.   :^...  ^?!~~^~^^~:!?~:^:........:::::^.......:::::.:::....                             ..         ..             :YJ.      .:?5!                                                   ........!BB:....J57.                                        .:::........      ^^:
         ...        :!!~^:.:~7!  PBG:    ...   :?7~~~^::~~:?!~::..........::^:...:..::::::::::......                           :         ..               .75!     .. ^5Y:                                               .........:^Y#7... ~BBB~                                        .:^^::..   ..    ^^:
       .:.        :?PGGPPY?!!77. PBB:      ..  :??~~~^::^!:!!~^^:...........:.....:.::::::.:::........                        :.        ..                  :YY:   ..  .757.                                          ............~:~BG... .Y55?                                           .:^^:    .....^^:
       .        .7PGPJ77!!!7?J?..PBB.       .:..?J!~^::::~!^!^^^^:................:::::::.....:..........    .               .:        ..                    .~5?. .   ..:J5!                                ..  ............::::^^:.Y#7    75Y5.                                            .:^:      ..^^^
       .      .~5GGP5Y7!~~~~!!?^.GBG.         . .!7~~:::.~!~^~^:^^:...........:.....:::::.....:...........   ....           .^.       ..                     ...757:    ...^5P~                         ... .... .....:::::^:::::!^:.:GG.   .5Y5!                                              .::     .:^~^
             .7BP5PP55Y7~~^^~~!!:.!?.          .  .^~^^:.^!!^^^^:::......:.......:.....:::.....:........... ..::.....      .:~.  ..   :.                      .. ^55:  ... ..^YY^..                    ... ......:..::^^^^^^^^^^!~^~:.7#7    !5YY                                            ...:::.......~^
~            :^J5J5555YY?!~^^^~!!:                  .::. ...             .::...:..:::..........:........... :::::.:.::......^^ ..... .:.                      . .^^JG7....  ..:7^.::.   ...........  ..:...::...::.:^^^^^^^^^^^~~^::~^:YB.   .YY5^                                                .:..  ..:^
P!  .         .:~JJYY55YYJ!~^^^~~!^                   ..                   ::........:::........:.......... .::::..::^::::::~:.......^:...               ..  ....^~^^GY^::...~!77!~..:............ ......::::..:::::^^^^^^^^^^~~^^^::^^~GJ    ^55J                                                  .....~~~
PB^  .         ..^7JJYY55YJ7~~^^^~!~.                  ...                  .:.....:....::.......:....:......:.:::.::^:::::^~..::::::^^:........................::^~.!!..~:..^!!~~!:.~~::::::::.........:::::..::::^^^^^^^^^^^~:^^^:.::::5~    ?55!                                                   ...~!!
5BB~            ..:!JJJY55YY7~~~^^~??.           .        ..                ..::....::...........::....:::.......::.::^::::^~.:::::::^:^::...........:::....::..::~~^77^:!^:::~!!!^~!!..^:::::.:::.....::::^:..:::^^^^^^^^::^!^::^^^:.::.:J.   .Y55^                                                     ..^
.5B?             ..:~?JJY55P?.!!!!~!?~.           .         .                .....::.:::..........^:..:..:::..::...:..:::::~^:::::::^^::^::::::::::::::...::::..::~.^777^.:^::^~!!!^!J~.:^::::::::::..:^:^^^..::::^^^^^^^^::7!~^::^^^.::: :~    :GBG:
 .:                ..:~!!!777:~~^^^^~.^                                         ...................^. ....... ........ ....:........::........................ ..::.^^^~^:::....^^^:.^~:............ .:...:. ........::::..:^^::....:....  ..    .~?J.
 */
/*
 * powered by ANDRIY POPYK
 * in honor of MYSELF and SEGMENT DECOMPOSITION and N^(log(N)) and (Harry Potter and the Methods of Rationality) and Monkie D. Luffy
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,sse4,popcnt")

using namespace std;
using namespace __gnu_pbds;
#define int long long
#define float long double
#define elif else if
#define endl "\n"
#define mod 1000000007
#define pi acos(-1)
#define eps 0.000000001
#define inf 1000'000'000'000'000'000LL
#define FIXED(a) cout << fixed << setprecision(a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define time_init auto start = std::chrono::high_resolution_clock::now()
#define time_report                                       \
        auto end = std::chrono::high_resolution_clock::now(); \
        std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << endl
#define debug(x) \
        { cerr << #x << " = " << x << endl; }
#define len(x) (int) x.size()
#define sqr(x) ((x) * (x))
#define cube(x) ((x) * (x) * (x))
#define bit(x, i) (((x) >> (i)) & 1)
#define set_bit(x, i) ((x) | (1LL << (i)))
#define clear_bit(x, i) ((x) & (~(1LL << (i))))
#define toggle_bit(x, i) ((x) ^ (1LL << (i)))
#define low_bit(x) ((x) & (-(x)))
#define count_bit(x) __builtin_popcountll(x)
#define srt(x) sort(all(x))
#define rsrt(x) sort(rall(x))
#define mp make_pair
#define maxel(x) (*max_element(all(x)))
#define minel(x) (*min_element(all(x)))
#define maxelpos(x) (max_element(all(x)) - x.begin())
#define minelpos(x) (min_element(all(x)) - x.begin())
#define sum(x) (accumulate(all(x), 0LL))
#define product(x) (accumulate(all(x), 1LL, multiplies<int>()))
#define gcd __gcd
#define lcm(a, b) ((a) / gcd(a, b) * (b))
#define rev(x) (reverse(all(x)))
#define shift_left(x, k) (rotate(x.begin(), x.begin() + k, x.end()))
#define shift_right(x, k) (rotate(x.rbegin(), x.rbegin() + k, x.rend()))
#define is_sorted(x) (is_sorted_until(all(x)) == x.end())
#define is_even(x) (((x) &1) == 0)
#define is_odd(x) (((x) &1) == 1)
#define pow2(x) (1LL << (x))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using matrix = vector<vector<T>>;
template<typename T>
using graph = vector<vector<T>>;
using hashmap = gp_hash_table<int, int, custom_hash>;

template<typename T>
vector<T> vect(int n, T val) {
    return vector<T>(n, val);
}

template<typename T>
vector<vector<T>> vect(int n, int m, T val) {
    return vector<vector<T>>(n, vector<T>(m, val));
}

template<typename T>
vector<vector<vector<T>>> vect(int n, int m, int k, T val) {
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, val)));
}

template<typename T>
vector<vector<vector<vector<T>>>> vect(int n, int m, int k, int l, T val) {
    return vector<vector<vector<vector<T>>>>(n, vector<vector<vector<T>>>(m, vector<vector<T>>(k, vector<T>(l, val))));
}

template<typename T>
matrix<T> new_matrix(int n, int m, T val) {
    return matrix<T>(n, vector<T>(m, val));
}

template<typename T>
graph<T> new_graph(int n) {
    return graph<T>(n);
}

template<class T, class S>
inline bool chmax(T &a, const S &b) {
    return (a < b ? a = b, 1 : 0);
}

template<class T, class S>
inline bool chmin(T &a, const S &b) {
    return (a > b ? a = b, 1 : 0);
}

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;

template<typename T>
using vec = vector<T>;

using pII = pair<int, int>;
template<typename T>
using enumerated = pair<T, int>;

template<typename T, typename P>
struct SegmentTree {
private:
    function<T(const T &, const T &)> comb;
    function<void(T &, const P, int, int)> apply_push;
    function<void(P &, const P &)> merge_push;
    function<pair<P, P>(const P &, int l, int r, int pos)> split_push;
    size_t n;
    vec<T> tree;
    vec<optional<P>> pushes;

    void push(int v, int tl, int tr) {
        if (!pushes[v].has_value())
            return;
        if (tl != tr) {
            int tm = (tl + tr) / 2;
            auto [l, r] = split_push(pushes[v].value(), tl, tr, tm);
            apply_push(tree[2 * v], l, tl, tm);
            apply_push(tree[2 * v + 1], r, tm + 1, tr);
            if (pushes[2 * v].has_value())
                merge_push(pushes[2 * v].value(), l);
            else
                pushes[2 * v] = l;
            if (pushes[2 * v + 1].has_value())
                merge_push(pushes[2 * v + 1].value(), r);
            else
                pushes[2 * v + 1] = r;
        }

        pushes[v] = nullopt;
    }

    void build(int v, int tl, int tr, const vec<T> &a) {
        if (tl == tr) {
            tree[v] = a[tl];
            return;
        }
        int tm = (tl + tr) / 2;
        build(2 * v, tl, tm, a);
        build(2 * v + 1, tm + 1, tr, a);
        tree[v] = comb(tree[2 * v], tree[2 * v + 1]);
    }

    T get(int v, int tl, int tr, int l, int r) {
        if (l > r)
            return T();
        if (l == tl && r == tr)
            return tree[v];
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        if (r <= tm)
            return get(2 * v, tl, tm, l, r);
        if (l > tm)
            return get(2 * v + 1, tm + 1, tr, l, r);

        return comb(get(2 * v, tl, tm, l, tm), get(2 * v + 1, tm + 1, tr, tm + 1, r));
    }

    void update(int v, int tl, int tr, int l, int r, const P &val) {
        if (l > r)
            return;
        if (l == tl && r == tr) {
            apply_push(tree[v], val, l, r);
            if (pushes[v].has_value())
                merge_push(pushes[v].value(), val);
            else
                pushes[v] = val;
            return;
        }
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        if (r <= tm)
            update(2 * v, tl, tm, l, r, val);
        elif (l > tm)update(2 * v + 1, tm + 1, tr, l, r, val);
        else {
            auto [lval, rval] = split_push(val, l, r, tm);
            update(2 * v, tl, tm, l, tm, lval);
            update(2 * v + 1, tm + 1, tr, tm + 1, r, rval);
        }
        tree[v] = comb(tree[2 * v], tree[2 * v + 1]);
    }

public:

    SegmentTree(const function<T(const T &, const T &)> &comb,
                const function<void(T &, const P, int, int)> &apply_push,
                const function<void(P &, const P &)> &merge_push,
                const function<pair<P, P>(const P &, int l, int r, int pos)> &split_push) :
            comb(comb), apply_push(apply_push), merge_push(merge_push), split_push(split_push) {

    }


    T get(int l, int r) {
        return get(1, 0, n - 1, l, r);
    }

    T operator[](int i) {
        return get(i, i);
    }

    T operator()(int l, int r) {
        return get(l, r);
    }

    void update(int l, int r, const P &val) {
        update(1, 0, n - 1, l, r, val);
    }

    void init(int _n, const vec<T> &a) {
        this->n = _n;
        tree.resize(4 * n);
        pushes.resize(4 * n);
        build(1, 0, n - 1, a);
    }

    void init(const vec<T> &a) {
        init(len(a), a);
    }

    void init(int _n, const T &val) {
        init(_n, vect<T>(_n, val));
    }

    void reset() {
        fill(all(tree), T());
        fill(all(pushes), nullopt);
    }

};

using Push = int;

auto split_push = [](const Push &p, int tl, int tr, int pos) {
    return mp(p, p);
};

auto merge_push = [](Push &p, const Push &q) {
    chmax(p, q);
};

auto apply_push = [](int &x, const Push &p, int l, int r) {
    chmax(x, p);
};
auto comb = [](const int &x, const int &y) {
    return max(x, y);
};

SegmentTree<int, Push> st(comb, apply_push, merge_push, split_push);


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vec<int> a(n);
    for (int &i: a) cin >> i;
    vec<int> stackMAX_pos;
    vec<int> stackMAX;
    vec<int> stackMAX_val;
    st.init(n, 0);
    struct query {
        int l, r, k, id;
    };
    vec<query> queries(m);
    for (int i = 0; i < m; i++) {
        cin >> queries[i].l >> queries[i].r >> queries[i].k;
        queries[i].l--;
        queries[i].r--;
        queries[i].id = i;
    }
    sort(all(queries), [](const query &a, const query &b) {
        if (a.r == b.r) return a.l < b.l;
        return a.r < b.r;
    });
    vec<int> ans(m, 0);
    int ptr = 0;
    for (int end = 0; end < n; end++) {


        while (!stackMAX.empty() and stackMAX.back() <= a[end]) {
            st.update(stackMAX_pos.back(), stackMAX_pos.back(), stackMAX_val.back() + stackMAX.back());
            stackMAX.pop_back();
            stackMAX_pos.pop_back();
            stackMAX_val.pop_back();
        }
        if (!stackMAX.empty()) {
            chmax(stackMAX_val.back(), a[end]);
            st.update(stackMAX_pos.back(), stackMAX_pos.back(), stackMAX_val.back() + stackMAX.back());
        }
        stackMAX.push_back(a[end]);
        stackMAX_pos.push_back(end);
        stackMAX_val.push_back(-inf);
        st.update(stackMAX_pos.back(), stackMAX_pos.back(), stackMAX_val.back() + stackMAX.back());

//        if (stackMAX.empty() or stackMAX.back() <= a[end]) {
//            stackMAX.push_back(a[end]);
//            stackMAX_pos.push_back(end);
//            stackMAX_val.push_back(-inf);
//        } else {
//            chmax(stackMAX_val.back(), a[end]);
//        }
//        st.update(len(stackMAX) - 1, len(stackMAX) - 1, stackMAX_val.back() + stackMAX.back());
        while (ptr < m and queries[ptr].r == end) {
            int l = queries[ptr].l;
            int r = queries[ptr].r;
            int k = queries[ptr].k;
            int best = st.get(l, r);
            ans[queries[ptr].id] = (best <= k);
            ptr++;
        }
    }

    for (int i = 0; i < m; i++) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 7 ms 1184 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1748 ms 165016 KB Output is correct
2 Correct 1708 ms 176084 KB Output is correct
3 Correct 1706 ms 175952 KB Output is correct
4 Correct 1697 ms 176304 KB Output is correct
5 Correct 1516 ms 175844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 16300 KB Output is correct
2 Correct 145 ms 16488 KB Output is correct
3 Correct 111 ms 16708 KB Output is correct
4 Correct 113 ms 16704 KB Output is correct
5 Correct 111 ms 16708 KB Output is correct
6 Correct 109 ms 16360 KB Output is correct
7 Correct 107 ms 16452 KB Output is correct
8 Correct 113 ms 16332 KB Output is correct
9 Correct 33 ms 5712 KB Output is correct
10 Correct 107 ms 16200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 7 ms 1184 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 1116 KB Output is correct
19 Correct 292 ms 34604 KB Output is correct
20 Correct 298 ms 35708 KB Output is correct
21 Correct 277 ms 35392 KB Output is correct
22 Correct 277 ms 35272 KB Output is correct
23 Correct 279 ms 35384 KB Output is correct
24 Correct 236 ms 35208 KB Output is correct
25 Correct 230 ms 35128 KB Output is correct
26 Correct 242 ms 35644 KB Output is correct
27 Correct 248 ms 35392 KB Output is correct
28 Correct 238 ms 35404 KB Output is correct
29 Correct 250 ms 35396 KB Output is correct
30 Correct 240 ms 35376 KB Output is correct
31 Correct 255 ms 35484 KB Output is correct
32 Correct 249 ms 35632 KB Output is correct
33 Correct 250 ms 35380 KB Output is correct
34 Correct 226 ms 35120 KB Output is correct
35 Correct 228 ms 35104 KB Output is correct
36 Correct 230 ms 34908 KB Output is correct
37 Correct 234 ms 35112 KB Output is correct
38 Correct 244 ms 35104 KB Output is correct
39 Correct 233 ms 34020 KB Output is correct
40 Correct 170 ms 26444 KB Output is correct
41 Correct 230 ms 33608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 7 ms 1184 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 1116 KB Output is correct
19 Correct 1748 ms 165016 KB Output is correct
20 Correct 1708 ms 176084 KB Output is correct
21 Correct 1706 ms 175952 KB Output is correct
22 Correct 1697 ms 176304 KB Output is correct
23 Correct 1516 ms 175844 KB Output is correct
24 Correct 134 ms 16300 KB Output is correct
25 Correct 145 ms 16488 KB Output is correct
26 Correct 111 ms 16708 KB Output is correct
27 Correct 113 ms 16704 KB Output is correct
28 Correct 111 ms 16708 KB Output is correct
29 Correct 109 ms 16360 KB Output is correct
30 Correct 107 ms 16452 KB Output is correct
31 Correct 113 ms 16332 KB Output is correct
32 Correct 33 ms 5712 KB Output is correct
33 Correct 107 ms 16200 KB Output is correct
34 Correct 292 ms 34604 KB Output is correct
35 Correct 298 ms 35708 KB Output is correct
36 Correct 277 ms 35392 KB Output is correct
37 Correct 277 ms 35272 KB Output is correct
38 Correct 279 ms 35384 KB Output is correct
39 Correct 236 ms 35208 KB Output is correct
40 Correct 230 ms 35128 KB Output is correct
41 Correct 242 ms 35644 KB Output is correct
42 Correct 248 ms 35392 KB Output is correct
43 Correct 238 ms 35404 KB Output is correct
44 Correct 250 ms 35396 KB Output is correct
45 Correct 240 ms 35376 KB Output is correct
46 Correct 255 ms 35484 KB Output is correct
47 Correct 249 ms 35632 KB Output is correct
48 Correct 250 ms 35380 KB Output is correct
49 Correct 226 ms 35120 KB Output is correct
50 Correct 228 ms 35104 KB Output is correct
51 Correct 230 ms 34908 KB Output is correct
52 Correct 234 ms 35112 KB Output is correct
53 Correct 244 ms 35104 KB Output is correct
54 Correct 233 ms 34020 KB Output is correct
55 Correct 170 ms 26444 KB Output is correct
56 Correct 230 ms 33608 KB Output is correct
57 Correct 1722 ms 176740 KB Output is correct
58 Correct 1677 ms 176760 KB Output is correct
59 Correct 1647 ms 176916 KB Output is correct
60 Correct 1670 ms 176916 KB Output is correct
61 Correct 1738 ms 176720 KB Output is correct
62 Correct 1731 ms 176808 KB Output is correct
63 Correct 1287 ms 175060 KB Output is correct
64 Correct 1280 ms 174800 KB Output is correct
65 Correct 1412 ms 176840 KB Output is correct
66 Correct 1465 ms 176900 KB Output is correct
67 Correct 1599 ms 176844 KB Output is correct
68 Correct 1481 ms 177016 KB Output is correct
69 Correct 1474 ms 176664 KB Output is correct
70 Correct 1528 ms 176756 KB Output is correct
71 Correct 1489 ms 176752 KB Output is correct
72 Correct 1494 ms 176752 KB Output is correct
73 Correct 1266 ms 173032 KB Output is correct
74 Correct 1332 ms 174268 KB Output is correct
75 Correct 1308 ms 173304 KB Output is correct
76 Correct 1379 ms 173284 KB Output is correct
77 Correct 1404 ms 173292 KB Output is correct
78 Correct 1491 ms 170612 KB Output is correct
79 Correct 898 ms 117352 KB Output is correct
80 Correct 1499 ms 167780 KB Output is correct