QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617120#7689. Flipping CardsPepinotTL 51ms3824kbC++201.1kb2024-10-06 13:58:552024-10-06 13:58:56

Judging History

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

  • [2024-10-06 13:58:56]
  • 评测
  • 测评结果:TL
  • 用时:51ms
  • 内存:3824kb
  • [2024-10-06 13:58:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
void solveTS() {
    int n; cin>>n;
    vector<pii> v(n);
    vector<int> nums;
    for(int i=0; i<n; i++) {
        cin>>v[i].first>>v[i].second;
        nums.push_back(v[i].first);
        nums.push_back(v[i].second);
    }

    sort(nums.begin(),nums.end());
    nums.erase(unique(nums.begin(),nums.end()),nums.end());
    
    int mid_id;

    for(int i=nums.size()-1; i>=0; i--){
        mid_id=i;
        int mid=nums[mid_id];

        int cnt_1=0;
        for(auto [x,y]:v)
            if(x>=mid) cnt_1++;

        int cnt_2=0,maxx=0;
        for(auto [x,y]:v) {
            int type=0;

            if(x<mid&&y>=mid) type=1;
            else if(x>=mid&&y<mid) type=-1;
            cnt_2+=type;
            if(cnt_2>maxx) maxx=cnt_2;
            if(cnt_2<0) cnt_2=0;
        }

        if(cnt_1+maxx>=n/2+1) break;

    }
    cout<<nums[mid_id];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solveTS();
}
/*
5
3 6
5 2
4 7
6 4
2 8

 */

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3476kb

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

99
749159996 323524232
125448341 365892333
481980673 143665393
394405973 44741918
687549448 513811513
287088118 385131171
11865696 666468353
449920567 373650719
671547289 116780561
41003675 671513243
351534153 507850962
374160874 985661954
222519431 600582098
987220654 704142246
856147059 37783620
1...

output:

528957505

result:

ok 1 number(s): "528957505"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

101
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000...

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

103
66 46
41 70
52 76
26 5
54 2
78 21
22 39
100 15
73 94
56 7
45 72
76 80
6 67
12 8
86 53
26 1
5 57
90 44
81 85
2 70
32 79
95 42
97 37
87 93
2 21
21 42
29 25
61 35
98 99
33 46
51 10
45 56
40 75
71 25
79 37
75 10
34 98
1 22
40 12
14 81
83 29
51 12
37 96
74 11
30 49
39 34
68 68
36 17
3 55
41 32
22 92
...

output:

55

result:

ok 1 number(s): "55"

Test #7:

score: 0
Accepted
time: 51ms
memory: 3684kb

input:

5555
884376710 45124731
564350738 110566376
82266416 71890085
742302826 424812817
441684523 786251012
1208704 118200627
206028578 736388312
179371956 412238226
562783304 721943945
855108903 710808533
969831121 89689888
833625410 9559177
39704951 153974475
778740527 562223006
103796470 968790365
2050...

output:

520583648

result:

ok 1 number(s): "520583648"

Test #8:

score: -100
Time Limit Exceeded

input:

55555
407954959 925854335
331922620 685714089
683072900 978458276
462828931 975317170
524480939 832278948
759453127 157033854
246638012 738429531
423955730 483191182
541683890 709827850
309667569 360334083
797868492 960421332
981833589 59185699
53482766 56438082
56804787 566838744
76359614 376208064...

output:


result: