{"problem":{"name":"F. Who has a better strategy ?","description":{"content":"Da'san and Abu Tahun are playing a video game, in that video game there are n monsters, the strength of the ith monster is si, (1 ≤ si ≤ n), where each monster has a *unique* strength. They both can ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10203F"},"statements":[{"statement_type":"Markdown","content":"Da'san and Abu Tahun are playing a video game, in that video game there are n monsters, the strength of the ith monster is si, (1 ≤ si ≤ n), where each monster has a *unique* strength.\n\nThey both can defeat all monsters, Da'san needs ai seconds to defeat the ith monster and Abu Tahun needs bi seconds to defeat the ith monster. \n\nNow they will play together at the same time, Abu Tahun will start killing monsters from the strongest one and Da'san will start killing monsters from the weakest one. The one who reaches a specific monster first will be the one to kill that monster. But if they came to kill the same monster at the same time, Abu Tahun will leave that monster to Da'san.\n\nNow you are given q queries, for each query you are given a subarray from l to r, you should print the number of monsters each one of them will kill, if they both started playing the game with the monsters in the subarray from l to r.\n\nThe first line contains 2 integers n and q (1 ≤ n, q ≤ 2 × 105) which are the number of monsters and the number of queries.\n\nThe second line will contain n distinct integers, the ith one is si (1 ≤ si ≤ n) which is the strength of the ith monster.\n\nThe Third line will contain n integers, the ith one is ai (1 ≤ ai ≤ 109), which is the time needed to kill the ith monster by Da'san.\n\nThe Fourth line will contain n integers, the ith one is bi (1 ≤ bi ≤ 109), which is the time needed to kill the ith monster by Abu Tahun.\n\nThe next q lines will contain 2 integers for each line, l and r (1 ≤ l ≤ r ≤ n), which is the sub-array that was given for the current query.\n\nFor each query print 2 integers, the number of monsters killed by Da'san and the number of monsters killed by Abu Tahun.\n\nIn the sample, for the first query at minute 0, Da'san will start with monster at index 1, and Abu Tahun will start with monster at index 2,\n\nat minute 1 they will both go to kill the monster at index 3, and since they both came to kill the same monster at the same time Abu Tahun will leave that monster to Da'san.\n\nSo Da'san will kill 2 monsters and Abu Tahun will kill 1 monster.\n\n## Input\n\nThe first line contains 2 integers n and q (1 ≤ n, q ≤ 2 × 105) which are the number of monsters and the number of queries.The second line will contain n distinct integers, the ith one is si (1 ≤ si ≤ n) which is the strength of the ith monster.The Third line will contain n integers, the ith one is ai (1 ≤ ai ≤ 109), which is the time needed to kill the ith monster by Da'san.The Fourth line will contain n integers, the ith one is bi (1 ≤ bi ≤ 109), which is the time needed to kill the ith monster by Abu Tahun.The next q lines will contain 2 integers for each line, l and r (1 ≤ l ≤ r ≤ n), which is the sub-array that was given for the current query.\n\n## Output\n\nFor each query print 2 integers, the number of monsters killed by Da'san and the number of monsters killed by Abu Tahun.\n\n[samples]\n\n## Note\n\nIn the sample, for the first query at minute 0, Da'san will start with monster at index 1, and Abu Tahun will start with monster at index 2,at minute 1 they will both go to kill the monster at index 3, and since they both came to kill the same monster at the same time Abu Tahun will leave that monster to Da'san.So Da'san will kill 2 monsters and Abu Tahun will kill 1 monster.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, q \\in \\mathbb{Z}^+ $ be the number of monsters and queries.  \nLet $ S = (s_1, s_2, \\dots, s_n) $ be the sequence of distinct monster strengths, where $ s_i \\in \\{1, 2, \\dots, n\\} $.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be the time required for Da'san to kill monster $ i $.  \nLet $ B = (b_1, b_2, \\dots, b_n) $ be the time required for Abu Tahun to kill monster $ i $.  \n\nLet $ P $ be the permutation of indices $ \\{1, 2, \\dots, n\\} $ such that $ s_{P(1)} < s_{P(2)} < \\dots < s_{P(n)} $ (ascending order of strength).  \nLet $ Q $ be the permutation of indices $ \\{1, 2, \\dots, n\\} $ such that $ s_{Q(1)} > s_{Q(2)} > \\dots > s_{Q(n)} $ (descending order of strength).  \n\nFor a query $ [l, r] $, define the subsequence of monsters by their original indices in $ [l, r] $.  \nLet $ M_{l,r} \\subseteq \\{l, l+1, \\dots, r\\} $ be the set of monster indices in the subarray.  \nOrder $ M_{l,r} $ by increasing strength: $ m_1, m_2, \\dots, m_k $ where $ k = r - l + 1 $, and $ s_{m_1} < s_{m_2} < \\dots < s_{m_k} $.  \n\n**Constraints**  \n1. $ 1 \\leq n, q \\leq 2 \\times 10^5 $  \n2. $ 1 \\leq s_i \\leq n $, all $ s_i $ distinct  \n3. $ 1 \\leq a_i, b_i \\leq 10^9 $  \n4. $ 1 \\leq l \\leq r \\leq n $ for each query  \n\n**Objective**  \nFor each query $ [l, r] $:  \n- Da'san starts at the weakest monster in $ M_{l,r} $ (i.e., $ m_1 $) and moves toward the strongest ($ m_k $), spending $ a_{m_j} $ seconds to kill monster $ m_j $.  \n- Abu Tahun starts at the strongest monster in $ M_{l,r} $ (i.e., $ m_k $) and moves toward the weakest ($ m_1 $), spending $ b_{m_j} $ seconds to kill monster $ m_j $.  \n- Time is synchronized: at time $ t $, Da'san has reached monster $ m_i $ if $ \\sum_{j=1}^{i} a_{m_j} \\leq t $, and Abu Tahun has reached monster $ m_i $ if $ \\sum_{j=i}^{k} b_{m_j} \\leq t $.  \n- Monster $ m_i $ is killed by:  \n  - Da'san if $ \\sum_{j=1}^{i} a_{m_j} < \\sum_{j=i}^{k} b_{m_j} $,  \n  - Abu Tahun if $ \\sum_{j=1}^{i} a_{m_j} > \\sum_{j=i}^{k} b_{m_j} $,  \n  - Da'san if $ \\sum_{j=1}^{i} a_{m_j} = \\sum_{j=i}^{k} b_{m_j} $ (tie-breaker rule).  \n\nCompute $ d_{l,r} $ = number of monsters killed by Da'san,  \nand $ u_{l,r} $ = number of monsters killed by Abu Tahun in $ M_{l,r} $.  \n\nOutput $ (d_{l,r}, u_{l,r}) $ for each query.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10203F","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}