当前位置:网站首页>P3500 [poi2010]tes intelligence test (two points & offline)
P3500 [poi2010]tes intelligence test (two points & offline)
2022-07-06 04:15:00 【Harris-H】
P3500 [POI2010]TES-Intelligence Test( Two points & offline )
Law 1
vector Save the corresponding position of each number .
Then for each position of each query string , Two points to find the minimum > l a s t last last Of . In fact, the essence of sequential automata is to find the next smallest position , It's just that sequential automata limits the size of the character set .
Time complexity : 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;
}
Law 2
You can do it offline , Consider building drawings , First connect the corresponding number with the first position of the query string .
Then traverse the position of the template string in order i i i , Edge the next position .
Pay attention to remove the front edge , direct h [ i ] = 0 h[i]=0 h[i]=0.
Time complexity : 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 Is the sequence to which it belongs 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;
}// Adjacency list ,bow[x] Representation number x Ask on
int a[N];
int k[N],*p[N];
int d[N*2],*last=d;// Pointer storage
int cur[N];// Ask the current position of the sequence
bool ok[N];// answer
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);// Add first item
}
rep(i,1,m){
int u= a[i];
int j= head[u];
head[u]= 0;// Clear adjacency table
for(;j;j=bow[j].nxt){
int t= bow[j].pos;
if( ++cur[t] == k[t] ) ok[t]= 1;// A successful match
else add(p[t][cur[t]+1],t);// Join next
}
}
rep(i,1,n) puts(ok[i]?"TAK":"NIE");
return 0;
//end Noodles ()
}
边栏推荐
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- 20、 EEPROM memory (AT24C02) (similar to AD)
- [FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
- Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
- P2102 地砖铺设(dfs&贪心)
- Use js to complete an LRU cache
- R note prophet
- Tips for using dm8huge table
- 《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
- DM8 backup set deletion
猜你喜欢
查询mysql数据库中各表记录数大小
Mlapi series - 04 - network variables and network serialization [network synchronization]
Path of class file generated by idea compiling JSP page
Security xxE vulnerability recurrence (XXe Lab)
SSTI template injection explanation and real problem practice
In depth MySQL transactions, stored procedures and triggers
[tomato assistant installation]
MySql數據庫root賬戶無法遠程登陸解决辦法
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
食品行业仓储条码管理系统解决方案
随机推荐
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
[Key shake elimination] development of key shake elimination module based on FPGA
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
深入浅出node模板解析错误escape is not a function
C. The Third Problem(找规律)
E. Best Pair
DM8 backup set deletion
电脑钉钉怎么调整声音
Unity中几个重要类
Ipv4中的A 、B、C类网络及子网掩码
Global and Chinese markets for endoscopic drying storage cabinets 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
IDEA编译JSP页面生成的class文件路径
Cross domain and jsonp details
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
pd. to_ numeric
颠覆你的认知?get和post请求的本质
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
MySql数据库root账户无法远程登陆解决办法