#pragma GCC optimize(3) #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<set> usingnamespace std; #define MAXN 200006 int n , m , t; int A[MAXN]; int a[MAXN] , M[MAXN]; boolchk( int len ){ for( int i = 1 ; i <= n - len + 1 ; ++ i ) { int flg = 0; memset( M , 0 , sizeof M ); for( int j = 1 ; j <= n ; ++ j ) { if( j >= i && j <= i + len - 1 ) continue; if( M[a[j]] ) {flg = 1;break;} M[a[j]] = 1; } if( !flg ) returntrue; } returnfalse; } intmain(){ cin >> n; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]) , a[i] = A[i]; sort( A + 1 , A + 1 + n ); int sz = unique( A + 1 , A + 1 + n ) - A - 1; for( int i = 1 ; i <= n ; ++ i ) a[i] = lower_bound( A + 1 , A + 1 + sz , a[i] ) - A; int l = 0 , r = n; while( l <= r ) { int mid = l + r >> 1; if( chk( mid ) ) r = mid - 1; else l = mid + 1; } cout << l << endl; }
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> usingnamespace std; #define int long long #define MAXN 1006 int n , data[MAXN][MAXN] , M[6][6]; signedmain(){ cin >> n; int x = 15, tot = 0; int now = 0; for (int i = 1; i <= 4; ++i) for (int j = 1; j <= 4; ++j) M[i][j] = x - now, now++; n /= 4; int cur = 0; for( int i = 0 ; i < n ; ++ i ) for( int j = 0 ; j < n ; ++ j ) { for( int k = 1 ; k <= 4 ; ++ k ) for( int kk = 1 ; kk <= 4 ; ++ kk ) data[i*4+k][j*4+kk] = M[k][kk] + cur * 16; ++ cur; } for( int i = 1 ; i <= n * 4 ; ++ i ) { for (int j = 1; j <= n * 4; ++j) printf("%lld ", data[i][j]); puts(""); } }
#include<cstring> #include<cstdio> #include<algorithm> #include<iostream> #include<map> usingnamespace std; #define MAXN 200006 #define int long long int n;
int T[MAXN]; voidadd( int x , int c ){ while( x <= n ) T[x] += c , x += x & -x; } intque( int x ){ int ret = 0; while( x > 0 ) ret += T[x] , x -= x & -x; return ret; } int S[MAXN]; int ans[MAXN]; signedmain(){ cin >> n; for( int i = 1 ; i <= n ; ++ i ) scanf("%lld",&S[i]); for( int i = 1 ; i <= n ; ++ i ) add( i , i ); for( int i = n ; i >= 1 ; -- i ) { int l = 0 , r = n; while( l <= r ) { int mid = l + r >> 1; if( que( mid ) > S[i] ) r = mid - 1; else l = mid + 1; } add( l , -l ); ans[i] = l;
} for( int i = 1 ; i <= n ; ++ i ) printf("%lld ",ans[i]); }
ll T[MAXN << 2]; voidmdfy(int rt,int l,int r,int L,int R,int valx){ if(L <= l && r <= R) { T[rt] += valx; return ; } int m = (l + r) >> 1; if(m >= L) mdfy( rt << 1 , l , m , L , R , valx ); if(m <= R - 1) mdfy( rt << 1 | 1 , m + 1 , r , L , R , valx); } voidwork(int rt,int l,int r){ if (l == r) { printf("%lld ", T[rt]); return; } T[rt << 1] += T[rt] , T[rt << 1 | 1] += T[rt]; int mid = (l + r) >> 1; work(rt << 1, l, mid) , work(rt << 1 | 1, mid + 1, r); }
structnode { ll val; int pos; node( ) { val = pos = 0; } }A[1000500];
boolcmp( node a , node b ){ return a.val > b.val; }
set<int> st; intmain(){ n = read() , w = read(); for (int i = 1 , l; i <= n; ++i) { st.clear(); l = read(); for (int j = 1; j <= l; ++j) A[j].pos = j, scanf("%lld", &A[j].val); int que = l , len = w - l + 1; sort(A + 1, A + 1 + l , cmp); for (int j = 1; j <= l; ++j) { int l = A[j].pos, r = A[j].pos + len - 1; auto it = st.lower_bound(A[j].pos), it1 = it; if (A[j].val < 0) r = min(r, que) , l = max(l, w - que + 1); if (it != st.end()) r = min(r, (*(it)) - 1); if (it1 != st.begin()) l = max(l, (*(--it1)) + len); if (l <= r) mdfy(1, 1, w, l, r, A[j].val); st.insert(A[j].pos); } } work(1, 1, w); }
int cnt[MAXN]; voidinsert( int x , int y ){ if( cnt[x | y] >= 2 ) return; if( x == 0 ) { ++ cnt[y]; return; } insert( x & x - 1 , y | ( x & -x ) ) , insert( x & x - 1 , y ); } int n , ans = 0; int A[MAXN]; intmain(){ cin >> n; for( int i = 1 ; i <= n ; ++ i ) A[i] = read(); for( int i = n , cur ; i >= 1 ; -- i ) { if( i <= n - 2 ) { cur = 0; for( int j = 21 ; j >= 0 ; -- j ) if( ( ~ A[i] >> j & 1 ) && cnt[ cur | ( 1 << j ) ] == 2 ) cur |= ( 1 << j ); ans = max( ans , A[i] | cur ); } insert( A[i] , 0 ); } cout << ans << endl; }
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> usingnamespace std; #define MAXN 1000006 #define int long long int n , k;
int p[MAXN] , cnt , phi[MAXN]; voidinit( ){ phi[1] = 1; for( int i = 2 ; i < MAXN ; ++ i ) { if( !p[i] ) p[++cnt] = i , phi[i] = i - 1; for( int j = 1 ; j <= cnt && p[j] * i < MAXN ; ++ j ) { p[p[j] * i] = 1; if( i % p[j] == 0 ) { phi[ p[j] * i ] = phi[i] * ( p[j] ); break; } phi[p[j] * i] = phi[i] * ( p[j] - 1 ); } } }
signedmain(){ init(); cin >> n >> k; if( k == 1 ) returnputs( "3" ) , 0; sort( phi + 1 , phi + 1 + n ); int res = 0; for( int i = 1 ; i <= k + 2 ; ++ i ) res += phi[i]; cout << res << endl; }