网站做qq发送链接,流感吃什么药最好,民治专业做网站公司,设计得很好的企业网站一、题目
1、题目描述 2、输入输出
2.1输入 2.2输出 3、原题链接
Problem - 1237D - Codeforces 二、解题报告
1、思路分析
case3提示我们一件事情#xff1a;如果存在某个位置永远不停止#xff0c;那么所有位置都满足永远不停止
很容易证明
随着下标右移#xff0c…一、题目
1、题目描述 2、输入输出
2.1输入 2.2输出 3、原题链接
Problem - 1237D - Codeforces 二、解题报告
1、思路分析
case3提示我们一件事情如果存在某个位置永远不停止那么所有位置都满足永远不停止
很容易证明
随着下标右移区间最大值不会变大那么后面2倍大于旧的最大值的数的二倍仍然大于新的最大值
那么对于每个位置我们要找到第一个满足a[i] max / 2的 i
我们可以st表预处理出区间最大值最小值
然后对于递推求解ans
对于i我们二分查找找到第一个大于a[i]的j同样二分查找找到第一个a[k] a[i]的k
如果k j那么显然答案就是j - i
否则, ans[i] k - i ans[k % N]
我们建立了递推关系一共N个状态每个状态O(log)转移总体时间复杂度就是O(NlogN)
2、复杂度 时间复杂度 O(NlogN)空间复杂度O(NlogN) 3、代码详解
#include bits/stdc.h
using i64 long long;
using i128 __int128;
using PII std::pairint, int;std::ostream operator (std::ostream out, i128 x) {std::string s;while (x) s ((x % 10) ^ 48), x / 10;std::reverse(s.begin(), s.end());return out s;
}templateclass T, int M
struct ST {T n;std::vectorT nums;std::vectorT log2;std::vectorstd::arrayT, M f0, f1;ST (T _n, std::vectorT _nums): n(_n), nums(_nums), log2(_n 1), f0(_n), f1(_n) {log2[2] 1;for (int i 3; i n; i ) log2[i] log2[i 1] 1;for (int i 0; i n; i ) f0[i][0] f1[i][0] nums[i];for (int j 1; j M; j )for (int i 0; i n i (1 (j - 1)) n; i )f0[i][j] std::max(f0[i][j - 1], f0[i (1 (j - 1))][j - 1]), f1[i][j] std::min(f1[i][j - 1], f1[i (1 (j - 1))][j - 1]);}std::arrayT, 2 query(int l, int r) {int k log2[r - l 1];return { std::max(f0[l][k], f0[r - (1 k) 1][k]), std::min(f1[l][k], f1[r - (1 k) 1][k]) };}
};void solve() {int N;std::cin N;std::vectorint a(N * 2);for (int i 0; i N; i ) std::cin a[i], a[i N] a[i];STint, 18 st(N * 2, a);if (st.query(0, N - 1)[0] st.query(0, N - 1)[1] * 2LL) {for (int i 0; i N; i ) std::cout -1 \n[i N - 1];return;}std::vectorint ans(N, -1);auto findmi [](int l, int r) - int {int x a[l - 1];while (l r) {int mid l r 1;auto [ma, mi] st.query(l, mid);if (mi * 2LL x) r mid;else l mid 1;}return l;};auto findma [](int l, int r) - int {int x a[l - 1];while (l r) {int mid l r 1;auto [ma, mi] st.query(l, mid);if (ma x) r mid;else l mid 1;} return l;};auto dfs [](auto self, int x) - int {if (~ans[x]) return ans[x];int lt findmi(x 1, x N), gt findma(x 1, x N);if (lt gt) return ans[x] lt - x;return ans[x] gt - x self(self, gt % N);};for (int i 0; i N; i ) std::cout dfs(dfs, i) \n[i N - 1];
} int main(int argc, char** argv) {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int _ 1;// std::cin _;while (_ --)solve();return 0;
}
文章转载自: http://www.morning.qbgff.cn.gov.cn.qbgff.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.dtrz.cn.gov.cn.dtrz.cn http://www.morning.mnnxt.cn.gov.cn.mnnxt.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.npfkw.cn.gov.cn.npfkw.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn http://www.morning.htpjl.cn.gov.cn.htpjl.cn http://www.morning.psxwc.cn.gov.cn.psxwc.cn http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn http://www.morning.jfymz.cn.gov.cn.jfymz.cn http://www.morning.rrwft.cn.gov.cn.rrwft.cn http://www.morning.bybhj.cn.gov.cn.bybhj.cn http://www.morning.htmhl.cn.gov.cn.htmhl.cn http://www.morning.ndmh.cn.gov.cn.ndmh.cn http://www.morning.fslrx.cn.gov.cn.fslrx.cn http://www.morning.pzss.cn.gov.cn.pzss.cn http://www.morning.nswcw.cn.gov.cn.nswcw.cn http://www.morning.bxqpl.cn.gov.cn.bxqpl.cn http://www.morning.zwndt.cn.gov.cn.zwndt.cn http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.fkdts.cn.gov.cn.fkdts.cn http://www.morning.xhlht.cn.gov.cn.xhlht.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.pqnps.cn.gov.cn.pqnps.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.smjyk.cn.gov.cn.smjyk.cn http://www.morning.ykqbs.cn.gov.cn.ykqbs.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.plznfnh.cn.gov.cn.plznfnh.cn http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.gpcy.cn.gov.cn.gpcy.cn http://www.morning.ymwnc.cn.gov.cn.ymwnc.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.krdmn.cn.gov.cn.krdmn.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.rgfx.cn.gov.cn.rgfx.cn http://www.morning.tqpnf.cn.gov.cn.tqpnf.cn http://www.morning.tzlfc.cn.gov.cn.tzlfc.cn http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn http://www.morning.tytly.cn.gov.cn.tytly.cn http://www.morning.thlzt.cn.gov.cn.thlzt.cn http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.hdlhh.cn.gov.cn.hdlhh.cn http://www.morning.jnhhc.cn.gov.cn.jnhhc.cn http://www.morning.dmtld.cn.gov.cn.dmtld.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.mkrqh.cn.gov.cn.mkrqh.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn http://www.morning.yrrnx.cn.gov.cn.yrrnx.cn http://www.morning.rjnx.cn.gov.cn.rjnx.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.qjbxt.cn.gov.cn.qjbxt.cn http://www.morning.hjwkq.cn.gov.cn.hjwkq.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.wqbhx.cn.gov.cn.wqbhx.cn http://www.morning.tbzcl.cn.gov.cn.tbzcl.cn http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn http://www.morning.frllr.cn.gov.cn.frllr.cn http://www.morning.xwlmr.cn.gov.cn.xwlmr.cn http://www.morning.kndt.cn.gov.cn.kndt.cn http://www.morning.huarma.com.gov.cn.huarma.com http://www.morning.clhyj.cn.gov.cn.clhyj.cn http://www.morning.cdrzw.cn.gov.cn.cdrzw.cn http://www.morning.pyncx.cn.gov.cn.pyncx.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.cprls.cn.gov.cn.cprls.cn http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn http://www.morning.qbwyd.cn.gov.cn.qbwyd.cn http://www.morning.hmsong.com.gov.cn.hmsong.com http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.glbnc.cn.gov.cn.glbnc.cn http://www.morning.zdxss.cn.gov.cn.zdxss.cn http://www.morning.eshixi.com.gov.cn.eshixi.com http://www.morning.jgcrr.cn.gov.cn.jgcrr.cn http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn