結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-08-14 21:42:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 10,155 bytes |
| コンパイル時間 | 3,147 ms |
| コンパイル使用メモリ | 224,628 KB |
| 最終ジャッジ日時 | 2025-01-12 23:28:25 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
(*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
(*arr)=(T*)(*mem);
(*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
sort(a, a+N);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
int i;
pair<T1, T2> *arr;
walloc1d(&arr, N, &mem);
for(i=(0);i<(N);i++){
arr[i].first = a[i];
arr[i].second = b[i];
}
sort(arr, arr+N);
for(i=(0);i<(N);i++){
a[i] = arr[i].first;
b[i] = arr[i].second;
}
}
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(unsigned x){
int s=0;
char f[10];
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(unsigned long long x){
int s=0;
char f[21];
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
const int d = WRITER_DOUBLE_DIGIT;
int k;
int r;
double v;
if(x!=x || (x==x+1 && x==2*x)){
my_putchar_unlocked('E');
my_putchar_unlocked('r');
my_putchar_unlocked('r');
return;
}
if(x < 0){
my_putchar_unlocked('-');
x = -x;
}
x += 0.5 * pow(0.1, d);
r = 0;
v = 1;
while(x >= 10*v){
v *= 10;
r++;
}
while(r >= 0){
r--;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
v *= 0.1;
my_putchar_unlocked(k + '0');
}
if(d > 0){
my_putchar_unlocked('.');
v = 1;
for(r=(0);r<(d);r++){
v *= 0.1;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
my_putchar_unlocked(k + '0');
}
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar_unlocked(c[i]);
}
}
inline void wt_L(string &x){
int i=0;
for(i=0;x[i]!='\0';i++){
my_putchar_unlocked(x[i]);
}
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
int i;
sz++;
for(i=sz-1;i>k;i--){
a[i] = a[i-1];
}
a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
int i;
sz++;
for(i=sz-1;i>k;i--){
a[i] = a[i-1];
}
for(i=sz-1;i>k;i--){
b[i] = b[i-1];
}
a[k] = aval;
b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
int i;
sz++;
for(i=sz-1;i>k;i--){
a[i] = a[i-1];
}
for(i=sz-1;i>k;i--){
b[i] = b[i-1];
}
for(i=sz-1;i>k;i--){
c[i] = c[i-1];
}
a[k] = aval;
b[k] = bval;
c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
int i;
sz++;
for(i=sz-1;i>k;i--){
a[i] = a[i-1];
}
for(i=sz-1;i>k;i--){
b[i] = b[i-1];
}
for(i=sz-1;i>k;i--){
c[i] = c[i-1];
}
for(i=sz-1;i>k;i--){
d[i] = d[i-1];
}
a[k] = aval;
b[k] = bval;
c[k] = cval;
d[k] = dval;
}
struct unionFind{
int *d;
int N;
int M;
inline void malloc(const int n){
d = (int*)std::malloc(n*sizeof(int));
M = n;
}
inline void malloc(const int n, const int fg){
d = (int*)std::malloc(n*sizeof(int));
M = n;
if(fg){
init(n);
}
}
inline void free(void){
std::free(d);
}
inline void walloc(const int n, void **mem=&wmem){
walloc1d(&d, n, mem);
M = n;
}
inline void walloc(const int n, const int fg, void **mem=&wmem){
walloc1d(&d, n, mem);
M = n;
if(fg){
init(n);
}
}
inline void init(const int n){
int i;
N = n;
for(i=(0);i<(n);i++){
d[i] = -1;
}
}
inline void init(void){
init(M);
}
inline int get(int a){
int t = a;
int k;
while(d[t]>=0){
t=d[t];
}
while(d[a]>=0){
k=d[a];
d[a]=t;
a=k;
}
return a;
}
inline int connect(int a, int b){
if(d[a]>=0){
a=get(a);
}
if(d[b]>=0){
b=get(b);
}
if(a==b){
return 0;
}
if(d[a] < d[b]){
d[a] += d[b];
d[b] = a;
}
else{
d[b] += d[a];
d[a] = b;
}
return 1;
}
inline int operator()(int a){
return get(a);
}
inline int operator()(int a, int b){
return connect(a,b);
}
inline int& operator[](const int a){
return d[a];
}
inline int size(int a){
a = get(a);
return -d[a];
}
inline int sizeList(int res[]){
int i;
int sz=0;
for(i=(0);i<(N);i++){
if(d[i]<0){
res[sz++] = -d[i];
}
}
return sz;
}
}
;
int N;
int A;
int B;
int X[200000];
int sz;
int l[400000];
int r[400000];
int main(){
int i;
wmem = memarr;
int a;
int b;
unionFind uf;
set<int> s;
rd(N);
rd(A);
rd(B);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
rd(X[Lj4PdHRW]);
}
}
uf.malloc(N,1);
for(i=(0);i<(N);i++){
int RZTsC2BF;
int FmcKpFmN;
int xr20shxY;
RZTsC2BF = 0;
FmcKpFmN = N;
while(RZTsC2BF < FmcKpFmN){
if((RZTsC2BF + FmcKpFmN)%2==0){
xr20shxY = (RZTsC2BF + FmcKpFmN) / 2;
}
else{
xr20shxY = (RZTsC2BF + FmcKpFmN - 1) / 2;
}
if(X[xr20shxY] >= X[i]-B){
FmcKpFmN = xr20shxY;
}
else{
RZTsC2BF = xr20shxY + 1;
}
}
a =FmcKpFmN;
int KrdatlYV;
int ao_dF3pO;
int tU__gIr_;
KrdatlYV = -1;
ao_dF3pO = N-1;
while(KrdatlYV < ao_dF3pO){
if((KrdatlYV + ao_dF3pO)%2==0){
tU__gIr_ = (KrdatlYV + ao_dF3pO) / 2;
}
else{
tU__gIr_ = (KrdatlYV + ao_dF3pO + 1) / 2;
}
if(X[tU__gIr_] <= X[i]-A){
KrdatlYV = tU__gIr_;
}
else{
ao_dF3pO = tU__gIr_ - 1;
}
}
b =ao_dF3pO;
if(a <= b){
arrInsert(sz, sz, l, a, r, b);
uf(i, a);
}
int V9aVTaxx;
int APIVbQlN;
int YREPHmFM;
V9aVTaxx = 0;
APIVbQlN = N;
while(V9aVTaxx < APIVbQlN){
if((V9aVTaxx + APIVbQlN)%2==0){
YREPHmFM = (V9aVTaxx + APIVbQlN) / 2;
}
else{
YREPHmFM = (V9aVTaxx + APIVbQlN - 1) / 2;
}
if(X[YREPHmFM] >= X[i]+A){
APIVbQlN = YREPHmFM;
}
else{
V9aVTaxx = YREPHmFM + 1;
}
}
a =APIVbQlN;
int ZIeRIny5;
int iMWUTgY_;
int AlM5nNnR;
ZIeRIny5 = -1;
iMWUTgY_ = N-1;
while(ZIeRIny5 < iMWUTgY_){
if((ZIeRIny5 + iMWUTgY_)%2==0){
AlM5nNnR = (ZIeRIny5 + iMWUTgY_) / 2;
}
else{
AlM5nNnR = (ZIeRIny5 + iMWUTgY_ + 1) / 2;
}
if(X[AlM5nNnR] <= X[i]+B){
ZIeRIny5 = AlM5nNnR;
}
else{
iMWUTgY_ = AlM5nNnR - 1;
}
}
b =iMWUTgY_;
if(a <= b){
arrInsert(sz, sz, l, a, r, b);
uf(i, a);
}
}
a = 0;
sortA_L(sz, l, r);
for(i=(0);i<(N);i++){
if(s.size()){
uf(i,i-1);
}
while(a < sz && l[a]==i){
s.insert(r[a++]);
}
if(s.size() && *s.begin()==i){
s.erase(s.begin());
}
}
for(i=(0);i<(N);i++){
wt_L(uf.size(i));
wt_L('\n');
}
return 0;
}
// cLay varsion 20200813-1 [beta]
// --- original code ---
// int N, A, B, X[2d5];
// int sz, l[4d5], r[4d5];
// {
// int a, b;
// unionFind uf;
// set<int> s;
// rd(N,A,B,X(N));
// uf.malloc(N,1);
//
// rep(i,N){
// a = bsearch_min[int,k,0,N](X[k] >= X[i]-B);
// b = bsearch_max[int,k,-1,N-1](X[k] <= X[i]-A);
// if(a <= b){
// arrInsert(sz, sz, l, a, r, b);
// uf(i, a);
// }
// a = bsearch_min[int,k,0,N](X[k] >= X[i]+A);
// b = bsearch_max[int,k,-1,N-1](X[k] <= X[i]+B);
// if(a <= b){
// arrInsert(sz, sz, l, a, r, b);
// uf(i, a);
// }
// }
// a = 0;
// sortA(sz, l, r);
// rep(i,N){
// if(s.size()) uf(i,i-1);
// while(a < sz && l[a]==i) s.insert(r[a++]);
// if(s.size() && *s.begin()==i) s.erase(s.begin());
// }
//
// rep(i,N) wt(uf.size(i));
// }
LayCurse