QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#520182 | #5504. Flower Garden | 123456xwd | WA | 1851ms | 273984kb | C++14 | 3.3kb | 2024-08-15 11:22:01 | 2024-08-15 11:22:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define p_b push_back
#define m_p make_pair
#define pii pair<int,int>
#define x first
#define y second
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
#define gcd __gcd
#define lowbit(x) (x&(-x))
using namespace std;
int rd(){
int x=0,f=1; char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if (ch=='-') f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
const int N=1e6+5,INF=0x3f3f3f3f3f3f3f3f;
int n,m,tot;
vector<int> G[N],E[N],EE[N];
int t1[N],t2[N];
void add(int u,int v){
G[u].p_b(v);
}
void build(int k,int l,int r){
if(l==r){
t1[k]=t2[k]=l;
return;
}
t1[k]=++tot,t2[k]=++tot;
build(ls,l,mid);build(rs,mid+1,r);
add(t1[ls],t1[k]),add(t1[rs],t1[k]);
add(t2[k],t2[ls]),add(t2[k],t2[rs]);
}
void add1(int k,int l,int r,int x,int y,int v){
if(x<=l&&r<=y){
add(t1[k],v);
return;
}
if(x<=mid) add1(ls,l,mid,x,y,v);
if(y>mid) add1(rs,mid+1,r,x,y,v);
}
void add2(int k,int l,int r,int x,int y,int u){
if(x<=l&&r<=y){
add(u,t2[k]);
return;
}
if(x<=mid) add2(ls,l,mid,x,y,u);
if(y>mid) add2(rs,mid+1,r,x,y,u);
}
int dfn[N],low[N],belong[N],siz[N],cnt,color;
bool vis[N];stack<int> q;
void tarjan(int u){
dfn[u]=low[u]=++cnt;
vis[u]=1,q.push(u);
for(auto v : G[u]){
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
color++;int v;
do{
v=q.top();q.pop();vis[v]=0;
belong[v]=color,siz[color]+=(v<=n*3);
}while(v!=u);
}
}
int in[N],a[N],b[N];
bool c[N];
void print(){
puts("TAK");
for(int i=1;i<=n*3;i++) putchar(c[belong[i]]?'R':'F');
puts("");
}
void solve(){
n=rd(),m=rd();
tot=n*3;
build(1,1,n*3);
for(int i=1;i<=m;i++){
int A,B,C,D,u;
A=rd(),B=rd(),C=rd(),D=rd();
u=++tot;
add1(1,1,n*3,A,B,u);add2(1,1,n*3,C,D,u);
}
for(int i=1;i<=tot;i++) if(!dfn[i]) tarjan(i);
for(int u=1;u<=tot;u++){
for(auto v : G[u]){
if(belong[v]==belong[u]) continue;
E[belong[u]].p_b(belong[v]);
EE[belong[v]].p_b(belong[u]);
in[belong[u]]++;
}
}
vector<int> vec;queue<int> Q;bool tag=0;
for(int i=1;i<=color;i++){
if(siz[i]>=n) vec.p_b(i);
}
for(int i=1;i<=color;i++) if(!in[i]) Q.push(i);
int u,sum=0;
while(!Q.empty()){
u=Q.front();Q.pop();
if(siz[u]>=n) continue;
sum+=siz[u];c[u]=1;
if(sum>=n&&sum<=2*n){
print();
return;
}
for(auto v : E[u]){
in[v]--;
if(!in[v]) Q.push(v);
}
}//>=n作为1
for(auto u : vec){
while(!Q.empty()) Q.pop();
for(int i=1;i<=color;i++) c[i]=0,in[i]=E[i].size();
for(int i=1;i<=color;i++) if(!in[i]) Q.push(i);
c[u]=1;sum=0;
while(!Q.empty()){
u=Q.front();Q.pop();
for(auto v : EE[u]){
in[v]--;
c[v]|=c[u];
if(!in[v]) Q.push(v);
}
}
for(int i=1;i<=color;i++) sum+=c[i]*siz[i];
if(n<=sum&&sum<=2*n){
print();
return;
}
}
puts("NIE");
}
void clean(){
while(!q.empty()) q.pop();
for(int i=1;i<=tot;i++){
G[i].clear();
dfn[i]=low[i]=0;
belong[i]=siz[i]=0;
vis[i]=0;
}
for(int i=1;i<=color;i++){
E[i].clear(),EE[i].clear();
c[i]=a[i]=b[i]=in[i]=0;
}
color=tot=cnt=0;
}
signed main(){
int T=rd();
while(T--){
solve();
clean();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 90808kb
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: 1851ms
memory: 196008kb
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: -100
Wrong Answer
time: 1804ms
memory: 273984kb
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:
NIE TAK RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
result:
wrong answer zla odpowiedz!