QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778527#3873. TowersNangu5 16ms52740kbC++144.0kb2024-11-24 15:04:142024-11-24 15:04:15

Judging History

This is the latest submission verdict.

  • [2024-11-24 15:04:15]
  • Judged
  • Verdict: 5
  • Time: 16ms
  • Memory: 52740kb
  • [2024-11-24 15:04:14]
  • Submitted

answer

#include<bits/stdc++.h>
#define rep(i, j, k) for(int i=(j); i<=(k); ++i)
#define per(i, j, k) for(int i=(j); i>=(k); --i)
#define siz(x) (int)x.size()
#define ck
using namespace std;
namespace DEBUG{
    template<class T>
    void _debug(const char *s, T x){ cout<<s<<'='<<x<<'\n'; }
    template<class T, class... T2>
    void _debug(const char *s, T x, T2... nxt){
        while(*s!=',') cout<<*s++;
        cout<<'='<<x<<',';
        _debug(s+1, nxt...);
    }
    #ifdef ck
    #define debug(...) 0
    #else
    #define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
    #endif
} using namespace DEBUG;
using pa=pair<int, int>;
const int N=1e6+7;
int n, maxn, hl[N], hr[N], up[N], down[N], ans[N];
vector<int> p[N];
pair<pa, int> z[N];
void clear(int r){hl[r]=hr[r]=-1;}
void get(int c){if(down[c]<up[c]) swap(down[c], up[c]);}
//down>up
void upd(int r){
    if(r==-1) return;
    int &x=hl[r], &y=hr[r];
    auto &p=::p[r];
    if(x==-1 && y==-1) return;
    while(x<=y && up[p[x]]<r && r<down[p[x]]) ++x;
    while(x<=y && up[p[y]]<r && r<down[p[y]]) --y;
    if(x>y) return clear(r);
    int d1=0, d2=0;
    if(up[p[x]]!=r && down[p[x]]!=r){
        if(up[p[x]]==-1) up[p[x]]=r, get(p[x]);
        else if(down[p[x]]==-1) down[p[x]]=r, get(p[x]);
        else{
            if(r<up[p[x]]){
                int tmp=up[p[x]];
                up[p[x]]=r;
                d1=tmp;
            } else{
                int tmp=down[p[x]];
                down[p[x]]=r;
                d1=tmp;
            }
        }
    } 
    if(up[p[y]]!=r && down[p[y]]!=r){
        if(up[p[y]]==-1) up[p[y]]=r, get(p[y]);
        else if(down[p[y]]==-1) down[p[y]]=r, get(p[y]);
        else{
            if(r<up[p[y]]){
                int tmp=up[p[y]];
                up[p[y]]=r;
                d2=tmp;
            } else{
                int tmp=down[p[y]];
                down[p[y]]=r;
                d2=tmp;
            }
        }
    }
    if(d1) upd(d1);
    if(d2 && d1!=d2) upd(d2);
}

int check(int l, int mid, int r){
    return l<mid && mid<r || r<mid && mid<l;
}

bool check(pa l, pa mid, pa r){
    bool res=0;
    if(l.first==mid.first && mid.first==r.first)
        res|=check(l.second, mid.second, r.second);
    if(l.second==mid.second && mid.second==r.second);
        res|=check(l.first, mid.first, r.first);
    return res;
}

