当前位置:网站首页>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面()
}
边栏推荐
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- [FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
- C form application of C (27)
- Solution of storage bar code management system in food industry
- [001] [stm32] how to download STM32 original factory data
- Cross domain and jsonp details
- Basic knowledge of binary tree, BFC, DFS
- QML和QWidget混合开发(初探)
- [tomato assistant installation]
猜你喜欢
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
Record the pit of NETCORE's memory surge
记一次excel XXE漏洞
Practical development of member management applet 06 introduction to life cycle function and user-defined method
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
1291_Xshell日志中增加时间戳的功能
Recommendation system (IX) PNN model (product based neural networks)
[FPGA tutorial case 11] design and implementation of divider based on vivado core
10個 Istio 流量管理 最常用的例子,你知道幾個?
Proof of Stirling formula
随机推荐
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
Interface idempotency
Hashcode and equals
C (thirty) C combobox listview TreeView
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
【按键消抖】基于FPGA的按键消抖模块开发
lora网关以太网传输
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
[tomato assistant installation]
C form application of C (27)
Python book learning notes - Chapter 09 section 01 create and use classes
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
HotSpot VM
51nod 1130 n factorial length V2 (Stirling approximation)
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Script lifecycle
[001] [stm32] how to download STM32 original factory data