当前位置:网站首页>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 ()
}
边栏推荐
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- TCP/IP协议里面的网关地址和ip地址有什么区别?
- How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
- lora网关以太网传输
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- Use js to complete an LRU cache
- Python book learning notes - Chapter 09 section 01 create and use classes
- 【可调延时网络】基于FPGA的可调延时网络系统verilog开发
- User datagram protocol UDP
猜你喜欢
颠覆你的认知?get和post请求的本质
Solution to the problem that the root account of MySQL database cannot be logged in remotely
TCP/IP协议里面的网关地址和ip地址有什么区别?
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
[disassembly] a visual air fryer. By the way, analyze the internal circuit
Slow SQL fetching and analysis of MySQL database
How does technology have the ability to solve problems perfectly
[tomato assistant installation]
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
随机推荐
图应用详解
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
Python book learning notes - Chapter 09 section 01 create and use classes
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
10个 Istio 流量管理 最常用的例子,你知道几个?
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
Basic knowledge of binary tree, BFC, DFS
Figure application details
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
In depth MySQL transactions, stored procedures and triggers
查询mysql数据库中各表记录数大小
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
MySQL master-slave replication
2327. 知道秘密的人数(递推)
asp. Core is compatible with both JWT authentication and cookies authentication
自动化测试的好处
Brief tutorial for soft exam system architecture designer | general catalog