QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618089#2266. Colorful Rectangleucup-team4153WA 2ms12052kbC++143.2kb2024-10-06 18:37:542024-10-06 18:37:55

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 18:37:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12052kb
  • [2024-10-06 18:37:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
const int inf=0x3f3f3f3f;
struct BIT{
    int n;
    int sum[N];
    void init(int _n){
        n=_n;
        for(int i=1;i<=n;i++)sum[i]=inf;
    }
    int low_bit(int x){
        return x&(-x);
    }
    void update(int pos,int v){
        for(int i=pos;i<=n;i+=low_bit(i))sum[i]=min(sum[i],v);
    }
    int query(int pos){
        int ans=inf;
        for(int i=pos;i>0;i-=low_bit(i))ans=min(ans,sum[i]);
        return ans;
    }
}T[2];
struct info{
    int res[3];
    info(int x=inf,int y=inf,int z=inf){
        res[0]=x;res[1]=y;res[2]=z;
    }
};
info operator +(const info &o1,const info &o2){
    info ans;
    ans.res[0]=min(o1.res[0],o2.res[0]);
    ans.res[1]=min(o1.res[1],o2.res[1]);
    ans.res[2]=min({o1.res[2],o2.res[2],o1.res[0]+o2.res[1]});
    return ans;
}
struct node{
    int l,r;
    info v;
}Tree[N<<2];
void push_down(int k){
    Tree[k<<1].v=Tree[k<<1].v+Tree[k].v;
    Tree[k<<1|1].v=Tree[k<<1|1].v+Tree[k].v;
    Tree[k].v=info();
}
void build(int k,int l,int r){
    Tree[k].l=l;Tree[k].r=r;Tree[k].v=info();
    if(l==r)return;
    int mid=(l+r)>>1;
    build(k<<1,l,mid);
    build(k<<1|1,mid+1,r);
}
void update(int k,int l,int r,info v){
    if(Tree[k].l>=l&&Tree[k].r<=r){
        Tree[k].v=Tree[k].v+v;return;
    }
    int mid=(Tree[k].l+Tree[k].r)>>1;
    push_down(k);
    if(l<=mid)update(k<<1,l,r,v);
    if(r>mid)update(k<<1|1,l,r,v);
}
int query(int k,int pos){
    if(Tree[k].l==Tree[k].r)return Tree[k].v.res[2];
    int mid=(Tree[k].l+Tree[k].r)>>1;
    push_down(k);
    if(pos<=mid)return query(k<<1,pos);
    return query(k<<1|1,pos);
}
int n;
int C[N];
struct P{
    int x,y,c;
    bool operator <(const P &o)const{
        if(x==o.x)return c<o.c;
        return x<o.x;
    }
};
vector<P>p;
int get(int x,vector<int>&v){
    return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
int solve(){
    int ans=inf;
    vector<int>v;
    for(auto [x,y,c]:p)v.push_back(y);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    int siz=v.size();
    sort(p.begin(),p.end());
    T[0].init(siz);T[1].init(siz);
    for(auto [x,y,c]:p){
        int pos=get(y,v);
        if(c==0)T[0].update(pos,-x-y);
        else if(c==1)T[1].update(pos,T[0].query(pos));
        else ans=min(ans,x+y+T[1].query(pos));
    }
    build(1,1,siz);
    for(auto [x,y,c]:p){
        int pos=get(y,v);
        if(c==0)update(1,pos,siz,info(-x-y,inf,inf));
        else if(c==1)update(1,1,pos,info(inf,y,inf));
        else ans=min(ans,x+query(1,pos));
    }
    return ans;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;p.resize(n);
    for(auto &[x,y,c]:p)cin>>x>>y>>c;
    for(int i=0;i<n;i++)C[i]=p[i].c;
    vector<int>rc(3);
    for(int i=0;i<3;i++)rc[i]=i;
    int ans=inf;
    do{
        for(int i=0;i<n;i++)p[i].c=rc[C[i]];
        for(int i=0;i<4;i++){
            ans=min(ans,solve());
            for(auto &[x,y,c]:p){
                swap(x,y);
                x=-x;
            }
        }
    }while(next_permutation(rc.begin(),rc.end()));
    cout<<ans*2<<"\n";
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 12052kb

input:

10
9991473 83825681 1
26476526 51616963 1
50765942 43355004 0
53028333 5604344 2
57100206 5782798 0
80628150 92688632 2
82964896 73929713 2
85102330 11439534 1
86076990 82286008 0
89626190 52420216 0

output:

98532912

result:

wrong answer 1st lines differ - expected: '75818374', found: '98532912'