#include <bits/stdc++.h>
#include <termio.h>
#include <unistd.h>
typedef long long ll;typedef unsigned long long ull; typedef double db;typedef long double ldb;
#define fre(x) freopen(#x ".in","r",stdin),freopen(#x ".out","w",stdout)
#define Rep(i,a,b) for(int i=a;i<=b;++i)
#define Dwn(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define mair make_pair
#define fir first
#define sec second
using namespace std; const int maxn=1e5+10; int n,m;
int S[20][20],D[20][20];
int h[5],l[5],a[5],K,G;
int V[maxn];
int num[5]; void Flush(){ cout<<"\033c";cout<<"\n\n\n\n\n\n\n\n\n\n\n\n"; } void Point(int x){ if(!x)cout<<"* "; if(x==1)cout<<"\033[31mH"<<"\033[0m"<<" "; if(x==2)cout<<"C "; }
void EdgeRow(int x){ if(x)cout<<"\033[32m"<<"R "<<"\033[0m";else cout<<"- "; }
void EdgeCol(int x){ if(x)cout<<"\033[32m"<<"R "<<"\033[0m";else cout<<"| "; } int building[20][20];
int pathrow[20][20],pathcol[20][20]; void Print(int Tim){
Flush();
cout<<"DAYS "<<" :: "<<Tim<<"\n";
Rep(i,Tim+1,52)cout<<V[i];
cout<<"\n\n\n\n"; cout<<" ";
Rep(i,0,m)cout<<i<<" ",(i && (cout<<i<<" ",1));
cout<<endl;
cout<<0<<" ";
Rep(i,0,m){ Point(building[0][i]);if(i<m)EdgeRow(pathrow[0][i]); }
cout<<endl<<endl;
Rep(i,1,n){
cout<<i<<" ";EdgeCol(pathcol[i][0]);
Rep(j,1,m){
cout<<"["<<S[i][j]<<","<<D[i][j]<<"] ";
EdgeCol(pathcol[i][j]);
}
cout<<endl<<endl;
cout<<i<<" ";Rep(j,0,m){ Point(building[i][j]);if(j<m)EdgeRow(pathrow[i][j]); }
cout<<endl<<endl;
}
cout<<"you have "<<" :: ";
Rep(i,1,4)cout<<" "<<num[i]<<" ";
cout<<endl<<endl;bool ok=0;
cout<<"build a house "<<" :: ";Rep(i,1,4)cout<<" "<<h[i]<<" ";
ok=1;Rep(i,1,4)ok&=(num[i]>=h[i]);if(ok)cout<<" [OK] "<<"[B]";
cout<<endl;
cout<<"build a castle "<<" :: ";Rep(i,1,4)cout<<" "<<h[i]+l[i]<<" ";
ok=1;Rep(i,1,4)ok&=(num[i]>=h[i]+l[i]);if(ok)cout<<" [OK] "<<"[C]";
cout<<endl;
cout<<"Upgrate a house"<<" :: ";Rep(i,1,4)cout<<" "<<l[i]<<" ";
ok=1;Rep(i,1,4)ok&=(num[i]>=l[i]);if(ok)cout<<" [OK] "<<"[U]";
cout<<endl;
cout<<"build a path "<<" :: ";Rep(i,1,4)cout<<" "<<a[i]<<" ";
ok=1;Rep(i,1,4)ok&=(num[i]>=a[i]);if(ok)cout<<" [OK] "<<"[R]";
cout<<endl;
cout<<"Exchange Cost "<<" :: "<<" "<<K;
cout<<endl;
} vector<string>Tool;
int Anssum=0;
string Tos(int x){ stringstream Id;Id<<x;string res;Id>>res;return res; } void Assert(int tag){ if(!tag){ cout<<"Warning: Illegal Option\n"; } }
bool Ill(){ cout<<"\033[31mWarning: Illegal Operation"<<"\033[0m"<<endl;usleep(500000);return true; } bool Option(int Tim){
string s;int x,y,xa,ya,xb,yb; cin>>s; if(s=="E")return Tool.emplace_back(s),false;
if(s=="B"){
cin>>x>>y;
if(building[x][y])return Ill();
if(Tim)Rep(i,1,4)if(num[i]<h[i])return Ill();
if(Tim)Rep(i,1,4)num[i]-=h[i];
building[x][y]=1;Anssum+=1;
s+=" "+Tos(x)+" "+Tos(y);
}
if(s=="C"){
cin>>x>>y;
if(building[x][y])return Ill();
Rep(i,1,4)if(num[i]<h[i]+l[i])return Ill();
Rep(i,1,4)num[i]-=h[i]+l[i];
building[x][y]=2;Anssum+=2;
s+=" "+Tos(x)+" "+Tos(y);
}
if(s=="U"){
cin>>x>>y;
if(building[x][y]!=1)return Ill();
Rep(i,1,4)if(num[i]<l[i])return Ill();
Rep(i,1,4)num[i]-=l[i];
building[x][y]=2;Anssum+=1;
s+=" "+Tos(x)+" "+Tos(y);
}
if(s=="R"){
cin>>xa>>ya>>xb>>yb;if(!((abs(xa-xb)==1 && ya==yb) || (abs(ya-yb)==1 && xa==xb)))return Ill();
Rep(i,1,4)if(num[i]<a[i])return Ill();
Rep(i,1,4)num[i]-=a[i];
if(xa==xb)pathrow[xa][min(ya,yb)]=1;
else pathcol[max(xa,xb)][ya]=1;
s+=" "+Tos(xa)+" "+Tos(ya)+" "+Tos(xb)+" "+Tos(yb);
}
if(s=="X"){
cin>>x>>y;if(num[x]<K)return Ill();
num[x]-=K,++num[y];
s+=" "+Tos(x)+" "+Tos(y);
}
Tool.emplace_back(s);
return true;
} void Get(int x){
Rep(i,1,n)Rep(j,1,m)if(D[i][j]==x){
num[S[i][j]]+=(building[i-1][j-1]+building[i-1][j]+building[i][j-1]+building[i][j]);
}
} void Check(int Tim){
if(Anssum>=10){
cout<<"\033c";
cout<<"\n\033[32mYou Win\n\n"<<"\033[0m";
cout<<Tim<<"\n";
for(auto it : Tool)cout<<it<<"\n";
exit(0);
}
} void solve(){
cin>>n>>m;Rep(i,1,n)Rep(j,1,m)cin>>S[i][j];Rep(i,1,n)Rep(j,1,m)cin>>D[i][j];
Rep(i,1,4)cin>>h[i]; Rep(i,1,4)cin>>l[i]; Rep(i,1,4)cin>>a[i];
cin>>K>>G;Rep(i,1,G)cin>>V[i]; Print(0);
while(Option(0))Print(0);
Rep(i,1,G){ Get(V[i]);Print(i);while(Option(i))Print(i);Check(i); } cout<<Tool.size()<<"\n";
for(auto it : Tool)cout<<it<<"\n";
} int main (){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);return solve(),0; }

