QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472625 | #5504. Flower Garden | zhao_daodao | WA | 2561ms | 275988kb | C++14 | 3.4kb | 2024-07-11 17:38:36 | 2024-07-11 17:38:37 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e6+5;
int T=-1;
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
struct Tree{
#define in(x) tr[x].in
#define out(x) tr[x].out
int in,out;
}tr[MAXN];int tot;
basic_string<int>V[MAXN];
inline void add(int u,int v){V[u].push_back(v);}
inline void build(int l,int r,int q){
if(l==r){
in(q)=out(q)=l;
return ;
}
int mid=l+r>>1;
in(q)=++tot,out(q)=++tot;
build(l,mid,ls(q)),build(mid+1,r,rs(q));
add(in(q),in(ls(q))),add(in(q),in(rs(q)));
add(out(ls(q)),out(q)),add(out(rs(q)),out(q));
}
inline void update(int l,int r,int ql,int qr,int q,int x,bool opt){
if(ql<=l&&r<=qr){
if(opt)add(x,in(q));
else add(out(q),x);
return ;
}int mid=l+r>>1;
if(ql<=mid)update(l,mid,ql,qr,ls(q),x,opt);
if(mid<qr)update(mid+1,r,ql,qr,rs(q),x,opt);
}
int n,q,w[MAXN];
int dfn[MAXN],low[MAXN],dfscnt;
int scc[MAXN],siz[MAXN],sc;
int instk[MAXN],stk[MAXN],tp;
inline void tarjan(int u){
dfn[u]=low[u]=++dfscnt;
instk[stk[++tp]=u]=1;
for(int v:V[u]){
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(instk[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
sc++;
while(stk[tp]!=u){
scc[stk[tp]]=sc;
instk[stk[tp--]]=0;
}
scc[stk[tp]]=sc;
instk[stk[tp--]]=0;
}
}
basic_string<int>G[2][MAXN];
int deg[MAXN],col[MAXN];
inline void dfs(int u){
col[u]=1;
for(int v:G[1][u])if(!col[v])
dfs(v);
}
signed main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
if(T==-1)cin>>T;
for(int i=1;i<=tot;i++)dfn[i]=low[i]=scc[i]=siz[i]=instk[i]=stk[i]=deg[i]=col[i]=0;
for(int i=1;i<=tot;i++)V[i].clear(),G[0][i].clear(),G[1][i].clear();
dfscnt=sc=tp=0;
cin>>n>>q;tot=3*n;
build(1,3*n,1);
for(int i=1;i<=3*n;i++)w[i]=1;
for(int i=1,a_,b_,c_,d_;i<=q;i++){
cin>>a_>>b_>>c_>>d_;
int now=++tot;
update(1,3*n,a_,b_,1,now,0);
update(1,3*n,c_,d_,1,now,1);
}
for(int i=1;i<=tot;i++)if(!dfn[i])tarjan(i);
for(int i=1;i<=tot;i++)siz[scc[i]]+=w[i];
for(int u=1;u<=tot;u++)for(int v:V[u])
if(scc[u]!=scc[v]){
G[1][scc[u]].push_back(scc[v]);
G[0][scc[v]].push_back(scc[u]);
deg[scc[u]]++;
}
queue<int>q;
for(int i=1;i<=sc;i++)if(!deg[i])q.push(i);
int all=0;
while(!q.empty()){
int u=q.front();q.pop();
if(siz[u]>n)continue;
col[u]=1,all+=siz[u];
if(all>=n)break;
for(int v:G[0][u])if(!--deg[v])q.push(v);
}
if(all>=n){
cout<<"TAK\n";
for(int i=1;i<=3*n;i++)
if(col[scc[i]])cout<<'F';
else cout<<'R';
cout<<"\n";
if(--T)main();else exit(0);
}
for(int _=1;_<=sc;_++)if(siz[_]>n){
for(int i=1;i<=sc;i++)col[i]=0;
all=0;dfs(_);
for(int i=1;i<=sc;i++)all+=col[i]*siz[i];
if(all<=2*n){
cout<<"TAK\n";
for(int i=1;i<=3*n;i++)
if(col[scc[i]])cout<<'F';
else cout<<'R';
cout<<"\n";
if(--T)main();else exit(0);
}
}
cout<<"NIE\n";
if(--T)main();else exit(0);
}
詳細信息
Test #1:
score: 100
Accepted
time: 19ms
memory: 102640kb
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 RRF NIE
result:
ok good!
Test #2:
score: 0
Accepted
time: 2561ms
memory: 217256kb
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...
output:
NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE
result:
ok good!
Test #3:
score: 0
Accepted
time: 2347ms
memory: 275988kb
input:
10 33333 100000 15207 33614 66276 66276 97173 97173 67589 73960 19673 36626 65207 65207 89825 98169 27079 27079 56067 56966 7560 7560 18170 35477 18752 18752 32621 36748 34460 34460 61595 61700 14117 14117 32395 36710 9064 9064 13172 13172 1728 4640 40462 41878 47171 47171 76965 82414 5767 5767 9225...
output:
TAK FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
result:
ok good!
Test #4:
score: 0
Accepted
time: 2242ms
memory: 253364kb
input:
10 33333 100000 2646 2646 6430 6446 82226 82231 15128 15132 877 877 85831 88474 51389 79196 37573 37573 38030 38030 14248 14280 63032 68489 81074 81074 46468 46468 7403 7487 19864 20058 97979 97979 71640 71833 8558 8558 12121 12434 82481 82481 32901 32901 1899 2162 65312 77886 75969 75974 87983 8798...
output:
TAK FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
result:
ok good!
Test #5:
score: -100
Wrong Answer
time: 343ms
memory: 178176kb
input:
87005 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 1 1 1 3 2 3 1 2 1 1 2 2 2 2 1 1 1 2 1 3 1 1 1 1 1 3 4 20 3 5 6 12 4 5 7 11 1 1 2 2 3 4 7 12 3 5 10 10 3 5 8 8 4 4 9 11 4 4 7 7 1 1 9 10 3 4 6 9 3 5 11 12 3 3 7 9 3 5 2 2 4 5 2 2 1 1 7 11 1 1 10 10 3 5 7 8 4 4 2 2 1 1 2 2 4 5 8 10 4 12 11 ...
output:
TAK RRF NIE TAK RFF TAK RRF NIE TAK RFRRRFRRFRRF TAK RFRFFFRRRRRR NIE TAK FFFFRRRFRRRRRRR TAK FRRRRRRRFRRF TAK FFRRRRRRRRRF TAK FFFFFRRRRRRRRRR TAK FRRRRRRRFRRF TAK FFRRFFRRRRRRRRF TAK RRRRRRRRR TAK RFFRRRRRRRRF NIE TAK RRRRRRRRR NIE TAK RRRRRRRRR TAK RRRRRFRRFRRF TAK FRRRFRRRRRRFFRF TAK RRRRRRFRFRR...
result:
wrong answer odpowiedz ma za malo/duzo roz!