当前位置:网站首页>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开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Explain in simple terms node template parsing error escape is not a function
- Mixed development of QML and QWidget (preliminary exploration)
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- 2328. 网格图中递增路径的数目(记忆化搜索)
- Lombok principle and the pit of ⽤ @data and @builder at the same time
- 深入浅出node模板解析错误escape is not a function
- About some basic DP -- those things about coins (the basic introduction of DP)
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- 【leetcode】22. bracket-generating
猜你喜欢
Practical development of member management applet 06 introduction to life cycle function and user-defined method
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
Overturn your cognition? The nature of get and post requests
Record an excel xxE vulnerability
User datagram protocol UDP
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Figure application details
Thread sleep, thread sleep application scenarios
绑定在游戏对象上的脚本的执行顺序
Fundamentals of SQL database operation
随机推荐
【FPGA教程案例11】基于vivado核的除法器设计与实现
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
DM8 archive log file manual switching
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
2328. 网格图中递增路径的数目(记忆化搜索)
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
51nod 1130 n factorial length V2 (Stirling approximation)
电脑钉钉怎么调整声音
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
查询mysql数据库中各表记录数大小
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
User datagram protocol UDP
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
[FPGA tutorial case 11] design and implementation of divider based on vivado core
Comprehensive ability evaluation system
Data processing methods - smote series and adasyn
Chinese brand hybrid technology: there is no best technical route, only better products
About some basic DP -- those things about coins (the basic introduction of DP)