結果

問題 No.1170 Never Want to Walk
ユーザー yurujirouyurujirou
提出日時 2021-09-22 17:46:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,783 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 6,244 KB
最終ジャッジ日時 2023-09-18 19:00:32
合計ジャッジ時間 7,331 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,500 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 343 ms
5,800 KB
testcase_28 AC 343 ms
5,624 KB
testcase_29 AC 354 ms
5,748 KB
testcase_30 AC 353 ms
5,652 KB
testcase_31 AC 340 ms
5,632 KB
testcase_32 AC 336 ms
6,216 KB
testcase_33 AC 338 ms
6,164 KB
testcase_34 AC 347 ms
6,244 KB
testcase_35 AC 350 ms
6,164 KB
testcase_36 AC 330 ms
6,152 KB
testcase_37 AC 345 ms
6,032 KB
testcase_38 AC 354 ms
6,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
using namespace std;

//#include <atcoder/all>
//using namespace atcoder;

#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define RREP(i,n) for(int i = (int)n-1; i >= 0; i--)
#define LREP(i,n) for(LL i = 0; i < (LL)n; i++)

#define Vi vector<int>
#define Vl vector<long long>
#define LP pair<long long ,long long>
#define P pair<int, int>
#define T3 tuple<LL, LL, LL>
#define T4 tuple<LL, LL, LL, LL>
#define INF 1000000007
#define SIZE	300010
#define MOD 1000000007
typedef long long LL;

int N, A, B;
int X[SIZE];

int parent[SIZE], s[SIZE];
void init() {
	REP(i, N) {
		parent[i] = i;
		s[i] = 1;
	}
}

int par(int a) {
	if (parent[a] == a) return a;
	else return parent[a] = par(parent[a]);
}

void merge(int a, int b) {
	int pa = par(a), pb = par(b);
	if(pa != pb) {
		parent[pb] = pa;
		s[pa] += s[pb];
	}
}

bool same(int a, int b) {
	int pa = par(a), pb = par(b);
	if (pa == pb) return true;
	else return false;
}

int size(int a) {
	int pa = par(a);
	return s[pa];
}

int main() {
	cin >> N >> A >> B;
	REP(i, N) cin >> X[i];
	X[N] = 2 * INF;
	init();

	queue<int> que;
	int left = 0, right = 0;
	REP(i, N) {
		while (X[right] <= B + X[i]) {
			que.push(X[right]);
			right += 1;
		}
		while (X[left] < A + X[i] && que.size()) {
			que.pop();
			left += 1;
		}
		
		if (que.size()) {
			merge(i, left);
		}

		for (int j = right - 1; j > left; j--) {
			if (same(j, j - 1)) break;
			else merge(j, j - 1);
		}
	}
	REP(i, N) {
		cout << size(i) << endl;
	}
}
0