当前位置:网站首页>P3500 [POI2010]TES-Intelligence Test(二分&离线)
P3500 [POI2010]TES-Intelligence Test(二分&离线)
2022-07-06 04:11:00 【Harris-H】
P3500 [POI2010]TES-Intelligence Test(二分&离线)
法1
vector 存每个数对应的位置。
然后对于每个查询串的每个位置,二分找到最小> l a s t last last 的。其实序列自动机的本质就是寻找下一个最小的位置,只不过序列自动机限制了字符集大小。
时间复杂度: O ( T m l o g m ) O(Tmlogm) O(Tmlogm)
#include <cstdio>
#include <vector>
using namespace std;
int poi;
bool yes;
vector <int> a[1000010];
int b[1000010];
int dd(int now,int l,int r)
{
int ans=-1;
while (l<=r)
{
int m=(l+r)/2;
if (a[now][m]>poi)
{
ans=a[now][m];
yes=true;
r=m-1;
}
else
l=m+1;
}
return ans;
}
int main()
{
int m;
scanf("%d",&m);
for (int i=1;i<=m;i++)
{
int t;
scanf("%d",&t);
a[t].push_back(i);
}
int T;
scanf("%d",&T);
while (T--)
{
bool flag=true;
int n;
poi=0;
scanf("%d",&n);
for (int j=1;j<=n;j++)
scanf("%d",&b[j]);
for (int j=1;j<=n;j++)
{
int now=b[j];
int l=0,r=a[now].size();
if (r==0)
{
flag=false;
break;
}
r--;
yes=false;
int ttt=dd(now,l,r);
if (yes)
poi=ttt;
else
{
flag=false;
break;
}
}
if (flag)
printf("TAK\n");
else
printf("NIE\n");
}
return 0;
}
法2
可以离线做,考虑建图做,先将对应数与查询串的第一个位置连边。
然后按顺序遍历模板串的位置 i i i ,对其下一个位置进行建边。
注意要去掉前面的连边,直接 h [ i ] = 0 h[i]=0 h[i]=0。
时间复杂度: O ( n + ∑ m ) O(n+\sum m) O(n+∑m)
// SeptEtavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#define re register
#define ll long long
#define il inline
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define pt(ch) putchar(ch)
#define pti(x) printf("%d",x)
using namespace std;
// c_ints
il int ci(){
re char ch;
while(!isdigit(ch=getchar()));
re int x= ch^'0';
while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
return x;
}
enum{
N=1000024};
class node{
public:
int nxt,pos;//pos是所属的序列id
}bow[N];
int tot;
int head[N];
il void add(int x,int y){
bow[++tot].nxt= head[x];
bow[tot].pos= y;
head[x]= tot;
}//邻接表,bow[x]表示数字x上的询问
int a[N];
int k[N],*p[N];
int d[N*2],*last=d;//指针存储
int cur[N];//询问序列当前位置
bool ok[N];//答案
int main(){
int m= ci();
rep(i,1,m) a[i]= ci();
int n= ci();
rep(i,1,n){
k[i]= ci();
//p[i]= last;
p[i] = new int[k[i]+1];
rep(j,1,k[i]) p[i][j]= ci();
//last+= k[i]+1;
add(p[i][1],i);//加入首项
}
rep(i,1,m){
int u= a[i];
int j= head[u];
head[u]= 0;//清除邻接表
for(;j;j=bow[j].nxt){
int t= bow[j].pos;
if( ++cur[t] == k[t] ) ok[t]= 1;//成功匹配
else add(p[t][cur[t]+1],t);//加入下一位
}
}
rep(i,1,n) puts(ok[i]?"TAK":"NIE");
return 0;
//end面()
}
边栏推荐
- Tips for using dm8huge table
- TCP/IP协议里面的网关地址和ip地址有什么区别?
- Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
- MySQL master-slave replication
- DM8 archive log file manual switching
- E. Best Pair
- Python book learning notes - Chapter 09 section 01 create and use classes
- Viewing and verifying backup sets using dmrman
- Ks008 SSM based press release system
- 绑定在游戏对象上的脚本的执行顺序
猜你喜欢
WPF effect Article 191 box selection listbox
综合能力测评系统
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
About some basic DP -- those things about coins (the basic introduction of DP)
Record an excel xxE vulnerability
Cross domain and jsonp details
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
Execution order of scripts bound to game objects
Mlapi series - 04 - network variables and network serialization [network synchronization]
MySQL master-slave replication
随机推荐
脚本生命周期
In depth MySQL transactions, stored procedures and triggers
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Web components series (VII) -- life cycle of custom components
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
【按键消抖】基于FPGA的按键消抖模块开发
10个 Istio 流量管理 最常用的例子,你知道几个?
User datagram protocol UDP
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Fundamentals of SQL database operation
WPF effect Article 191 box selection listbox
E. Best Pair
MySql数据库root账户无法远程登陆解决办法
MySQL master-slave replication
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Database, relational database and NoSQL non relational database
MySQL transaction isolation level
Unity中几个重要类