Submission #855695
Source Code Expand
Copy
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF 1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline ll getint(){
ll _x=0,_tmp=1; char _tc=getchar();
while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
if( _tc == '-' ) _tc=getchar() , _tmp = -1;
while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
return _x*_tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
ll _ = _x + _y;
if( _ >= _mod ) _ -= _mod;
return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
ll _ = _x - _y;
if( _ < 0 ) _ += _mod;
return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
ll _ = _x * _y;
if( _ >= _mod ) _ %= _mod;
return _;
}
ll mypow( ll _a , ll _x , ll _mod ){
if( _x == 0 ) return 1ll;
ll _tmp = mypow( _a , _x / 2 , _mod );
_tmp = mul( _tmp , _tmp , _mod );
if( _x & 1 ) _tmp = mul( _tmp , _a , _mod );
return _tmp;
}
ll mymul( ll _a , ll _x , ll _mod ){
if( _x == 0 ) return 0ll;
ll _tmp = mymul( _a , _x / 2 , _mod );
_tmp = add( _tmp , _tmp , _mod );
if( _x & 1 ) _tmp = add( _tmp , _a , _mod );
return _tmp;
}
inline bool equal( D _x , D _y ){
return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 202020
struct Seg{
int vl , tag , lft , rgt;
Seg(){
vl = tag = lft = rgt = 0;
}
} st[ N << 5 ];
int _cnt = 1;
int copy( int id ){
int now = _cnt ++;
st[ now ] = st[ id ];
return now;
}
#define mid ((l+r)>>1)
void push( int now , int l , int r ){
if( st[ now ].tag ){
st[ now ].lft = copy( st[ now ].lft );
st[ now ].rgt = copy( st[ now ].rgt );
st[ st[ now ].lft ].vl += st[ now ].tag;
st[ st[ now ].lft ].tag += st[ now ].tag;
st[ st[ now ].rgt ].vl += st[ now ].tag;
st[ st[ now ].rgt ].tag += st[ now ].tag;
}
st[ now ].tag = 0;
}
void modify( int now , int l , int r , int ql , int qr ){
if( r < ql || l > qr || ql > qr ) return;
if( ql <= l && r <= qr ){
st[ now ].vl ++;
st[ now ].tag ++;
return;
}
push( now , l , r );
st[ now ].lft = copy( st[ now ].lft );
st[ now ].rgt = copy( st[ now ].rgt );
modify( st[ now ].lft , l , mid , ql , qr );
modify( st[ now ].rgt , mid + 1 , r , ql , qr );
}
int query( int now , int l , int r , int pos ){
if( now == 0 ){
assert( false );
return 0;
}
if( l == r ) return st[ now ].vl;
push( now , l , r );
if( pos <= mid ) return query( st[ now ].lft , l , mid , pos );
return query( st[ now ].rgt , mid + 1 , r , pos );
}
void build(){
}
int n , x[ N ] , l , q , ans[ N ];
vector< PII > v[ N ];
void init(){
n = getint();
for( int i = 1 ; i <= n ; i ++ )
x[ i ] = getint();
l = getint();
q = getint();
for( int i = 0 ; i < q ; i ++ ){
int ai = getint();
int bi = getint();
if( ai > bi ) swap( ai , bi );
v[ ai ].push_back( { bi , i } );
}
}
int root[ N ];
void solve(){
root[ n ] = copy( 0 );
for( int i = n - 1 ; i >= 1 ; i -- ){
int bl = i + 1 , br = n , til = i + 1;
while( bl <= br ){
int bmid = ( bl + br ) >> 1;
if( x[ bmid ] - x[ i ] <= l )
til = bmid, bl = bmid + 1;
else br = bmid - 1;
}
root[ i ] = copy( root[ til ] );
modify( root[ i ] , 1 , n , i + 1 , n );
for( PII qry : v[ i ] )
ans[ qry.SE ] = query( root[ i ] , 1 , n , qry.FI );
}
for( int i = 0 ; i < q ; i ++ )
printf( "%d\n" , ans[ i ] );
}
int main(){
build();
//__ = getint();
while( __ -- ){
init();
solve();
}
}
Submission Info
Submission Time |
|
Task |
E - Tak and Hotels |
User |
eddy1021 |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
4224 Byte |
Status |
AC |
Exec Time |
327 ms |
Memory |
109696 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
500 / 500 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
example_01.txt |
Subtask1 |
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt |
All |
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt |
Case Name |
Status |
Exec Time |
Memory |
example_01.txt |
AC |
157 ms |
105984 KB |
subtask1_01.txt |
AC |
155 ms |
105984 KB |
subtask1_02.txt |
AC |
157 ms |
105984 KB |
subtask1_03.txt |
AC |
156 ms |
105984 KB |
subtask1_04.txt |
AC |
156 ms |
105984 KB |
subtask1_05.txt |
AC |
156 ms |
105984 KB |
subtask1_06.txt |
AC |
169 ms |
105984 KB |
subtask1_07.txt |
AC |
158 ms |
105984 KB |
subtask1_08.txt |
AC |
157 ms |
105984 KB |
subtask1_09.txt |
AC |
156 ms |
105984 KB |
subtask1_10.txt |
AC |
155 ms |
105984 KB |
subtask1_11.txt |
AC |
157 ms |
105984 KB |
subtask1_12.txt |
AC |
156 ms |
105984 KB |
subtask1_13.txt |
AC |
156 ms |
105984 KB |
subtask2_01.txt |
AC |
322 ms |
109568 KB |
subtask2_02.txt |
AC |
316 ms |
109696 KB |
subtask2_03.txt |
AC |
327 ms |
109568 KB |
subtask2_04.txt |
AC |
246 ms |
108160 KB |
subtask2_05.txt |
AC |
257 ms |
108416 KB |
subtask2_06.txt |
AC |
299 ms |
109312 KB |
subtask2_07.txt |
AC |
312 ms |
109568 KB |
subtask2_08.txt |
AC |
315 ms |
109696 KB |
subtask2_09.txt |
AC |
315 ms |
109696 KB |
subtask2_10.txt |
AC |
316 ms |
109696 KB |
subtask2_11.txt |
AC |
309 ms |
109568 KB |
subtask2_12.txt |
AC |
259 ms |
109184 KB |
subtask2_13.txt |
AC |
297 ms |
109312 KB |