ETT2:

51
B 0 2
E
E
E
R 0 2 0 3
E
X 3 1
E
E
E
E
E
E
E
E
R 0 3 1 3
E
E
E
E
B 1 3
E
R 0 1 0 2
E
E
E
R 0 1 1 1
E
E
E
E
E
U 0 2
E
E
E
E
E
B 1 1
E
R 0 0 0 1
R 0 3 0 4
E
E
E
E
X 2 1
U 1 3
E
E
E
X 2 1
B 0 0
X 2 1
B 0 4
E
E
E
E
E
E
E
E
E
U 1 1
E
E
E
E
X 1 3
X 1 3
X 1 3
X 1 3
X 2 3
X 2 3
U 0 0
U 0 4
E
#include <bits/stdc++.h>
#include <termio.h>
#include <unistd.h>
using namespace std ;
#define clear() cout << "\033c"
const int N = 20 ;
const int M = 1e4 + 100 ; int n , m ; int h[4] , l[4] , a[4] , K , G ; int V[M] ;
int S[N][N] , D[N][N] ; // cout << "\033[31mWarning\033[0m" ; 32 Green int Point[N][N] ; bool Road[N][N][N][N] ; int times ; int up ; struct OPER {
int opt ;
int a , b , c , d ;
} b[N] ; int now[4] ; void Print(int x , int y) {
switch (Point[x][y]) {
case 0 :
cout << '*' ;
break ;
case 1 :
cout << "\033[31mH\033[0m" ;
break ;
case 2 :
cout << "C" ;
break ;
}
} void Print_Road(int a , int b , int c , int d) {
if (Road[a][b][c][d] || Road[c][d][a][b]) cout << "\033[32mR\033[0m" ;
else cout << '-' ;
} void Print_Block(int x) {
cout << '\n' << '\n' ;
cout << " " ; for (int i = 1 ; i <= m ; ++ i) {
if (Road[x][i - 1][x - 1][i - 1] || Road[x - 1][i - 1][x][i - 1]) cout << "\033[32mR\033[0m" ;
else cout << '|' ; cout << " " << '[' << S[x][i] << ',' << D[x][i] << ']' << " " ;
} if (Road[x][m][x - 1][m] || Road[x - 1][m][x][m]) cout << "\033[32mR\033[0m" ;
else cout << '|' ; cout << '\n' << '\n' << '\n' ;
} void Rebuild() { } void Error() {
cout << "\033[31m操作非法,失效!!!\033[0m" ; usleep(500000) ;
clear() ;
} bool OKey(int *f , int *s) {
for (int i = 0 ; i < 4 ; ++ i) if (f[i] < s[i]) return false ; return true ;
} void Operate(int &t) {
clear() ;
cout << "第" << t << "天" << '\n' ; for (int i = t + 1 ; i <= 51 ; ++ i) {
if ((i - t) % 30 == 0) cout << '\n' ; cout << V[i] << ' ' ;
} cout << '\n' ; cout << " " ; for (int i = 0 ; i <= m ; ++ i) cout << i << " " ; cout << '\n' ; cout << "0 " ;
for (int i = 0 ; i < m ; ++ i) {
Print(0 , i) ; cout << " " ;
Print_Road(0 , i , 0 , i + 1) ;
cout << " " ;
}
Print(0 , m) ; cout << '\n' ; for (int i = 1 ; i <= n ; ++ i) {
Print_Block(i) ; cout << i << " " ;
for (int j = 0 ; j < m ; ++ j) {
Print(i , j) ; cout << " " ;
Print_Road(i , j , i , j + 1) ;
cout << " " ;
}
Print(i , m) ; cout << '\n' ;
} cout << "我的拥有 : " << now[0] << ' ' << now[1] << ' ' << now[2] << ' ' << now[3] ; cout << '\n' ;
cout << "建房子的花费: " << h[0] << ' ' << h[1] << ' ' << h[2] << ' ' << h[3] ;
if (OKey(now , h)) cout << "[OK] -> H" << '\n' ;
else cout << '\n' ;
cout << "建城堡的花费: " << h[0] + l[0] << ' ' << h[1] + l[1] << ' ' << h[2] + l[2] << ' ' << h[3] + l[3] ;
int p[4] ; for (int i = 0 ; i < 4 ; ++ i) p[i] = h[i] + l[i] ;
if (OKey(now , p)) cout << "[OK] -> C" << '\n' ;
else cout << '\n' ;
cout << "升级的花费 : " << l[0] << ' ' << l[1] << ' ' << l[2] << ' ' << l[3] ;
if (OKey(now , l)) cout << "[OK] -> U" << '\n' ;
else cout << '\n' ;
cout << "建路的话费 : " << a[0] << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] ;
if (OKey(now , a)) cout << "[OK] -> R" << '\n' ;
else cout << '\n' ; char c ; cin >> c ; switch (c) {
case 'H' :
int x , y ;
cin >> x >> y ; if (x < 0 || y < 0 || x > n || y > m) Error() ;
else if (Point[x][y]) Error() ;
else if (!(Road[x][y][x][y - 1] || Road[x][y][x][y + 1] || Road[x][y][x - 1][y] || Road[x][y][x + 1][y])) Error() ;
else if (Point[x][y - 1] || Point[x][y + 1] || Point[x + 1][y] || Point[x - 1][y]) Error() ;
else Point[x][y] = 1 , ++ t , b[t] = {1 , x , y} ; break ;
case 'C' :
int x , y ; cin >> x >> y ; if (x < 0 || y < 0 || x > n || y > m) Error() ;
else if (Point[x][y]) Error() ;
else if (!(Road[x][y][x][y - 1] || Road[x][y][x][y + 1] || Road[x][y][x - 1][y] || Road[x][y][x + 1][y])) Error() ;
else if (Point[x][y - 1] || Point[x][y + 1] || Point[x + 1][y] || Point[x - 1][y]) Error() ;
else Point[x][y] = 2 , ++ t , b[t] = {2 , x , y} ;
break ;
case 'U' :
int x , y ; cin >> x >> y ; if (x < 0 || y < 0 || x > n || y > m) Error() ;
else if (Point[x][y] != 1) Error() ;
else if (!(Road[x][y][x][y - 1] || Road[x][y][x][y + 1] || Road[x][y][x - 1][y] || Road[x][y][x + 1][y])) Error() ;
else if (Point[x][y - 1] || Point[x][y + 1] || Point[x + 1][y] || Point[x - 1][y]) Error() ;
else Point[x][y] = 2 , ++ t , b[t] = {3 , x , y} ;
break ;
case 'R' : break ;
case 'S' :
cout << "真的选择复原吗? y/s" ;
char f ; cin >> f ; if (f == 'y') Rebuild() ;
break ;
}
} bool check() { } void solve() {
cin >> n >> m ; for (int i = 1 ; i <= n ; ++ i) {
for (int j = 1 ; j <= m ; ++ j) {
cin >> S[i][j] ;
}
} for (int i = 1 ; i <= n ; ++ i) {
for (int j = 1 ; j <= m ; ++ j) {
cin >> D[i][j] ;
}
} cin >> h[0] >> h[1] >> h[2] >> h[3] ;
cin >> l[0] >> l[1] >> l[2] >> l[3] ;
cin >> a[0] >> a[1] >> a[2] >> a[3] ;
cin >> K >> G ; for (int i = 1 ; i <= G ; ++ i) cin >> V[i] ; Operate(times) ; while (check()) {
Operate(times) ;
}
} signed main() {
ios :: sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
solve() ;
}
#include <bits/stdc++.h>
#include <bits/extc++.h>
#ifdef linux
#define getchar getchar_unlocked
#endif
using namespace std ;
using namespace __gnu_pbds ;
using namespace __gnu_cxx ;
typedef long long ll ;
const int N = 1e5 + 100 ;
inline int read() {
int x = 0 , f = 1 ;
char c = getchar() ; while (c < '0' || c > '9') {
if (c == '-') f = -f ; c = getchar() ;
} while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
} return x * f ;
} int n ; int a[N] ; int Ans[N] ; struct Binary_Index_Array_Max {
#define lowbit(x) (x & (- x))
int t[N] ; void clear() {
memset(t , 0 , sizeof(t)) ;
} void add(int pos , int val) {
while (pos <= n) {
t[pos] = max(t[pos] , val) ;
pos += lowbit(pos) ;
}
} int Query(int pos) {
int ans = 0 ; while (pos > 0) {
ans = max(t[pos] , ans) ;
pos -= lowbit(pos) ;
} return ans ;
}
} t1 , t2 ; int front1[N] , front2[N] ;
vector <int> v1[N] , v2[N] ;
__gnu_pbds :: priority_queue <int , less<int> > q ; int pos[N] ; signed main() {
#ifdef LOCAL
auto Cymhiptjzzl = freopen("1.in" , "r" , stdin) ;
Cymhiptjzzl = freopen("1.out" , "w" , stdout) ;
#endif
n = read() ;
for (int i = 1 ; i <= n ; ++ i) a[i] = read() , pos[a[i]] = i ;
for (int i = 1 ; i <= n ; ++ i) {
front1[i] = t1.Query(n - a[i] + 1) ; v1[front1[i]].push_back(i) ;
front2[i] = t2.Query(a[i]) ; v2[front2[i]].push_back(i) ;
t1.add(n - a[i] + 1 , i) ; t2.add(a[i] , i) ;
} t1.clear() ; for (int i = 1 ; i <= n ; ++ i) {
cout << i << ':' << '\n' ;
for (auto j : v1[i]) {
cout << j << ' ' ;
} cout << '\n' ;
} // for (int i = 1 ; i <= n ; ++ i) {
// for (auto j : v1[i]) {
// Ans[j] = t1.Query(a[j] - 1) ;
// } // while (!q.empty()) {
// int x = q.top() ;
// if (x <= a[i]) break ;
// t1.add(x , pos[x]) ;
// } q.push(a[i]) ;
// } t1.clear() ; // q.clear() ; // for (int i = 1 ; i <= n ; ++ i) {
// for (auto j : v2[i]) {
// Ans[j] = max(Ans[j] , t1.Query(n - (a[j] + 1) + 1)) ;
// } // while (!q.empty()) {
// int x = q.top() ;
// if (x >= a[i]) break ;
// t1.add(n - x + 1 , pos[x]) ;
// } q.push(a[i]) ;
// }
}
#include <bits/stdc++.h>
using namespace std ;
const int mod1 = 39989 ;
const int mod2 = 1e9 ;
const int N = 4e4 + 100 ; int n ;
struct Segment {
double k ; int d ;
} b[N] ; int cnt ; int ans ; inline void add(int w , int x , int y , int z) {
cnt ++ ; if (w == y) return b[cnt].d = max(x , z) , void() ;
else return b[cnt].k = (z - x) * 1.0 / (y - w) , b[cnt].d = x - b[cnt].k * w , void() ;
} double Y(int pos , int x) {
return b[x].d + pos * b[x].k ;
} double eps = 1e-15 ; int Compare(double x , double y) {
if (x - y > eps) return 1 ;
else if (y - x > eps) return -1 ; return 0 ;
} #ifndef Lee_Chao
#define lson (id << 1)
#define rson (id << 1 | 1)
#define mid ((l + r) >> 1) int t[N << 2] ; void updata(int id , int l , int r , int u) {
int &v = t[id] ; int Direct = Compare(Y(mid , u) , Y(mid , v)) ;
if (Direct == 1 || (!Direct && u < v)) swap(u , v) ;
if (l == r) return ; int Direc1 = Compare(Y(l , u) , Y(l , v)) , Direc2 = Compare(Y(r , u) , Y(r , v)) ;
if (Direc1 == 1 || (!Direc1 && u < v)) updata(lson , l , mid , u) ;
if (Direc2 == 1 || (!Direc2 && u < v)) updata(rson , mid + 1 , r , u) ;
} void Interval(int id , int l , int r , int x , int y , int c) {
if (x <= l && r <= y) {
return updata(id , l , r , c) , void() ;
} if (x <= mid) Interval(lson , l , mid , x , y , c) ;
if (y > mid) Interval(rson , mid + 1 , r , x , y , c) ;
} void Query(int id , int l , int r , int x , int &ret) {
int Direct = Compare(Y(mid , t[id]) , Y(mid , ret)) ;
if (Direct == 1 || (!Direct && t[id] < ret)) ret = t[id] ; if (l == r) {
return ;
} if (x <= mid) Query(lson , l , mid , x , ret) ;
else Query(rson , mid + 1 , r , x , ret) ;
} #undef mid
#endif signed main() {
#ifdef LOCAL
auto Scape = freopen("1.in" , "r" , stdin) ;
Scape = freopen("1.out" , "w" , stdout) ;
#endif
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
cin >> n ; int opt , w , x , y , z ; while (n --) {
cin >> opt ; if (opt == 1) {
cin >> w >> x >> y >> z ;
w = (w + ans - 1) % mod1 + 1 ; x = (x + ans - 1) % mod2 + 1 ;
y = (y + ans - 1) % mod1 + 1 ; z = (z + ans - 1) % mod2 + 1 ; if (w > y) swap(w , y) , swap(x , z) ; add(w , x , y , z) ;
Interval(1 , 1 , 10 , w , y , cnt) ;
} else {
cin >> w ;
w = (w + ans - 1) % mod1 + 1 ; ans = 0 ;
Query(1 , 1 , mod1 , w , ans) ; cout << ans << '\n' ;
// cerr << '\n' ;
}
}
}
#include <bits/stdc++.h>
typedef long long ll ;
using namespace std ;
const int N = 2e5 + 100 ;
inline ll read() {
ll x = 0 , f = 1 ;
char c = getchar() ; while (c < '0' || c > '9') {
if (c == '-') f = -f ; c = getchar() ;
} while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
} return x * f ;
} int n , m ; int a[N] , fir[500] , belong[N] ;
int pi[N << 1] , cnt , len , length ;
int last[N] ; bool vis[N] ;
int lazy[N] ; int c[N] ;
int bucket[N] ; struct Pro {
int opt , l , r , x ;
} b[N] ; struct Precursor_With_Subsesqent {
bool id ; int pos ;
} Pre[N] , Next[N] , First[N << 1] , Final[N << 1] , Block_Pre[1000] , Block_Next[1000] ; void Modify(int l , int r , int x) {
if (belong[l] == belong[r]) {
int now = belong[l] ; if (lazy[now]) {
for (int i = fir[now] ; i < fir[now + 1] ; ++ i) a[i] = lazy[now] ;
lazy[now] = 0 ;
} if (vis[now]) {
vis[now] = 0 ;
int front = 0 , back = 0 ; for (int i = fir[now] ; i < l ; ++ i) {
Pre[i].id = 0 , Pre[i].pos = i - 1 ;
if (i != l - 1) {
Next[i].id = 0 , Next[i].pos = i + 1 ;
} else {Next[i].id = 0 , Next[i].pos = r + 1 ; }
}
for (int i = r + 1 ; i < fir[now + 1] ; ++ i) {
if (i != r + 1) {
Pre[i].id = 0 , Pre[i].pos = i - 1 ;
} else {Pre[i].id = 0 , pre[i].pos = l - 1 ; } Next[i].id = 0 , Next[i].pos = i + 1 ;
} front = (l == fir[now] ? r + 1 : fir[now]) ;
back = (r == fir[now + 1] - 1 ? l - 1 : fir[now + 1] - 1) ;
Pre[front].id = Block_Pre[now].id , Pre[front].pos = Block_Pre[now].pos ;
int laster = Pre[front].pos , id = Pre[front].id ; if (!id) Next[laster].id = 0 , Next[laster].pos = front ;
else Block_Next[laster].id = 0 , Block_Next[laster].pos = front ; Next[back].id = Block_Next[now].id , Next[back].pos = Block_Next[now].pos ;
laster = Next[back].pos , id = Next[back].id ; if (!id) Pre[laster].id = 0 , Pre[laster].pos = back ;
else Block_Pre[laster].id = 0 , Block_Pre[laster].pos = back ; for (int i = fir[now] ; i < fir[now + 1] ; ++ i) {
if (Pre[i].id) c[i] = fir[Pre[i].pos + 1] - 1 ;
else c[i] = Pre[i].pos ;
} stable_sort(c + fir[now] , c + fir[now + 1]) ;
} else {
// for (int i = l ; i <= r ; ++ i) { // }
}
}
} signed main() {
freopen("1.in" , "r" , stdin) ;
freopen("1.out" , "w" , stdout) ;
n = read() , m = read() ;
length = sqrt(n) ; len = 1 ; for (int i = 1 ; i <= n ; i += length , ++ len) {
fir[len] = i ;
} fir[len] = n + 1 ; -- len ; for (int i = 1 ; i <= len ; ++ i) {
for (int j = fir[i] ; j < fir[i + 1] ; ++ j) {
a[j] = read() ; belong[j] = i ;
pi[++ cnt] = a[i] ;
}
} for (int i = 1 ; i <= m ; ++ i) {
b[i].opt = read() , b[i].l = read() , b[i].r = read() ; if (b[i].opt == 1) {
b[i].x = read() ; pi[++ cnt] = b[i].x ;
}
} stable_sort(pi + 1 , pi + cnt + 1) ;
cnt = unique(pi + 1 , pi + cnt + 1) - pi - 1 ; for (int i = 1 ; i <= n ; ++ i) a[i] = lower_bound(pi + 1 , pi + cnt + 1 , a[i]) - pi ;
for (int i = 1 ; i <= m ; ++ i) b[i].x = b[i].x ? lower_bound(pi + 1 , pi + cnt + 1 , b[i].x) - pi : 0 ;
for (int i = 1 ; i <= n ; ++ i) {
Pre[i].pos = last[a[i]] ; last[a[i]] = i ; if (!First[a[i]].pos) First[a[i]].pos = i ;
}
memset(last , 0 , sizeof(last)) ;
for (int i = n ; i >= 1 ; -- i) {
Next[i].pos = last[a[i]] ; last[a[i]] = i ; if (!Final[a[i]].pos) Final[a[i]].pos = i ;
} for (int OP = 1 ; OP <= m ; ++ OP) {
int opt = b[OP].opt , x = b[OP].x , l = b[OP].l , r = b[OP].r ; if (opt == 1) [
Modify(l , r , x) ;
] else {
Query(l , r) ;
}
}
}
#include <bits/stdc++.h>
#ifdef linux
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
using namespace std ;
const int N = 6e5 + 100 ;
namespace Fast_IO {
inline int read() {
int x = 0 , f = 1 ;
char c = getchar() ; while (c < '0' || c > '9') {
c = getchar() ;
} while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
} return x * f ;
} void write(int x) {
if (x / 10) write(x / 10) ;
putchar(x % 10 + '0') ;
}
} using namespace Fast_IO ; int father[N] , back[N] ;
int n , m ; int num[N] ; #ifndef ACAM
int trie[N][26] , fail[N] , numbol = 1 ; void Insert(char s[] , int len , int id) {
int now = 1 ; for (int i = 1 ; i <= len ; ++ i) {
if (!trie[now][s[i] - 'a']) trie[now][s[i] - 'a'] = ++ numbol ; father[trie[now][s[i] - 'a']] = now ;
now = trie[now][s[i] - 'a'] ;
num[now] = i ;
} back[id] = now ;
}
void Get_Fail() {
queue <int> q ;
for (int i = 0 ; i < 26 ; ++ i) trie[0][i] = 1 ; q.push(1) ; while (!q.empty()) {
int x = q.front() ; q.pop() ; for (int i = 0 ; i < 26 ; ++ i) {
if (!trie[x][i]) {
trie[x][i] = trie[fail[x]][i] ;
continue ;
} fail[trie[x][i]] = trie[fail[x]][i] ;
q.push(trie[x][i]) ;
}
}
} void Print(int x) {
for (int i = 0 ; i < 25 ; ++ i) {
if (trie[x][i]) {
cerr << x << ' ' << trie[x][i] << ' ' << (char)(i + 'a') << '\n' ;
Print(trie[x][i]) ;
}
}
}
#endif char s[N] ; int len[N] ; struct Edge {
int next , to ;
} e[N << 1] ; int head[N] , cnt ;
inline void add(int x , int y) {
cnt ++ ;
e[cnt].next = head[x] , e[cnt].to = y , head[x] = cnt ;
} int in[N] , out[N] , tot ; void dfs(int x) {
in[x] = ++ tot ; for (int i = head[x] ; i ; i = e[i].next) {
int y = e[i].to ; dfs(y) ;
} out[x] = tot ;
} #if !Segment
#define lson (id << 1)
#define rson (id << 1 | 1)
#define Cleared zero[1] = 1
#define mid ((l + r) >> 1) int t[N << 2] , lazy[N << 2] ; bool zero[N << 2] ; inline void push_down(int id) {
if (lazy[id]) {
lazy[lson] = lazy[rson] = lazy[id] ;
t[lson] = max(t[lson] , lazy[id]) ; t[rson] = max(t[rson] , lazy[id]) ;
lazy[id] = 0 ;
} if (zero[id]) {
zero[lson] = zero[rson] = 1 ;
t[lson] = t[rson] = 0 ;
zero[id] = 0 ;
}
} inline void push_up(int id) {
t[id] = max(t[lson] , t[rson]) ;
} void updata(int id , int l , int r , int x , int y , int c) {
if (x <= l && r <= y) {
push_down(id) ;
t[id] = max(t[id] , c) ; lazy[id] = c ;
return ;
} push_down(id) ; if (x <= mid) updata(lson , l , mid , x , y , c) ;
if (y > mid) updata(rson , mid + 1 , r , x , y , c) ; push_up(id) ;
} int Query(int id , int l , int r , int x) {
if (l == r) return t[id] ; push_down(id) ; if (x <= mid) return Query(lson , l , mid , x) ;
else return Query(rson , mid + 1 , r , x) ;
} void Find(int id , int l , int r) {
if (l == r) return cerr << id << '\n' , void() ;
Find(lson , l , mid) ;
Find(rson , mid + 1 , r) ;
} #undef mid
#endif int Ans[1000001] ;
struct Node {
int first , second ;
} ;
vector <Node> v[N] ; signed main() {
#ifdef LOCAL
freopen("1.in" , "r" , stdin) ;
freopen("1.out" , "w" , stdout) ;
#endif
n = read() , m = read() ; for (int i = 1 ; i <= n ; ++ i) {
scanf("%s" , s + 1) ; len[i] = strlen(s + 1) ;
cerr << s + 1 << '\n' ;
Insert(s , len[i] , i) ;
} Get_Fail() ; for (int i = 2 ; i <= numbol ; ++ i) {
add(fail[i] , i) ;
} dfs(1) ;
int x , y ; int toter = 0 ; for (int i = 1 ; i <= m ; ++ i) {
x = read() , y = read() ;
v[y].push_back({x , i}) ;
} for (int i = 1 ; i <= n ; ++ i) {
x = back[i] ;
Cleared ; while (x > 1) {
updata(1 , 1 , numbol , in[x] , out[x] , num[x]) ;
x = father[x] ;
} for (int j = 0 ; j < v[i].size() ; ++ j) {
Ans[v[i][j].second] = Query(1 , 1 , numbol , in[back[v[i][j].first]]) ;
}
} for (int i = 1 ; i <= m ; ++ i) {
write(Ans[i]) ; puts("") ;
}
}

