{"id":3901,"date":"2018-12-02T00:33:29","date_gmt":"2018-12-01T21:33:29","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=3901"},"modified":"2018-12-19T00:26:38","modified_gmt":"2018-12-18T21:26:38","slug":"e-olymp-1225-%d1%87%d0%b5%d1%80%d0%bd%d1%8b%d0%b9-%d1%8f%d1%89%d0%b8%d0%ba","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=3901","title":{"rendered":"e-olymp 1225. \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u044b\u0445. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $i$. \u0412 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043f\u0443\u0441\u0442\u043e\u0439, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f $i$ \u0440\u0430\u0432\u043d\u0430 $0$. \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434 (\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439). \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439:<br \/>\n<strong>ADD(x)<\/strong>: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 x \u0432 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a;<br \/>\n<strong>GET<\/strong>: \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c $i$ \u043d\u0430 $1$ \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 $i$-\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u0427\u0435\u0440\u043d\u043e\u043c \u042f\u0449\u0438\u043a\u0435.<br \/>\n\u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e $i$-\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 $i$-\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0427\u0435\u0440\u043d\u043e\u0433\u043e \u042f\u0449\u0438\u043a\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043d\u0435\u0443\u0431\u044b\u0432\u0430\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<br \/>\n\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0447\u0435\u0440\u043d\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<table border=\"1\" align=\"center\">\n<tbody>\n<tr>\n<td>\n                \u2116\n            <\/td>\n<td>\n                \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\n            <\/td>\n<td>\n                $i$\n            <\/td>\n<td>\n                \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0427\u0435\u0440\u043d\u043e\u0433\u043e \u042f\u0449\u0438\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438\n            <\/td>\n<td>\n                \u041e\u0442\u0432\u0435\u0442\n            <\/td>\n<\/tr>\n<tr>\n<td>\n                1\n            <\/td>\n<td>\n                <strong>ADD(3)<\/strong>\n            <\/td>\n<td>\n                0\n            <\/td>\n<td>\n                3\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                2\n            <\/td>\n<td>\n                <strong>GET<\/strong>\n            <\/td>\n<td>\n                1\n            <\/td>\n<td>\n                3\n            <\/td>\n<td>\n                3\n            <\/td>\n<\/tr>\n<tr>\n<td>\n                3\n            <\/td>\n<td>\n                <strong>ADD(1)<\/strong>\n            <\/td>\n<td>\n                1\n            <\/td>\n<td>\n                1, 3\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                4\n            <\/td>\n<td>\n                <strong>GET<\/strong>\n            <\/td>\n<td>\n                2\n            <\/td>\n<td>\n                1, 3\n            <\/td>\n<td>\n                3\n            <\/td>\n<\/tr>\n<tr>\n<td>\n                5\n            <\/td>\n<td>\n                <strong>ADD(-4)<\/strong>\n            <\/td>\n<td>\n                2\n            <\/td>\n<td>\n                -4, 1, 3\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                6\n            <\/td>\n<td>\n                <strong>ADD(2)<\/strong>\n            <\/td>\n<td>\n                2\n            <\/td>\n<td>\n                -4, 1, 2, 3\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                7\n            <\/td>\n<td>\n                <strong>ADD(8)<\/strong>\n            <\/td>\n<td>\n                2\n            <\/td>\n<td>\n                -4, 1, 2, 3, 8\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                8\n            <\/td>\n<td>\n                <strong>ADD(-1000)<\/strong>\n            <\/td>\n<td>\n                2\n            <\/td>\n<td>\n                -1000, -4, 1, 2, 3, 8\n            <\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n                9\n            <\/td>\n<td>\n                <strong>GET<\/strong>\n            <\/td>\n<td>\n                3\n            <\/td>\n<td>\n                -1000, -4, 1, 2, 3, 8\n            <\/td>\n<td>\n                1\n            <\/td>\n<\/tr>\n<tr>\n<td>\n                10\n            <\/td>\n<td>\n                <strong>GET<\/strong>\n            <\/td>\n<td>\n                4\n            <\/td>\n<td>\n                -1000, -4, 1, 2, 3, 8\n            <\/td>\n<td>\n                2\n            <\/td>\n<\/tr>\n<tr>\n<td>\n                11\n            <\/td>\n<td>\n                <strong>ADD(2)<\/strong>\n            <\/td>\n<td>\n                4\n            <\/td>\n<td>\n                -1000, -4, 1, 2, 2, 3, 8\n            <\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 <strong>ADD<\/strong> \u0438 <strong>GET<\/strong> \u0440\u0430\u0432\u043d\u043e $30000$ (\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430).<br \/>\n\u041e\u043f\u0438\u0448\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0434\u0432\u0443\u043c\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438:<\/p>\n<ol>\n<li>$A_1, \\ A_2, \\ldots , \\ A_m:$ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 $2 000 000 000$, $m \\leq 30000$. \u0414\u043b\u044f \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 $A = \\left (3, 1, -4, 2, 8, -1000, 2 \\right).$\n    <\/li>\n<li>$u_1, \\ u_2, \\ldots, \\ u_n:$ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0427\u0435\u0440\u043d\u043e\u043c \u042f\u0449\u0438\u043a\u0435 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0439, \u0432\u0442\u043e\u0440\u043e\u0439, &#8230; $n$-\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 <strong>GET<\/strong>. \u0414\u043b\u044f \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 $u = \\left (1, 2, 6, 6 \\right ).$\n    <\/li>\n<\/ol>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0427\u0435\u0440\u043d\u043e\u0433\u043e \u042f\u0449\u0438\u043a\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 $u_1, \\ u_2, \\ldots , \\ u_n$ \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043d\u0435\u0443\u0431\u044b\u0432\u0430\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, $n \\leq m$, \u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e $p \\left (1 \\leq p \\leq n \\right )$ \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e $p \\leq u(p) \\leq m$. \u042d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043b\u044f $p$-\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 $u$ \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <strong>GET<\/strong> \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 $p$-\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0447\u0438\u0441\u0435\u043b $A_1, \\ A_2, \\ldots , \\ A_{u_p}$.<\/p>\n<h2><em>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/em><\/h2>\n<p>\u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0447\u0438\u0441\u0435\u043b: $m, \\ n, \\ A_1, \\ A_2, \\ldots , \\ A_m, \\ u_1, \\ u_2, \\ldots , \\ u_n.$ \u0412\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u0440\u043e\u0431\u0435\u043b\u0430\u043c\u0438 \u0438 (\u0438\u043b\u0438) \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<h2><em>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/em><\/h2>\n<p>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0427\u0435\u0440\u043d\u043e\u0433\u043e \u042f\u0449\u0438\u043a\u0430 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u041a\u0430\u0436\u0434\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u044b<\/h2>\n<table>\n<tbody>\n<tr>\n<td><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<td><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n7 4<br \/>\n3 1 -4 2 8 -1000 2<br \/>\n1 2 6 6\n<\/td>\n<td>\n3<br \/>\n3<br \/>\n1<br \/>\n2\n<\/td>\n<\/tr>\n<tr>\n<td>\n8 3<br \/>\n5 8 3 7 3 5 7 0<br \/>\n2 3 3<\/td>\n<td>\n5<br \/>\n5<br \/>\n8\n<\/td>\n<\/tr>\n<tr>\n<td>\n10 4<br \/>\n6 3 7 3 8 4 7 4 6 15<br \/>\n4 6 8 9\n<\/td>\n<td>\n3<br \/>\n3<br \/>\n4<br \/>\n4\n<\/td>\n<\/tr>\n<tr>\n<td>\n5 5<br \/>\n1 2 3 4 5<br \/>\n1 2 3 4 5\n<\/td>\n<td>\n1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5\n<\/td>\n<\/tr>\n<tr>\n<td>\n11 5<br \/>\n4 6 8 9 5 3 6 8 10 12 13<br \/>\n6 7 8 9 10\n<\/td>\n<td>\n3<br \/>\n4<br \/>\n5<br \/>\n6<br \/>\n6\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h2>\n<pre class=\"lang:java decode:true \" title=\"Solution\">import java.io.BufferedReader;\r\nimport java.io.InputStreamReader;\r\nimport java.util.Map;\r\nimport java.util.Scanner;\r\nimport java.util.TreeMap;\r\n\r\npublic class Main {\r\n    public static void main(String[] args) throws Exception{\r\n        Scanner sc = new Scanner(System.in);\r\n        int m = sc.nextInt();\r\n        int n = sc.nextInt();\r\n        int[] nums = new int[m];\r\n        for(int i = 0; i &lt; m; i++){\r\n            nums[i] = sc.nextInt();\r\n        }\r\n        TreeMap&lt;Integer, Integer&gt; blackBox = new TreeMap&lt;&gt;();\r\n        blackBox.put(Integer.MAX_VALUE, 1);\r\n        int size = 1;\r\n        int curKey = Integer.MAX_VALUE;\r\n        int curValue = 1;\r\n        int curPosition = 0;\r\n        for(int i = 0; i &lt; n; i++){\r\n            int req = sc.nextInt();\r\n            for(int j = size - 1; j &lt; req; j++){\r\n                if (blackBox.containsKey(nums[j])) {\r\n                    blackBox.put(nums[j], blackBox.get(nums[j]) + 1);\r\n                    if (curKey == nums[j]) {\r\n                        curValue++;\r\n                    }\r\n                }\r\n                else {\r\n                    blackBox.put(nums[j], 1);\r\n                }\r\n                if(nums[j] &lt; curKey) {\r\n                    if (curPosition == 0) {\r\n                        Map.Entry&lt;Integer, Integer&gt; curEnrty= blackBox.lowerEntry(curKey);\r\n                        curKey = curEnrty.getKey();\r\n                        curValue = curEnrty.getValue();\r\n                        curPosition = curValue - 1;\r\n                    }\r\n                    else {\r\n                        curPosition--;\r\n                    }\r\n                }\r\n            }\r\n            size = req + 1;\r\n            System.out.println(curKey);\r\n            if (curPosition == curValue - 1) {\r\n                Map.Entry&lt;Integer, Integer&gt; curEnrty = blackBox.higherEntry(curKey);\r\n                curKey = curEnrty.getKey();\r\n                curValue = curEnrty.getValue();\r\n                curPosition = 0;\r\n            }\r\n            else {\r\n                curPosition++;\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 JCF \u043d\u0435\u0442 \u043c\u0443\u043b\u044c\u0442\u0438\u0441\u0435\u0442\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u043d\u0430 \u0431\u0430\u0437\u0435 <code>TreeSet,<\/code> \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u0447\u0435\u0440\u043d\u043e\u043c \u044f\u0449\u0438\u043a\u0435, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0447\u0435\u0440\u043d\u043e\u043c \u044f\u0449\u0438\u043a\u0435. \u041f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0447\u0435\u0440\u043d\u044b\u0439 \u044f\u0449\u0438\u043a, \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u044f\u0441\u044c \u0432\u043d\u0438\u0437 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439, \u0438 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u0432\u0432\u0435\u0440\u0445 \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/1225\" target=\"_blank\" rel=\"noopener\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 e-olymp<\/a><br \/>\n<a href=\"https:\/\/www.e-olymp.com\/ru\/submissions\/4804623\" target=\"_blank\" rel=\"noopener\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 e-olymp<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/Jv9ZXM\" target=\"_blank\" rel=\"noopener\">\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 Ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u044b\u0445. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $i$. \u0412 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043f\u0443\u0441\u0442\u043e\u0439, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f $i$ \u0440\u0430\u0432\u043d\u0430 $0$. \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434 (\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439). \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439: ADD(x): \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 x \u0432 \u0427\u0435\u0440\u043d\u044b\u0439 \u042f\u0449\u0438\u043a; GET: \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c $i$ \u043d\u0430 $1$ \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 $i$-\u044b\u0439 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=3901\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":119,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[478,479,480],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3901"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3901"}],"version-history":[{"count":4,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3901\/revisions"}],"predecessor-version":[{"id":4236,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3901\/revisions\/4236"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}