https://wenku.baidu.com/view/bc213eff700abb68a982fb22.html?from=search
https://www.cnblogs.com/AWCXV/p/9486282.html
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct know :map<string,int>
{
int operator ()(const string &tmp)
{
if(!count(tmp))
{
insert(make_pair(tmp,size()));
}
return at(tmp);
}
}id;
struct node
{
node(int n):v(n){}
struct Vex
{
vector<int>a;
int s[2][521];
};
struct road
{
int from,to,op;
};
int fa;
vector<Vex>v;
vector<road>e;
void add(const road &st)
{
v[st.from].a.push_back((int)e.size());
//这里用到了类似前向星的东西
e.push_back(st);
}
void dfs(int u,int is)
{
v[fa].s[is][u] = 1;
int to ;
for(int y:v[u].a)
{
//
if(to = e[y].to ,is = is&&e[y].op,!v[fa].s[is][to])
{
dfs(to,is);
}
}
}
}exm(521);
int main()
{
int n,m;
cin>>n>>m;
string t1,t2,t3;
node::road tmp;
for(int i=1; i<=n; i++)
{
cin>>t1>>t2>>t3;
tmp.from = id(t1);
tmp.to =id(t3);
tmp.op = (t2=="is-a");
exm.add(tmp);
}
for(int i=0;i<(int )id.size();i++)
{
exm.fa =1;
exm.dfs(i,1);
}
for(int i=1; i<=m; i++)
{
cin>>t1>>t2>>t3;
int j = t3=="is-a"?1:0;
int n = exm.v[id(t1)].s[j][id(t3)];
if(!n)printf("Query %d: true\n",i);
else printf("Query %d: false\n",i);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1E5;
int n,m,a[N+10],_size[N+10];
int dl[N+10],h,t,step[N+10],dp[N+10][20];
int ma(int i,int j){
if (a[i]>=a[j]) return i;
return j;
}
int get_ma(int l,int r){
if (l>r) return 0;
int len = log2(r-l+1);
return ma(dp[l][len],dp[r-(1<<len)+1][len]);
}
int get_first_bigger(int q,int L){
int l = L,r = n,temp = -1;
while (l <= r){
int mid = (l+r)>>1;
if (a[get_ma(L,mid)]>q){
temp = mid;
r = mid-1;
}else l = mid + 1;
}
return temp;
}
void debug(int a[],int n)
{
cout<<"数组a为"<<endl;
int top = 1;
for(int i=0;i<=n;i++)
{
if(top)top =0;
else printf(" ");
printf("%d",a[i]);
}
printf("\n");
}
int main(){
//freopen("D:\\rush.txt","r",stdin);
//freopen("D:\\rush_out.txt","w",stdout);
int T;
scanf("%d",&T);
while (T--){
scanf("%d%d",&n,&m);
for (int i = 1;i <= n;i++) scanf("%d",&a[i]);
h = 1,t = 0;
for (int i = n;i >= 1;i--){
while (h<=t && a[i]>=a[dl[t]]) t--;
dl[++t] = i;
_size[i] = t-h+1;
}
step[1] = 1;
int cur = 1;
for (int i = 2;i <= n;i++)
if (a[i]>a[cur]){
step[i] = step[cur]+1;
cur = i;
}
for (int i = 0;i <= n;i++) dp[i][0] = i;
for (int l = 1;l <= 17;l++){
for (int i = 1;i <= n;i++){
if ((i+(1<<l)-1)>n) break;
dp[i][l] = ma(dp[i][l-1],dp[i+(1<<(l-1))][l-1]);
}
}
//注意这里讲的上升序列是指题目中讲的从左到右
//遇到一个比当前值大的就进行更新。
//step数组含义 是从1开始,到
//当前数为止上升序列的长度,注意
//如果step数组不为0,那么a[i]一定是确定好的上升序列中的一个
//例如 1 2 3 4 4即使是相等,a[5]也是0;
//_size数组含义是单调栈的大小,代表从当前标号到最后上升序列的长度
//dl数组含义 是单调栈内元素的位置标号
debug(step,n);
debug(_size,n);
debug(dl,n);
for (int i = 1;i <= m;i++){
int p,q;
scanf("%d%d",&p,&q);
int idx = get_ma(1,p-1);
int key = q,ans = 0;
cout<<idx<<" "<<a[idx]<<" idx"<<endl;
if (q<=a[idx]){
key = a[idx];
ans = -1;
}
int idx2 = get_first_bigger(key,p+1);
cout<<"idx= "<<idx<<" idx2= "<<idx2<<" "<<" ;"<<step[idx]<<" "<<endl;
if (idx2==-1){
ans += step[idx]+1;
}else{
ans += step[idx]+1+_size[idx2];
cout<<"_size[idx2]= "<<_size[idx2]<<endl;
}
printf("%d\n\n\n",ans);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
i
int a[maxn];
int get_ma(int )
{
}
int main()
{
return 0;
}
//5
//5 1
//1 5 2 4 3
//数组a为
//0 1 2 0 0 0
//数组a为
//0 2 1 2 1 1
//数组a为
//0 2 1 0 0 0
//3 4
//2 5 idx
//idx= 2 idx2= -1 ;2
//2
//
//
//5 1
//1 2 3 4 4
//数组a为
//0 1 2 3 4 0
//数组a为
//0 4 3 2 1 1
//数组a为
//0 4 3 2 1 0
//3 8
//2 2 idx
//idx= 2 idx2= -1 ;2
//3
//
//
//5 10
//1 2 3 4 4
//数组a为
//0 1 2 3 4 0
//数组a为
//0 4 3 2 1 1
//数组a为
//0 4 3 2 1 0
//3 2
//2 2 idx
//idx= 2 idx2= 4 ;2
//_size[idx2]= 1
//3
//