QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470821 | #5504. Flower Garden | yinhee | WA | 3ms | 22024kb | C++20 | 3.6kb | 2024-07-10 16:36:35 | 2024-07-10 16:36:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define mems(x,y) memset(x,y,sizeof x)
#define Mp make_pair
#define eb emplace_back
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a);i>=(b);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
il void read(T &x){
int f=1;x=0;char c=gc();
while(c<'0'||c>'9'){
if(c=='-'){
f=-1;
}
c=gc();
}
while(c>='0'&&c<='9'){
x=x*10+c-48,c=gc();
}
x*=f;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){
read(x),read(args...);
}
template<typename T>
il void write(T x){
char buf[43];int len=0;
if(x<0){
pc('-'),x=-x;
}
do{
buf[++len]=x%10,x/=10;
}while(x);
while(len){
pc(buf[len--]+'0');
}
}
}
using namespace my_std;
const int N=1e5+7,M=1e6+7,inf=0x3f3f3f3f,mod=0;
int n,m,k,ans[N];
int cur,top,dfn[M],low[M],st[M];
bool vis[M];
int s,col[M],siz[M];
int tot,head[M];
struct node{
int to,nxt;
}e[M*5];
il void add(int u,int v){
e[++tot]={v,head[u]},head[u]=tot;
}
struct SGT{
int tr[N<<2];
void build(int l,int r,int o){
if(l==r){
tr[o]=l;
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1),build(mid+1,r,o<<1|1);
tr[o]=++k;
add(tr[o<<1],tr[o]),add(tr[o<<1|1],tr[o]);
}
void update(int l,int r,int o,int x,int y,int k){
if(l>=x&&r<=y){
add(tr[o],k);
return;
}
int mid=(l+r)>>1;
if(x<=mid){
update(l,mid,o<<1,x,y,k);
}
if(y>mid){
update(mid+1,r,o<<1|1,x,y,k);
}
}
}T;
struct sgt{
int tr[N<<2];
void build(int l,int r,int o){
if(l==r){
tr[o]=l;
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1),build(mid+1,r,o<<1|1);
tr[o]=++k;
add(tr[o],tr[o<<1]),add(tr[o],tr[o<<1|1]);
}
void update(int l,int r,int o,int x,int y,int k){
if(l>=x&&r<=y){
add(k,tr[o]);
return;
}
int mid=(l+r)>>1;
if(x<=mid){
update(l,mid,o<<1,x,y,k);
}
if(y>mid){
update(mid+1,r,o<<1|1,x,y,k);
}
}
}R;
void tarjan(int u){
dfn[u]=low[u]=++cur;
st[++top]=u;
vis[u]=1;
go(i,u){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(vis[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
s++;
do{
int v=st[top];
col[v]=s,siz[s]++;
vis[s]=0;
}while(st[top--]!=u);
}
}
void solve(int u){
int v=0;
rep(i,1,k){
if(col[i]==u){
v=i;
break;
}
}
assert(v);
queue<int> q;
vis[u]=1,q.push(u);
while(q.size()){
int u=q.front();
q.pop();
ans[col[u]]=1;
go(i,u){
int v=e[i].to;
if(vis[v]){
continue;
}
vis[v]=1,q.push(v);
}
}
int sum=0;
rep(i,1,s){
if(ans[i]){
sum+=i;
}
}
if(sum-siz[u]>=n){
ans[u]=0;
}
}
void Yorushika(){
read(n,m),n*=3;
rep(i,1,n){
ans[i]=0;
}
rep(i,1,n*10){
head[i]=dfn[i]=siz[i]=vis[i]=0;
}
k=n,tot=cur=s=0;
T.build(1,n,1),R.build(1,n,1);
while(m--){
int l,r,x,y;read(l,r,x,y);
k++;
T.update(1,n,1,l,r,k),R.update(1,n,1,x,y,k);
}
rep(i,1,k){
if(!dfn[i]){
tarjan(i);
}
}
int sum=0;
rep(i,1,s){
if(siz[i]>n*2){
puts("NIE");
return;
}
if(siz[i]>=n){
solve(i);
goto END;
}
}
rep(i,1,s){
sum+=siz[i],ans[i]=1;
if(sum>=n){
break;
}
}
END:
puts("TAK");
rep(i,1,n){
pc(ans[i]?'F':'R');
}
puts("");
}
signed main(){
int t=1;
read(t);
while(t--){
Yorushika();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 22024kb
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 FRR NIE
result:
wrong answer odpowiedz nie spelnia wymogow!