QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#263994 | #6822. Bracket Query | vp_account# | TL | 54ms | 11572kb | C++17 | 5.7kb | 2023-11-25 11:05:28 | 2023-11-25 11:05:28 |
Judging History
answer
#if defined(ONLINE_JUDGE)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt")
#endif
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
const int N=3005,M=1009005;
int n,c[N],d[N],v[N];
int head[N],nxt[M],ver[M],edge[M],tot;
vector<pair<int,int>> e[N];
int read() {
int x=0,f=1; char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
return x*f;
}
void add(int x,int y,int z) {
nxt[++tot]=head[x]; head[x]=tot; ver[tot]=y; edge[tot]=z;
}
int q[N*N];
bool visited[N];
bool judge(int u) {
memset(d,0x3f,sizeof(d));
memset(v,0,sizeof v);
memset(c,0x3f,sizeof c);
int hd=1,tl=1;
q[1]=u,d[u]=0,v[u]=1,c[u]=0;
while(hd<=tl) {
int x=q[hd]; ++hd, v[x]=0;
for(int i=head[x];i;i=nxt[i]) {
int y=ver[i],z=edge[i];
if(visited[y]==true)continue;
if(d[y]>d[x]+z) {
d[y]=d[x]+z;
c[y]=c[x]+1;
if(c[y]>=n) return 1;
if(!v[y]) {
v[y]=1;
q[++tl]=y;
}
}
}
}
return 0;
}
int main() {
cin>>n;
if(n&1) {puts("?"); return 0;}
int q;
cin>>q;
for(;q--;) {
int l,r,k;
cin>>l>>r>>k;
if(k>r-l+1||r-l+1-k&1) {puts("?"); return 0;}
int c=r-l+1-k>>1;
add(l-1,r,c);
add(r,l-1,-c);
}
for(int i=1;i<=n;i++) {
add(i-1,i,1);
add(i,i-1,0);
}
for(int i=1;i<=n;i++) {
add(0,i,i>>1);
}
add(0,n,n/2);
add(n,0,-n/2);
bool exist=false;
for(int i=0;i<=n;++i)
if(visited[i]==false){
if(judge(i)){
exist=true;
}
}
if(exist) cout<<"?";
else {
cout<<"! ";
for(int i=1;i<=n;i++) cout<<(d[i]==d[i-1]?'(':')');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9552kb
input:
4 1 1 2 0
output:
! ()()
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 9536kb
input:
4 1 1 2 2
output:
! (())
result:
ok ok
Test #3:
score: 0
Accepted
time: 2ms
memory: 9572kb
input:
2 2 1 1 1 2 2 -1
output:
! ()
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 5548kb
input:
2 1 1 1 2
output:
?
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 9692kb
input:
4 0
output:
! ()()
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 9572kb
input:
8 2 1 5 1 3 7 1
output:
! ()()()()
result:
ok ok
Test #7:
score: 0
Accepted
time: 54ms
memory: 11572kb
input:
3000 0
output:
! ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()...
result:
ok ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 9572kb
input:
2 1 1 2 2
output:
?
result:
ok ok
Test #9:
score: 0
Accepted
time: 54ms
memory: 9596kb
input:
3000 1 1 3000 0
output:
! ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()...
result:
ok ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 9536kb
input:
8 2 1 6 2 3 7 1
output:
! ()()(())
result:
ok ok
Test #11:
score: -100
Time Limit Exceeded
input:
3000 3 1111 1113 3 1112 1114 -1 1113 1115 3