QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#504926 | #5504. Flower Garden | ucup-team1525# | RE | 4ms | 22188kb | C++20 | 4.0kb | 2024-08-04 17:22:15 | 2024-08-04 17:22:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50,T=3e6;
int n, q;
int tot;
vector<int> e[T+5];
int id[20][N+5];
int id2[20][N+5];
void adde(int u,int v){
// printf("edge %d %d\n",u,v);
e[u].push_back(v);
}
// void addint(int l,int r){
// int k=__lg(r-l+1);
// adde(u,id[k][l]);
// adde(u,id[k][r-(1<<k)+1]);
// }
int dfn[T+5],low[T+5],dfns;
bool in[T+5];
int st[T+5],ss;
int bl[T+5],sz[T+5],cnt;
void dfs(int u){
dfn[u]=low[u]=++dfns;
st[++ss]=u; in[u]=1;
for(auto v:e[u])
if(!dfn[v]){
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(in[v]) low[u]=min(low[u],dfn[v]);
if(dfn[u]==low[u]){
cnt++;
while(st[ss]!=u){
int v=st[ss];
bl[v]=cnt;
sz[cnt]+=v<=n;
in[v]=0;
ss--;
}
bl[u]=cnt;
sz[cnt]+=u<=n;
in[u]=0;
ss--;
}
}
vector<int> e2[T+5];
bool chk(int st){
fill(in,in+tot+1,0);
static int q[T+5];
int qs=0,sum=0;
q[++qs]=st; in[st]=1;
for(int i=1;i<=qs;i++){
int u=q[i];
sum+=sz[u];
for(auto v:e2[u])
if(!in[v]){
q[++qs]=v; in[v]=1;
}
}
if(sum<=2*n/3){
// puts("-----");
puts("TAK");
static char ans[N+5];
ans[n+1]=0;
for(int i=1;i<=n;i++)
if(in[bl[i]]) ans[i]='R';
else ans[i]='F';
printf("%s\n",ans+1);
return 1;
}
return 0;
}
void clear(){
for(int i=1;i<=tot;i++){
e[i].clear();
dfn[i]=low[i]=bl[i]=in[i]=0;
}
for(int i=1;i<=cnt;i++){
sz[i]=0; e2[i].clear();
}
tot=cnt=dfns=0;
}
void solve(){
scanf("%d %d",&n,&q); n*=3;
tot=0;
for(int i=0;n>>i;i++)
for(int j=1;j+(1<<i)-1<=n;j++){
id[i][j]=++tot;
if(i){
adde(id[i][j],id[i-1][j]);
adde(id[i][j],id[i-1][j+(1<<i-1)]);
}
}
for(int i=1;i<=n;i++)
id2[0][i]=i;
for(int i=1;n>>i;i++)
for(int j=1;j+(1<<i)-1<=n;j++){
id2[i][j]=++tot;
if(i){
adde(id2[i-1][j],id2[i][j]);
adde(id2[i-1][j+(1<<i-1)],id2[i][j]);
}
}
for(int i=1,a,b,c,d;i<=q;i++){
scanf("%d %d %d %d",&a,&b,&c,&d);
int k1=__lg(b-a+1),k2=__lg(d-c+1);
int c1=id2[k2][c],c2=id2[k2][d-(1<<k2)+1];
int r1=id[k1][a],r2=id[k1][b-(1<<k1)+1];
adde(c1,r1);
adde(c2,r2);
adde(c1,r2);
adde(c2,r1);
}
for(int i=1;i<=tot;i++)
if(!dfn[i]) dfs(i);
for(int i=1;i<=tot;i++){
int u=bl[i];
for(auto v:e[i])
if(bl[v]!=u) e2[u].push_back(bl[v]);
}
// cout<<"__________________"<<endl;
// for (int i=1;i<=cnt;++i)
// cout<<sz[i]<<' ';cout<<endl;
static bool ok[T+5];
fill(ok,ok+cnt+1,1);
for(int i=1;i<=cnt;i++)
if(sz[i]>n/3){
if(chk(i)){
clear();
return;
}
else ok[i]=0;
}
// for(int i=1;i<=tot;i++)
// printf("%d ",bl[i]);
// puts("");
int sum=0;
fill(in,in+cnt+1,0);
for(int i=1;i<=cnt;i++){
for(auto v:e2[i]) ok[i]&=ok[v];
if(ok[i]){
sum+=sz[i];
in[i]=1;
if(sum>=n/3){
// puts("11111");
puts("TAK");
static char ans[N+5];
ans[n+1]=0;
for(int i=1;i<=n;i++)
if(in[bl[i]]) ans[i]='R';
else ans[i]='F';
printf("%s\n",ans+1);
clear(); return;
}
}
}
puts("NIE");
clear();
}
int main() {
int t; scanf("%d",&t);
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 22188kb
input:
2 1 3 1 1 2 2 1 2 3 3 1 1 3 3 1 3 1 1 2 2 2 2 3 3 3 3 1 1
output:
TAK RFF NIE
result:
ok good!
Test #2:
score: -100
Runtime Error
input:
10 33333 100000 28701 40192 93418 95143 95902 97908 78378 78461 36823 44196 22268 23996 23977 24786 33315 48829 83965 90411 4923 8445 20235 21177 32543 47454 29598 35414 72477 73049 2014 12632 42163 46466 64305 65518 98825 99552 32331 41625 92772 96224 26500 54122 76990 77126 18249 20335 31165 36080...