QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584511 | #4212. Brackets | ciuim | WA | 1ms | 9944kb | C++14 | 2.5kb | 2024-09-23 14:58:29 | 2024-09-23 14:58:30 |
Judging History
answer
bool M1;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<" MB\n"
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#define i128 __int128
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define fo(a,b,c) for(ll a=b;a<=c;++a)
#define re(a,b,c) for(ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<pii> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
ll _=1;
const ll inf=2e17+5,iinf=2e9;
const ll N=500005;
ll n,a[N];
set<ll> s,ss;
ll buk[N],cx[N][2],use[N];
struct IO
{
ll mn;
ll tag;
}node[N*4];
void wk(ll rt,ll val)
{
node[rt].mn+=val;
node[rt].tag+=val;
}
void pd(ll rt)
{
wk(rt*2,node[rt].tag);
wk(rt*2+1,node[rt].tag);
node[rt].tag=0;
}
void ud(ll rt,ll l,ll r,ll L,ll R,ll val)
{
if(L<=l&&r<=R)
{
wk(rt,val);
return;
}
ll mid=(l+r)/2;
pd(rt);
if(L<=mid) ud(rt*2,l,mid,L,R,val);
if(R>mid) ud(rt*2+1,mid+1,r,L,R,val);
node[rt].mn=max(node[rt*2].mn,node[rt*2+1].mn);
}
void bt(ll rt,ll l,ll r)
{
if(l==r)
{
node[rt].mn=-(2*n-l+1);
return;
}
ll mid=(l+r)/2;
bt(rt*2,l,mid);
bt(rt*2+1,mid+1,r);
node[rt].mn=max(node[rt*2].mn,node[rt*2+1].mn);
}
void sol()
{
n=gi();
bt(1,1,2*n);
fo(i,1,n) buk[i]=1;
fo(i,1,n*2) a[i]=gi();
fo(i,1,n*2)
{
if(cx[a[i]][0]) cx[a[i]][1]=i;
else cx[a[i]][0]=i;
}
ll num=0;
fo(i,1,2*n)
{
if(i==cx[a[i]][1]) continue;
ud(1,1,2*n,1,i,2);
ud(1,1,2*n,1,cx[a[i]][1],2);
if(node[1].mn>0)
{
ud(1,1,2*n,1,i,-2);
ud(1,1,2*n,1,cx[a[i]][1],-2);
}
else use[a[i]]=1,num++;
}
if(num!=n/2)
{
cout<<"(";
return;
}
fo(i,1,n*2)
{
if(use[a[i]])
{
cout<<"(";
}
else
{
cout<<")";
}
}
}
bool M2;
int main()
{
int Time=clock();
look_memory;
// _=gi();
while(_--)
{
sol();
printf("\n");
}
look_time;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9944kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7984kb
input:
1 1 1
output:
))
result:
wrong answer 1st lines differ - expected: '(', found: '))'