QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#158199#7105. Pixel Artucup-team206#AC ✓517ms31544kbC++142.5kb2023-09-02 16:18:322023-09-04 04:30:32

Judging History

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

  • [2023-09-04 04:30:32]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:517ms
  • 内存:31544kb
  • [2023-09-02 16:18:32]
  • 评测
  • 测评结果:100
  • 用时:580ms
  • 内存:31448kb
  • [2023-09-02 16:18:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef long long ll;
const int N=1e5+50;
unordered_map<int,set<pair<pair<int,int>,int>>> A,B;
int qry(int x,int y) {
    if(A.count(x)) {
        auto it=A[x].upper_bound({{y,1e9},0});
        if(it!=A[x].begin()) {
            --it;
            if((it->first).second>=y) return it->second;
        }
    }
    if(B.count(y)) {
        auto it=B[y].upper_bound({{x,1e9},0});
        if(it!=B[y].begin()) {
            --it;
            if((it->first).second>=x) return it->second;
        }
    }
    return 0;
}
vector<pair<int,int>> a[N];
vector<int> b[N];

int X1[N],Y1[N],X2[N],Y2[N];
ll sum[N];
int Fa[N];
int Find(int x) {
    return Fa[x]==x?x:Fa[x]=Find(Fa[x]);
}
void solve() {
    int n,m,K;
    // n=m=K=1e5;
    cin >> n >> m >> K;
    A.clear();
    B.clear();
    FOR(i,0,n+1) sum[i]=0;
    FOR(i,0,n+1) a[i].clear();
    FOR(i,0,n+1) b[i].clear();
    FOR(i,1,K) {
        int x1,y1,x2,y2;
        // x1=x2=rand()%n+1,y1=rand()%m+1,y2=rand()%m+1;
        // if(y1>y2) swap(y1,y2);
        cin >> x1 >> y1 >> x2 >> y2;
        b[x1].push_back(i);
        X1[i]=x1,Y1[i]=y1,X2[i]=x2,Y2[i]=y2;
        if(x1==x2) {
            A[x1].insert({{y1,y2},i});
            sum[x1]+=y2-y1+1;
            sum[x1+1]-=y2-y1+1;
        } else {
            B[y1].insert({{x1,x2},i});
            sum[x1]++;
            sum[x2+1]--;
        }
    }
    FOR(i,1,K) {
        int x=X1[i],y=Y1[i];
        for(auto j: {qry(x-1,y),qry(x,y-1),qry(x,y+1)}) {
            if(j) a[x].push_back({i,j});
        }
        for(auto j: {qry(x+1,y)}) {
            if(j) a[x+1].push_back({i,j});
        }
        x=X2[i],y=Y2[i];
        for(auto j: {qry(x-1,y),qry(x,y-1),qry(x,y+1)}) {
            if(j) a[x].push_back({i,j});
        }
        for(auto j: {qry(x+1,y)}) {
            if(j) a[x+1].push_back({i,j});
        }
    }
    FOR(i,1,K) Fa[i]=i;
    ll s=0,ss=0;
    int r=0;
    FOR(i,1,n) {
        r+=b[i].size();
        for(auto [u,v]: a[i]) {
            if(Find(u)!=Find(v)) {
                --r;
                Fa[Find(u)]=Find(v);
            }
        }
        s+=sum[i];
        ss+=s;
        cout << ss << ' ' << r << '\n';
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=5;
    cin >> T;
    while(T--) solve();
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9952kb

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: 517ms
memory: 31544kb

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