随机推荐

  1. python基础-数据容器的通用操作

    五种数据容器的特性   列表list[]  元组tuple()  字符串str""   集合set{}   字典dict{key:value} 元素数量 支持多个 支持多个 支持多 ...

  2. RK3588J + 麒麟系统,“软硬件”全国产——让您的产品更具竞争力!

    银河麒麟嵌入式操作系统简介 银河麒麟嵌入式操作系统V10是面向物联网及工业互联网场景的安全实时嵌入式操作系统,具备信息安全.多域隔离.云边端协同.多样性算力支持等特点,可满足嵌入式场景对操作系统小型化 ...

  3. Vue源码学习(二十):$emit、$on实现原理

    好家伙, 0.一个例子 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset= ...

  4. oeasy教您玩转vim - 84 - # 命令command

    ​ 命令 command 回忆 关于 函数function 可以调用别的函数 :call append(0,"oeasy o2z o3z") 还可以执行表达式 :call exec ...

  5. Pandas库学习笔记(6) -- Pandas 基本方法

    Pandas 基本方法实例 到目前为止,我们了解了三个Pandas DataStructures以及如何创建它们.由于它在实时数据处理中的重要性,因此我们将主要关注DataFrame对象,并讨论其他一 ...

  6. 【JavaScript高级04】作用域和作用域链

    1,作用域 作用域表示的是变量的有效区域,JavaScript中作用域分为全局作用域和函数作用域(在es6之前没有块作用域).其确定时间为编写成功之后就已经确定好了. 作用域的作用是用来隔离变量,不同 ...

  7. 【js】 reduce、filter、map 数组链式调用求加和

    let data = [ {hierarchy: '香蕉', count: 1}, {hierarchy: '苹果', count: 2}, {hierarchy: '葡萄', count: 3}, ...

  8. 在英特尔 Gaudi 2 上加速蛋白质语言模型 ProtST

    引言 蛋白质语言模型 (Protein Language Models, PLM) 已成为蛋白质结构与功能预测及设计的有力工具.在 2023 年国际机器学习会议 (ICML) 上,MILA 和英特尔实 ...

  9. 如何通过minIO在后端实现断点续传

    首先是黑马的媒资管理模块流程图:前端负责计算媒资文件的MD5值,同时对媒资文件进行分块. 后端需要以下几个接口: 1.检查分块是否存在(传入参数为视频唯一标识信息与块信息):检查当前分块是否已经上传至 ...

  10. 万字干货:从消息流平台Serverless之路,看Serverless标准演进

    摘要:如今,Serverless化已经成为消息流平台发展的新趋势,而如何更好地基于Serverless化的消息流平台进行应用设计和开发,则成为了一个值得思考的问题. 本文分享自华为云社区<900 ...