求卡常
  • 板块灌水区
  • 楼主youakioi
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/2/6 21:38
  • 上次更新2025/2/7 10:28:28
查看原帖
求卡常
696748
youakioi楼主2025/2/6 21:38
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: putc;
using io :: print;
const int N=2e6+10;
struct node{
	int l,r,minn,tag;
};
struct segment_tree{
	node t[N<<2];
	void build(int k,int l,int r){
		t[k].l=l,t[k].r=r;
		if(l==r){
			return;
		}
		int mid=(l+r)>>1;
		build(k*2,l,mid);
		build(k*2+1,mid+1,r);
	}
	inline void spread(int k){
		int x=t[k].tag;
		t[k*2].minn+=x,t[k*2].tag+=x;
		t[k*2+1].minn+=x,t[k*2+1].tag+=x;
		t[k].tag=0; 
	}
	void change(int k,int l,int r,int p){
		int L=t[k].l,R=t[k].r;
		if(l>R||L>r) return;
		if(l<=L&&R<=r){
			t[k].minn+=p;
			t[k].tag+=p;
			return;
		}
		spread(k);
		change(k*2,l,r,p);
		change(k*2+1,l,r,p);
		t[k].minn=min(t[k*2].minn,t[k*2+1].minn);
	}
	int query(int k,int l,int r){
		int L=t[k].l,R=t[k].r;
		if(l>R||L>r) return 1e9;
		if(l<=L&&R<=r) return t[k].minn;
		spread(k);
		return min(query(k*2,l,r),query(k*2+1,l,r));
	}
}t1,t2; 
int n,p[N],a[N];
vector<int> b[N];
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	cin.tie(0);
//	cout.tie(0);
//	ios::sync_with_stdio(0);
	gi(n);
	n*=2;
	t1.build(1,1,n),t2.build(1,1,n);
	for(int i=1;i<=n;i++) gi(p[i]),b[p[i]].push_back(i),t1.change(1,i,i,i),t2.change(1,i,i,n-i+1);
	for(int i=1;i<=n;i++){
		if(a[i]) continue;
//		cout<<t1.query(1,1,n)<<' '<<t2.query(1,1,n)<<endl;
//		cout<<i<<endl; 
//		for(int j=1;j<=n;j++) cout<<t1.query(1,j,j)<<' ';
//		cout<<endl;
//		for(int j=1;j<=n;j++) cout<<t2.query(1,j,j)<<' ';
//		cout<<endl;
		if(t1.t[1].minn>=0&&t2.t[1].minn>=0&&t2.query(1,1,i)-4>=0&&t2.query(1,1,b[p[i]][1])-2>=0){
			t2.change(1,1,i,-2),t2.change(1,1,b[p[i]][1],-2);
			a[i]=a[b[p[i]][1]]=1;
		}else{
			t1.change(1,i,n,-2),t1.change(1,b[p[i]][1],n,-2);
			a[i]=a[b[p[i]][1]]=2;
		}
	}
	if(t1.query(1,1,n)>=0&&t2.query(1,1,n)>=0){
		for(int i=1;i<=n;i++){
			if(a[i]==1) putc('(');
			else putc(')');
		}
	}else putc(':'),putc('(');
	return 0;
}

2025/2/6 21:38
加载中...