QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159255#7105. Pixel Artucup-team198#WA 625ms12644kbC++234.7kb2023-09-02 17:41:562023-09-02 17:41:57

Judging History

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

  • [2023-09-02 17:41:57]
  • 评测
  • 测评结果:WA
  • 用时:625ms
  • 内存:12644kb
  • [2023-09-02 17:41:56]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <tuple>
#include <map>
#include <set>
using namespace std;
constexpr int N=1e5+10;

// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#include <heltim7/debug>
#else
#define debug(...) 7
#endif

#define endl '\n'

struct DSU {
    vector<int> fa;
    
    int find(int x) {
        return x==fa[x]?x:fa[x]=find(fa[x]);
    }

    bool join(int x,int y) {
        x=find(x);
        y=find(y);
        if(x==y) return false;
        fa[y]=x;
        return true;
    }

    void init(int n) {
        fa.resize(n+1);
        iota(fa.begin(),fa.end(),0);
    }
};

struct SegSet {
    struct Seg
    {
        int l;
        mutable int r,p;
        bool operator<(const Seg &x) const {
            return l<x.l;
        }
        friend ostream &operator<<(ostream &os,const Seg &x) {
            return os<<"["<<x.l<<"->"<<x.r<<"="<<x.p<<"]";
        }
    };
    DSU dsu;
    set<int> dif;
    set<Seg> st;
    
    void insert(int l,int r,int p) {
        auto lit=--st.upper_bound({l-1});
        auto rit=--st.upper_bound({r+1});
        if(lit->r<l-1) lit++;
        int mnl=l,mxr=r;
        if(lit->r>=l-1&&rit->l<=r+1) {
            mnl=min(mnl,lit->l);
            mxr=max(mxr,rit->r);
            rit++;
            while(lit!=rit) {
                int fa=dsu.find(lit->p);
                dsu.join(p,fa);
                dif.erase(fa);
                dif.insert(p);
                lit=st.erase(lit);
            }
        }
        dif.insert(p);
        st.emplace(mnl,mxr,p);
    }

    auto split(int pos) {
        auto it=st.lower_bound({pos});
        if(it->l==pos) return it;
        it--;
        auto [l,r,fa]=*it;
        st.erase(it);
        st.emplace(l,pos-1,fa);
        return st.emplace(pos,r,fa).first;
    }

    void erase(int l,int r) {
        auto it=split(l);
        auto [L,R,fa]=*it;
        st.erase(it);
        if(r<R) st.emplace(r+1,R,fa);
    }

    SegSet(int n) {
        dsu.init(n);
        st.emplace(-1,-1,-1);
        st.emplace(N,N,N);
    }
};

void solve() {
    int n,m,k;
    cin>>n>>m>>k;
    
    vector<int> s(n+2);
    using T=tuple<bool,int,int,int>;
    auto vec=vector(n+2,vector<T>());
    for(int i=1;i<=k;i++) {
        int r1,r2,c1,c2;
        cin>>r1>>c1>>r2>>c2;
        if(r1==r2) {
            vec[r1].emplace_back(1,c1,c2,i);
            vec[r1+1].emplace_back(0,c1,c2,i);
            s[r1]+=c2-c1+1;
            s[r2+1]-=c2-c1+1;
        }
        else {
            vec[r1].emplace_back(1,c1,c1,i);
            vec[r2+1].emplace_back(0,c1,c1,i);
            s[r1]++;
            s[r2+1]--;
        }
    }
    
    for(int i=1;i<=n;i++) s[i]+=s[i-1];
    for(int i=1;i<=n;i++) s[i]+=s[i-1];

    auto format=[&](vector<T> &v) {
        vector<int> num(1,-1);
        for(auto [add,l,r,id]:v) {
            num.emplace_back(l);
            num.emplace_back(r);
            num.emplace_back(l-1);
            num.emplace_back(r+1);
        }
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        auto get=[&](int x) {
            return lower_bound(num.begin(),num.end(),x)-num.begin();
        };
        int n=num.size();
        vector<int> sign(n+2),vid(n+2);
        for(auto [add,l,r,id]:v) {
            l=get(l),r=get(r);
            if(add) {
                sign[l]+=2;
                sign[r+1]-=2;
            }
            else {
                sign[l]--;
                sign[r+1]++;
            }
            for(int i=l;i<=r;i++) vid[i]=id;
        }
        partial_sum(sign.begin(),sign.end(),sign.begin());

        vector<T> res;
        for(int i=1,last=i;i<sign.size();i++) {
            if(sign[i]!=sign[last]) {
                if(sign[last]) {
                    res.emplace_back(sign[last]>0?1:0,num[last],num[i-1],vid[last]);
                }
                last=i;
            }
        }
        v=res;
        sort(v.begin(),v.end());
    };

    for(int i=1;i<=n;i++) if(vec[i].size()) format(vec[i]);

    SegSet st(k);
    for(int i=1;i<=n;i++) {
        if(vec[i].size()) {
            for(auto [add,l,r,id]:vec[i]) {
                if(add) {
                    st.insert(l,r,id);
                }
                else {
                    st.erase(l,r);
                }
            }
            debug(st.st);
            debug(st.dif);
        }
        cout<<s[i]<<' '<<st.dif.size()<<endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3576kb

input:

3
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 625ms
memory: 12644kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

wrong answer 10239th lines differ - expected: '109 5', found: '109 6'