CF1168C And Reachability
CF1168C And Reachability
And Reachability - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目大意
给定一个长度为
你可以选择一个长度为
当
现在给你
思路
设
设
那么
设
-
需要中转站
-
不需要中转站
code
#include <bits/stdc++.h>
#define fu(x , y , z) for(int x = y ; x <= z ; x ++)
#define fd(x , y , z) for(int x = y ; x >= z ; x --)
using namespace std;
const int N = 3e5 + 5;
int n , q;
int a[N] , f[N][25] , g[N][25] , c[N][25];
int read () {
int val = 0;
char ch = getchar ();
while (ch > '9' || ch < '0') ch = getchar ();
while (ch >= '0' && ch <= '9') {
val = val * 10 + (ch - '0');
ch = getchar();
}
return val;
}
void pre (int i , int x) {
fu (j , 1 , 20) {
if (x & 1) c[i][j] = 1;
x >>= 1;
}
}
int main () {
freopen ("and.in" , "r" , stdin);
freopen ("and.out" , "w" , stdout);
n = read () , q = read ();
fu (i , 1 , n) {
a[i] = read ();
pre (i , a[i]);
}
fu (i , 1 , n) {
fu (j , 1 , 20) {
if (c[i - 1][j]) g[i][j] = i - 1;
else g[i][j] = g[i - 1][j];
}
}
fu (i , 1 , n) {
fu (j , 1 , 20) {
fu (k , 1 , 20) {
if (!c[i][k]) continue;
int x = g[i][k];
if (c[x][j]) f[i][j] = max (f[i][j] , x);
else f[i][j] = max (f[i][j] , f[x][j]);
}
}
}
int l , r , flg = 0;
while (q --) {
flg = 0;
scanf ("%d%d" , &l , &r);
fu (i , 1 , 20) {
if (c[l][i] && f[r][i] >= l) {
puts ("Shi");
flg = 1;
break;
}
}
if (flg) continue;
puts ("Fou");
}
return 0;
}
如果人生会有很长,愿有你的荣耀永不散场
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端