結果

問題 No.1950 片道きゃっちぼーる
ユーザー 👑 kmjpkmjp
提出日時 2022-05-20 23:25:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,757 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 217,536 KB
実行使用メモリ 25,264 KB
最終ジャッジ日時 2023-10-20 14:17:41
合計ジャッジ時間 13,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,572 KB
testcase_01 AC 4 ms
9,572 KB
testcase_02 AC 4 ms
9,572 KB
testcase_03 AC 415 ms
23,944 KB
testcase_04 AC 413 ms
25,264 KB
testcase_05 AC 4 ms
9,572 KB
testcase_06 AC 426 ms
23,944 KB
testcase_07 AC 385 ms
22,888 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 428 ms
23,944 KB
testcase_12 AC 399 ms
23,416 KB
testcase_13 AC 423 ms
22,888 KB
testcase_14 AC 435 ms
22,888 KB
testcase_15 WA -
testcase_16 AC 433 ms
23,416 KB
testcase_17 WA -
testcase_18 AC 392 ms
22,888 KB
testcase_19 WA -
testcase_20 AC 395 ms
22,888 KB
testcase_21 AC 434 ms
23,152 KB
testcase_22 AC 463 ms
22,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll X[202020];
ll A[202020];
ll B[202020];
template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<202020> uf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	map<ll,int> M;
	FOR(i,N) {
		cin>>X[i];
		M[X[i]]=i;
	}
	FOR(i,N) {
		cin>>A[i];
		B[i]=X[i]+A[i];
		if(M.count(X[i]+A[i])) uf(i,M[X[i]+A[i]]);
		if(M.count(X[i]-A[i])) uf(i,M[X[i]-A[i]]);
	}
	FOR(i,N) B[uf[i]]=max(B[uf[i]],B[i]);
	FOR(i,N) cout<<B[uf[i]]-X[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0