# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577621 | lollipop | Poklon (COCI17_poklon) | C++17 | 5101 ms | 20044 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define FOR( j , n ) for( int j = 0 ; j < n ; j ++ )
#define FOR( k , n ) for( int k = 0 ; k < n ; k ++ )
using namespace std ;
const int mod1 = 1000000007 ;
const int mod = 998244353 ;
const int N = 2e5 + 10 ;
map < int , int > ma , ma1 ;
int block = 800 ;
struct stu{
int f ;
int s ;
int indx ;
};
int qu[ 500005 ] ;
bool sortby( stu p , stu p1 ){
if( p.f / block == p1.f / block ) return p.s < p1.s ;
else return ( p.f / block ) < ( p1.f / block ) ;
}
int ans = 0 ;
int a[ 500005 ] ;
void addR( int i ){
if( ma[ a[ i ] ] == 2 ) ans -- ;
if( ma[ a[ i ] ] == 1 ) ans ++ ;
ma[ a[ i ] ] ++ ;
}
void delR( int i ){
if( ma[ a[ i ] ] == 3 ) ans ++ ;
if( ma[ a[ i ] ] == 2 ) ans -- ;
ma[ a[ i ] ] -- ;
}
void addL( int i ){
if( ma[ a[ i ] ] == 2 ) ans -- ;
if( ma[ a[ i ] ] == 1 ) ans ++ ;
ma[ a[ i ] ] ++ ;
}
void delL( int i ){
if( ma[ a[ i ] ] == 3 ) ans ++ ;
if( ma[ a[ i ] ] == 2 ) ans -- ;
ma[ a[ i ] ] -- ;
}
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n , q ;
cin >> n >> q ;
FOR( i , n ) cin >> a[ i + 1 ] ;
vector < stu > v ;
// block = ( n / sqrt( q ) ) ;
FOR( i , q ){
int x , y ; cin >> x >> y ;
v.pb( { x , y , i } ) ;
}
sort( v.begin() , v.end() , sortby ) ;
int l = 1 , r = 0 ;
for( int i = 0 ; i < v.size() ; i ++ ){
int L = v[ i ].f ;
int R = v[ i ].s ;
while( l < L ){
delL( l ) ;
l ++ ;
}
while( l > L ){
l -- ;
addL( l ) ;
}
while( R > r ){
r ++ ;
addR( r ) ;
}
while( R < r ){
delR( r ) ;
r -- ;
}
qu[ v[ i ].indx ] = ans ;
}
FOR( i , q ) cout << qu[ i ] << "\n" ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |