QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240857#7105. Pixel Artucup-team2307#AC ✓336ms17924kbC++202.5kb2023-11-05 20:18:072023-11-05 20:18:07

Judging History

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

  • [2023-11-05 20:18:07]
  • 评测
  • 测评结果:AC
  • 用时:336ms
  • 内存:17924kb
  • [2023-11-05 20:18:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll

const int N=1e5+100;

int u[N],d[N];
vector<int> start[N],stop[N];

int comps;
int par[N];

void init(int v)
{
//    cout<<"init "<<v<<"\n";
    par[v]=v;
    comps++;
}

int dsu(int v)
{
    return par[v]==v?v:par[v]=dsu(par[v]);
}

void un(int u,int v)
{
//    cout<<"un "<<u<<" "<<v<<"\n";
    u=dsu(u);
    v=dsu(v);
    if(u==v)
        return;
    comps--;
    if(rand()%2)
        par[u]=v;
    else
        par[v]=u;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin>>T;
    while(T--)
    {
        int n,m,k;
        cin>>m>>n>>k;
        for(int i=1;i<=m;i++)
            start[i].clear(),
            stop[i].clear();
        for(int i=1;i<=k;i++)
        {
            int l,r;
            cin>>l>>u[i]>>r>>d[i];
            start[l].push_back(i);
            stop[r].push_back(i);
        }
        set<tuple<int,int,int>> segs;
//        cout<<"testcase\n";
        comps=0;
        int sum=0,cur=0;
        for(int i=1;i<=m;i++)
        {
//            cout<<"i="<<i<<"\n";
            set<tuple<int,int,int>> del;
            for(int j:stop[i-1])
            {
                segs.erase({u[j],d[j],j});
                del.emplace(u[j],d[j],j);
                cur-=d[j]-u[j]+1;
            }
            for(int j:start[i])
            {
                cur+=d[j]-u[j]+1;
                init(j);
                int U=u[j],D=d[j];
                auto it=del.lower_bound({U,-1,-1});
                if(it!=del.begin())
                    it--;
                for(;it!=del.end();it++)
                {
                    auto[UU,DD,jj]=*it;
                    if(DD<U)
                        continue;
                    if(UU>D)
                        break;
                    un(j,jj);
                }
                it=segs.lower_bound({U,-1,-1});
                if(it!=segs.end())
                {
                    auto[UU,DD,jj]=*it;
                    if(UU==D+1)
                        un(j,jj);
                }
                if(it!=segs.begin())
                {
                    it--;
                    auto[UU,DD,jj]=*it;
                    if(U==DD+1)
                        un(j,jj);
                }
                segs.insert({U,D,j});
            }
            sum+=cur;
            cout<<sum<<" "<<comps<<"\n";
        }
    }
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

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: 0
Accepted
time: 336ms
memory: 17924kb

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:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed