Solution to a problem - [NOIP simulation] is not normal family bucket

Solution to a problem - not the normal sequence gang + State +

Background decent praise
on ssw02, he bombed


Abnormal gang

The main idea

50 minutes practice

Open barrels of violence, statistics can be.

60 minutes practice

Chairman of the tree plus violence

100 practice

50 points available from the practice squad offline Mo click on it. (By the way, here ZYC seniors code optimization a bit ssw02 his team Mo board)

Can be obtained from the 60 points, the President of trees recorded on a location.

Segment tree approach is also recorded on a location. (These methods range dyeing it a)

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
const int MAXN = 100005 ;
inline int read(){
   int s=0 , w=1 ; char g=getchar() ;while(g>'9'||g<'0'){if(g=='-')w=-1;g=getchar();}
   while(g>='0'&&g<='9')s=s*10+g-'0',g=getchar() ;return w*s ;
}
struct Seg{
   int l , r , id ;
}t[ MAXN ];
int N , M , block , a[ MAXN ] , pos[ MAXN ] , num[ MAXN ]  ;
ll tot = 0 , ans[ MAXN ] ;
inline bool cmp( Seg x , Seg y ){
   return ( pos[ x.l ]==pos[ y.l ] )?( x.r < y.r ) : ( pos[x.l] < pos[y.l] ) ;
}
inline void updata( int x , int  opt ){
   if( !opt ){//收缩 扩张 
       --num[ a[ x ] ] ;
       if( num[ a[ x ] ] > 2 ) tot -= a[ x ];
       else if(num[ a[ x ] ] == 2) tot -= a[ x ]*3 ;  
       else if(num[ a[ x ] ] == 1) tot += a[ x ] ;
       else tot -= a[ x ] ; 
       return;
   }
   ++num[ a[ x ] ] ;
   if( num[ a[ x ] ] > 3 )  tot += a[ x ];
   else if( num[ a[ x ] ] == 3 ) tot += a[ x ]*3 ;
   else if( num[ a[ x ] ] == 2 ) tot -= a[ x ] ;
   else tot += a[ x ];
}
void  Mo(){
   for( int l = 1 , r = 0 , i = 1 ; i <= M  ; ++i ){
       while( l < t[ i ].l )updata( l++ , 0 ) ;
       while( l > t[ i ].l )updata( --l , 1 ) ;
       while( r < t[ i ].r )updata( ++r , 1 ) ;
       while( r > t[ i ].r )updata( r-- , 0 ) ;
       ans[ t[ i ].id ] = tot ;
   }
}
int main(){
   freopen("abnormal.in","r",stdin);
   freopen("abnormal.out","w",stdout);
   N = read() , M = read() , block = sqrt(N) ;
   for( int i = 1 ; i <= N ; ++i )a[ i ] = read() ;
   block = sqrt( N ) ;
   for( int i = 1 ; i <= N ; ++i )pos[ i ] = (i-1) / block+1 ;
   for( int i = 1 ; i <= M ; ++i )
       t[ i ].l = read() , t[ i ].r = read() , t[ i ].id = i ;
   sort( t+1 , t+M+1 , cmp ) ;
   Mo() ;
   for( int i = 1 ; i <= M ; ++i )printf("%lld\n",ans[ i ] ) ;
   return 0 ;
} 

As a OIer, to keep the topic of respect for people, especially school seniors gold out of the question.

Not a normal country

Trie tree split heavy chain + + heuristic merge (SXK, STD)
Trie tree delete + No heuristic merge (ZYC)
tree sectional + + heuristic merge Trie tree (in fact, the first and almost)

Not the normal sequence

Cancer of the topic and people all perfectly balanced tree card. (Mang in the past when there hzy last card)

Seeking median, with a double stack it. Smaller than a constant level.

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
const int MAXN = 1000005 , mod = 1e9+7 ;
inline ll read(){
    ll s=0 ; char g=getchar() ; while(g>'9'||g<'0')g=getchar() ;
    while( g>='0'&&g<='9')s=s*10+g-'0',g=getchar() ; return s ;
}
ll ans = 0 ;
ll a[ MAXN ] , N , A , B , C ; 
priority_queue<ll>ma,mi ;
int  deal( int N ){
    if( N%2 )return N/2+1 ;
    else return N/2 ;
}
void  insert( int x ){
    int u = mi.top() ;
    if( x < u )mi.push( x ) ;
    else ma.push( -x ) ;
    while( mi.size() < ma.size() ){
        int u = -ma.top() ; ma.pop() ;
        mi.push( u ) ;
    }
    while( mi.size()-1 > ma.size() ){
        int u = mi.top() ; mi.pop() ;
        ma.push( -u ) ;
    }
}
int main(){
    freopen("unnormal.in","r",stdin) ;
    freopen("unnormal.out","w",stdout) ;
    A = read() , B = read() , C = read() , N = read() ;
    mi.push(1) ;
    ans = 1LL ;
    for( ll i = 2 ; i <= N ; ++i ){
        ll op = mi.top() ;
        op = ( op*A%mod + B*i%mod + C )%mod ; 
        insert(op);ans += (ll)op ;
    }
    cout<<ans<<endl ;
}

If insufficient, please indicate Gangster

Guess you like

Origin www.cnblogs.com/ssw02/p/11593657.html