当前位置:网站首页>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 ()
}
边栏推荐
- Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
- Mlapi series - 04 - network variables and network serialization [network synchronization]
- Web components series (VII) -- life cycle of custom components
- Maxay paper latex template description
- Custom event of C (31)
- 食品行业仓储条码管理系统解决方案
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- 2/12 didn't learn anything
- Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
- 【leetcode】22. bracket-generating
猜你喜欢
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/45/6777fa919386e526dbb0d2c808a7f2.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package

Overturn your cognition? The nature of get and post requests

SSTI template injection explanation and real problem practice

Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control

Data processing methods - smote series and adasyn
![[Key shake elimination] development of key shake elimination module based on FPGA](/img/47/c3833c077ad89d4906e425ced945bb.png)
[Key shake elimination] development of key shake elimination module based on FPGA

Security xxE vulnerability recurrence (XXe Lab)

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

Practical development of member management applet 06 introduction to life cycle function and user-defined method

When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
随机推荐
Viewing and verifying backup sets using dmrman
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
CertBot 更新证书失败解决
Leetcode32 longest valid bracket (dynamic programming difficult problem)
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
. Net interprocess communication
51nod 1130 n factorial length V2 (Stirling approximation)
pd. to_ numeric
[Key shake elimination] development of key shake elimination module based on FPGA
[disassembly] a visual air fryer. By the way, analyze the internal circuit
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
HotSpot VM
IDEA编译JSP页面生成的class文件路径
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Several important classes in unity
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Data processing methods - smote series and adasyn
Script lifecycle