void check(){
    static pa p[N];
    rep(i, 1, n) p[z[i].second]=z[i].first;
    static int cnt[N];
    rep(i, 1, n) if(ans[i]) ++cnt[p[i].first];
    rep(i, 1, maxn) assert(cnt[i]<=2);
    memset(cnt, 0, sizeof cnt);
    rep(i, 1, n) if(ans[i]) ++cnt[p[i].second];
    rep(i, 1, maxn) assert(cnt[i]<=2);
    rep(i, 1, n){
        if(ans[i]) continue;
        bool flag=0;
        rep(j, 1, n) rep(k, 1, n) if(ans[j] && ans[k]){
            if(check(p[j], p[i], p[k])){
                flag=1;
                break;
            }
        }
        assert(flag);
    }
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    rep(i, 1, n){
        int x, y;
        cin>>x>>y;
        z[i]=make_pair(pa(x, y), i);
        maxn=max({maxn, x, y});
        p[x].emplace_back(y);
    }
    rep(i, 1, maxn) sort(p[i].begin(), p[i].end());
    memset(hl, -1, sizeof hl);
    memset(hr, -1, sizeof hr);
    memset(down, -1, sizeof down);
    memset(up, -1, sizeof up);
    rep(i, 1, maxn){
        if(siz(p[i])==0) continue;
        hl[i]=0, hr[i]=siz(p[i])-1;
        upd(i);
    }
    sort(z+1, z+n+1);
    rep(i, 1, maxn){
        pa x;
        if(hl[i]!=-1){
            x=pa(i, p[i][hl[i]]);
            debug(x.first, x.second);
            int pos=lower_bound(z+1, z+n+1, make_pair(x, 0))-z;
            ans[z[pos].second]=1;
        } if(hr[i]!=-1 && hr[i]!=hl[i]){
            x=pa(i, p[i][hr[i]]);
            debug(x.first, x.second);
            int pos=lower_bound(z+1, z+n+1, make_pair(x, 0))-z;
            ans[z[pos].second]=1;
        }
    }
    check();
    rep(i, 1, n) cout<<ans[i];
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 11ms
memory: 50772kb

input:

2
869400 218695
664808 31410

output:

11

result:

ok 

Test #2:

score: 5
Accepted
time: 6ms
memory: 50704kb

input:

2
195447 154323
271823 133730

output:

11

result:

ok 

Test #3:

score: 5
Accepted
time: 9ms
memory: 50692kb

input:

3
751594 545975
951568 859051
621150 686048

output:

111

result:

ok 

Test #4:

score: 5
Accepted
time: 3ms
memory: 50736kb

input:

3
404592 259430
770816 43371
147329 582162

output:

111

result:

ok 

Test #5:

score: 5
Accepted
time: 12ms
memory: 50636kb

input:

3
401670 296316
401670 809250
401670 595959

output:

110

result:

ok 

Test #6:

score: 5
Accepted
time: 8ms
memory: 50732kb

input:

3
657802 927690
657802 872623
657802 83083

output:

101

result:

ok 

Test #7:

score: 5
Accepted
time: 12ms
memory: 50692kb

input:

3
759291 185618
759291 386687
759291 100713

output:

011

result:

ok 

Test #8:

score: 5
Accepted
time: 11ms
memory: 48656kb

input:

3
997737 106763
684497 106763
412296 106763

output:

101

result:

ok 

Test #9:

score: 5
Accepted
time: 7ms
memory: 48684kb

input:

3
305388 642835
538743 642835
608034 642835

output:

101

result:

ok 

Test #10:

score: 5
Accepted
time: 0ms
memory: 50700kb

input:

3
420692 202248
784725 202248
931773 202248

output:

101

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #11:

score: 11
Accepted
time: 8ms
memory: 52704kb

input:

16
296455 404592
582162 770816
807435 536085
259430 536085
112538 770816
610915 369095
582162 369095
94860 147329
112538 147329
296455 61932
259430 147329
807435 369095
610915 404592
807435 309191
807435 61932
94860 770816

output:

1111011101101011

result:

ok 

Test #12:

score: 11
Accepted
time: 13ms
memory: 52740kb

input:

16
561476 595959
58474 595959
58474 664431
105001 143086
809250 250085
58474 250085
789588 281386
350332 161786
789588 250085
561476 281386
296316 401670
296316 250085
350332 595959
296316 161786
350332 281386
58474 281386

output:

1011111101101100

result:

ok 

Test #13:

score: 11
Accepted
time: 12ms
memory: 50640kb

input:

16
316904 170612
433799 125553
316904 125553
859728 341680
433799 32398
872623 388831
859728 83083
872623 83083
584763 388831
148042 861814
316904 861814
927690 861814
148042 83083
148042 32398
584763 657802
905375 388831

output:

1111101111010111

result:

ok 

Test #14:

score: 11
Accepted
time: 16ms
memory: 50648kb

input:

16
386687 759291
995919 169567
788489 197826
185618 713079
198743 100713
995919 372561
916765 169567
185618 763504
386687 169567
832084 763504
832084 759291
386687 292594
185618 197826
386687 197826
832084 197826
916765 759291

output:

1100110111001011

result:

ok 

Test #15:

score: 11
Accepted
time: 4ms
memory: 50660kb

input:

16
716236 20497
587980 648488
587980 642779
412708 997737
369271 642779
106763 71182
412708 642779
173374 869560
684497 648488
587980 945118
106763 648488
716236 412296
587980 71182
412708 869560
369271 869560
412708 412296

output:

1001110111111011

result:

ok 

Test #16:

score: 11
Accepted
time: 7ms
memory: 50728kb

input:

16
642835 173421
512014 309394
610395 518804
538743 305388
493101 608034
610395 85927
214511 309394
512014 173421
214511 608034
493101 85927
512014 85927
538743 309394
538743 608034
512014 518804
610395 309394
214511 518804

output:

1011011111001100

result:

ok 

Test #17:

score: 11
Accepted
time: 6ms
memory: 50768kb

input:

16
327159 848430
202248 689260
248917 848430
860732 109812
810547 931773
248917 551698
248917 109812
327159 109812
202248 420692
784725 848430
810547 109812
860732 551698
860732 848430
784725 109812
810547 689260
810547 551698

output:

0111101010001001

result:

ok 

Test #18:

score: 11
Accepted
time: 7ms
memory: 50704kb

input:

16
929868 357006
544399 533307
65980 485996
679846 756501
679846 533307
679846 712386
888311 756501
679846 357006
569069 357006
679846 326645
65980 712386
569069 756501
544399 357006
929868 712386
929868 326645
888311 357006

output:

0110101001111111

result:

ok 

Test #19:

score: 11
Accepted
time: 12ms
memory: 48720kb

input:

16
819172 856879
310900 856879
110339 25925
110339 712188
110339 856879
193758 568642
110339 518110
334829 712188
819172 25925
334829 518110
962527 856879
962527 712188
819172 568642
193758 712188
819172 518110
193758 856879

output:

0010110011111100

result:

ok 

Test #20:

score: 11
Accepted
time: 16ms
memory: 50688kb

input:

16
788180 40074
788180 353457
642341 40074
919317 353457
642341 341228
139346 808233
788180 889183
919317 40074
87340 808233
788180 341228
139346 32374
919317 808233
919317 341228
753883 32374
87340 32374
919317 32374

output:

1010101010010011

result:

ok 

Test #21:

score: 0
Wrong Answer
time: 6ms
memory: 50640kb

input:

16
965515 596717
798876 887533
800289 573487
798876 325675
798876 596717
965515 760793
800289 887533
800289 760793
798876 573487
965515 887533
681117 596717
965515 573487
48193 325675
965515 325675
798876 760793
681117 325675

output:

0110100101101100

result:

wrong answer 

Subtask #3:

score: 0
Time Limit Exceeded

Test #26:

score: 0
Time Limit Exceeded

input:

92690
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #38:

score: 0
Time Limit Exceeded

input:

1000000
1 18543
4 40327
7 19084
8 44274
10 42366
12 22173
13 9862
15 44706
19 48070
21 13389
24 39273
26 18680
27 46858
28 46126
32 27753
34 28289
36 12220
38 39235
42 28505
45 47348
46 34220
48 47551
50 49156
54 8856
55 25515
56 21932
58 24482
59 20686
61 41381
66 30112
67 44504
70 24510
71 26418
7...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Time Limit Exceeded

Test #85:

score: 0
Time Limit Exceeded

input:

1000000
1 602300
1 778881
2 397065
3 291452
3 678039
5 235300
6 499367
8 8597
10 327718
10 516489
12 416542
12 440048
13 284169
13 383581
13 642202
13 770858
14 378154
14 710033
15 905531
16 50155
17 142259
19 395613
19 500321
20 358934
21 461772
24 562953
24 995887
25 421244
27 900412
29 301006
31 ...

output:


result: