#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usingnamespace std; #define MAXN 300006 #define P 998244353 intPow( int x , int a ){ int cur = x , ans = 1; while( a ) { if( a & 1 ) ans = 1ll * ans * cur % P; cur = 1ll * cur * cur % P , a >>= 1; } return ans; } int n , m; int A[MAXN]; boolchk( int x ){ int base = 0; for( int i = 1 ; i <= n ; ++ i ) { if( A[i] + x >= m ) { int t = ( A[i] + x ) % m; if( t >= base ) continue; } if( A[i] + x >= base && A[i] <= base ) continue; elseif( A[i] + x >= base ) base = A[i]; elsereturnfalse; } returntrue; } intmain(){ cin >> n >> m; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",A+i); int l = 0 , r = m; while( l <= r ) { int m = l + r >> 1; if( chk( m ) ) r = m - 1; else l = m + 1; } cout << l << endl; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usingnamespace std; #define MAXN 300116 #define P 998244353 intPow( int x , int a ){ int cur = x , ans = 1; while( a ) { if( a & 1 ) ans = 1ll * ans * cur % P; cur = 1ll * cur * cur % P , a >>= 1; } return ans; } int n , m; char ch[MAXN]; int ans[MAXN]; intmain(){ scanf("%s",ch); n = strlen( ch ); int cur = -1; longlong res = 0; for( int i = 0 ; i < n ; ++ i ) { for( int j = i - 1 ; j >= 0 ; -- j ) { if( ch[i] == ch[j] && ch[j] == ch[i + i - j] ) { ans[i + ( i - j )] = max( ans[i + i - j] , j + 1 ); break; } } } int re = 0; for( int i = 0 ; i < n ; ++ i ) re = max( re , ans[i] ) , res += re; cout << res << endl; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usingnamespace std; #define MAXN 300016 #define P 998244353 intPow( int x , int a ){ int cur = x , ans = 1; while( a ) { if( a & 1 ) ans = 1ll * ans * cur % P; cur = 1ll * cur * cur % P , a >>= 1; } return ans; } int n , q; int A[MAXN]; int T[MAXN << 2][20], w; voidpu(int rt){ for( int i = 0 ; i < 20 ; ++ i ) { T[rt][i] = T[rt << 1][i]; int v = T[rt << 1][i]; for( int j = 0 ; j < 20 ; ++ j ) if( v & ( 1 << j ) ) T[rt][i] |= T[rt << 1 | 1][j]; T[rt][i] |= T[rt << 1 | 1][i]; } } voidbuild(int rt, int l, int r){ if (l == r) { for( int w = 0 ; w < 20 ; ++ w ) if (A[l] & (1 << w)) T[rt][w] = A[l]; return; } int m = l + r >> 1; build(rt << 1, l, m), build(rt << 1 | 1, m + 1, r); pu(rt); } int fr , to; boolque(int rt, int l, int r, int L, int R){ if( fr & to ) returntrue; if (L <= l && R >= r) { int re = 0; for( int w = 0 ; w < 20 ; ++ w ) if( fr & ( 1 << w ) ) re |= T[rt][w]; fr |= re; return fr & to; } int m = l + r >> 1, re = 0; if (L <= m) re |= que(rt << 1, l, m, L, R); if (R > m) re |= que(rt << 1 | 1, m + 1, r, L, R); return re; } intmain(){ cin >> n >> q; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",A + i); build( 1 , 1 , n ); int x , y; while( q --> 0 ) { scanf("%d%d",&x,&y); if( x + 1 == y ) { puts( ( A[x] & A[y] ) ? "Shi" : "Fou" ); continue; } fr = A[x] , to = A[y]; puts(que( 1 , 1 , n , x + 1 , y - 1 ) ? "Shi" : "Fou"); } }