제출 #1345000

#제출 시각아이디문제언어결과실행 시간메모리
1345000weedywelonStranded Far From Home (BOI22_island)C++20
15 / 100
103 ms23348 KiB
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <map>
#include <chrono>
#include <random>
#include <bitset>
#include <tuple>
#define SZ(x) int(x.size())
#define FR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,n) FR(i,0,n)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define A first
#define B second
#define mp(a,b) make_pair(a,b)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef unsigned __int128 U128;
typedef __int128 I128;
typedef std::pair<int,int> PII;
typedef std::pair<LL,LL> PLL;
using namespace std;

//1st subtask: run for every village, store pq of next village with smallest size +id
//2nd subtask: ts a tree. all kids can be absorbed. i can win iff sz[i]>=s[par[i]] && par[i] can win
//3rd subtask: line. for each i, find leftmost greater and rightmost greater, then merge everything in range? u do this since while(works) s[i] doubles so log1e9

const LL MAXN=2e5+5;
vector<LL> adj[MAXN];
LL pref[MAXN], s[MAXN], ans[MAXN];
struct segment_tree{
	LL st[4*MAXN];
	void update(LL id, LL lf, LL rt, LL i, LL x){
		if (i<lf || rt<i) return;
		if (lf==rt){
			st[id]=x;
			return;
		}
		LL mid=(lf+rt)/2;
		if (i<=mid) update(id*2,lf,mid,i,x);
		else update(id*2+1,mid+1,rt,i,x);
		st[id]=max(st[id*2], st[id*2+1]);
	}
	
	LL walk_left(LL id, LL lf, LL rt, LL l, LL r, LL x){
		if (rt<l || lf>r) return r+1;
		if (st[id]<x) return r+1;
		if (lf==rt) return lf;

		LL mid=(lf+rt)/2;
		if (r>mid){
			LL res=walk_left(id*2+1,mid+1,rt,l,r,x);
			if (res!=r+1) return res;
		}
		return walk_left(id*2,lf,mid,l,r,x);
	}
	
	LL walk_right(LL id, LL lf, LL rt, LL l, LL r, LL x){
		if (rt<l || lf>r) return l-1;
		if (st[id]<x) return l-1;
		if (lf==rt) return lf;

		LL mid=(lf+rt)/2;
		if (l<=mid){
			LL res=walk_right(id*2,lf,mid,l,r,x);
			if (res!=l-1) return res;
		}
		return walk_right(id*2+1,mid+1,rt,l,r,x);
	}
};

signed main(){
	FAST;
	LL n,m; cin>>n>>m;
	//LL n; cin>>n;
	FR(i,1,n+1) cin>>s[i];
	while(m--){
		LL a,b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	s[0]=s[n+1]=1e18;
	FR(i,1,n+2) pref[i]=pref[i-1]+s[i];
	
	segment_tree seg;
	FOR(i,n+2) seg.update(1,0,n+1,i,s[i]);
	
	FR(i,1,n+1){
		LL cur=s[i], l=i-1, r=i+1;
		while (l!=0 || r!=n+1){
			LL bef=cur, x=cur;
			if (l!=0){
				LL nl=seg.walk_left(1,0,n+1,0,l,x+1);
				//cout<<i<<" "<<x<<": "<<nl<<"\n";
				if (nl<l){
					cur+=pref[l]-pref[nl];
					l=nl;
				}
			}
			x=cur;
			if (r!=n+1){
				LL nr=seg.walk_right(1,0,n+1,r,n+1,x+1);
				//cout<<i<<" "<<x<<": "<<nr<<"\n";
				if (nr>r){
					cur+=pref[nr-1]-pref[r-1];
					r=nr;
				}
			}
			if (cur==bef) break;
		}
		if (l==0 && r==n+1) ans[i]=1;
	}
	FR(i,1,n+1) cout<<ans[i];
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...