Submission #1026399

# Submission time Handle Problem Language Result Execution time Memory
1026399 2024-07-18T04:43:55 Z Mardonbekhazratov Radio Towers (IOI22_towers) C++17
41 / 100
4000 ms 4960 KB
#include "towers.h"

#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>

using namespace std;

struct SegTree{
    int N;
    vector<int>tree;

    int merge(int a,int b){
        return max(a,b);
    }

    void build(int n){
        N=1;
        while(N<n) N<<=1;
        
        tree.assign(2*N,0);
    }

    void update(int v,int l,int r,int id,int x){
        if(r-l==1){
            tree[v]=x;
            return;
        }
        int mid=(l+r)/2;
        if(id<mid) update(v<<1,l,mid,id,x);
        else update(v<<1|1,mid,r,id,x);
        tree[v]=merge(tree[v<<1],tree[v<<1|1]);
    }

    void update(int id,int x){
        return update(1,0,N,id,x);
    }

    int get(int v,int l,int r,int ql,int qr){
        if(ql>=r || l>=qr) return 0;
        if(l>=ql && qr>=r) return tree[v];

        int mid=(l+r)/2;
        return merge(get(v<<1,l,mid,ql,qr),get(v<<1|1,mid,r,ql,qr));
    }

    int get(int l,int r){
        if(r<=l) return 0;
        return get(1,0,N,l,r);
    }
};

int n,k;
vector<int>h,pref;
bool su1=true;


void init(int N, std::vector<int> H) {
    n=N;
    h=H;
    k=0;
    bool ok=true;
    pref.resize(n);
    pref[0]=0;
    vector<int>last(n);
    for(int i=1;i<n;i++){
        if(h[i]>h[i-1] && ok) k=i;
        else{
            if(h[i]>h[i-1]) su1=false;
            ok=false;
        }
        pref[i]=pref[i-1];
        if(h[i]<h[i-1]){
            if(last[i-1]==1) pref[i]++;
            last[i]=-1;
        }
        else{
            last[i]=1;
        }
    }
}

int max_towers(int L, int R, int D) {
    if(su1){
        if(L<k && R>k && h[k]-D>=h[L] && h[k]-D>=h[R]) return 2;
        return 1;
    }
    if(D==1){
        return pref[R]-pref[min(R,L+1)]+1;
    }
    vector<int>a,dp(R-L+1);
    dp[0]=1;
    for(int i=L;i<=R;i++){
        a.push_back(h[i]);
    }
    
    // map<int,int>mp;
    vector<int>b=a;
    sort(b.begin(),b.end());
    int c=b.size();
    // for(int x:b) m[x]=c++;
    SegTree S1,S2;
    S1.build(c+2);
    S2.build(c+2);
    
    int ans=1,mx=0;
    for(int i=0;i<a.size();i++){
        int pos=lower_bound(b.begin(),b.end(),a[i]+D)-b.begin();
        dp[i]=S2.get(pos,c+2);
        dp[i]++;
        ans=max(ans,dp[i]);
        int pos2=lower_bound(b.begin(),b.end(),a[i])-b.begin();
        S1.update(pos2,dp[i]);
        int pos1=lower_bound(b.begin(),b.end(),a[i]-D+1)-b.begin();
        S2.update(pos2,S1.get(0,pos1));
        // cout<<dp[i]<<' ';
    }
    return ans;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
towers.cpp:108:15: warning: unused variable 'mx' [-Wunused-variable]
  108 |     int ans=1,mx=0;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 293 ms 1368 KB Output is correct
2 Correct 652 ms 2392 KB Output is correct
3 Correct 619 ms 2392 KB Output is correct
4 Correct 634 ms 2392 KB Output is correct
5 Correct 570 ms 2392 KB Output is correct
6 Correct 613 ms 2392 KB Output is correct
7 Correct 591 ms 2392 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 23 ms 1880 KB Output is correct
37 Correct 33 ms 3144 KB Output is correct
38 Correct 17 ms 2392 KB Output is correct
39 Correct 23 ms 2392 KB Output is correct
40 Correct 16 ms 2392 KB Output is correct
41 Correct 67 ms 4680 KB Output is correct
42 Correct 10 ms 2392 KB Output is correct
43 Correct 9 ms 2216 KB Output is correct
44 Correct 8 ms 2392 KB Output is correct
45 Correct 17 ms 2368 KB Output is correct
46 Correct 9 ms 2392 KB Output is correct
47 Correct 10 ms 2220 KB Output is correct
48 Correct 9 ms 2392 KB Output is correct
49 Correct 15 ms 2340 KB Output is correct
50 Correct 8 ms 2392 KB Output is correct
51 Correct 9 ms 2392 KB Output is correct
52 Correct 9 ms 2368 KB Output is correct
53 Correct 9 ms 2364 KB Output is correct
54 Correct 9 ms 2392 KB Output is correct
55 Correct 8 ms 2392 KB Output is correct
56 Correct 16 ms 2392 KB Output is correct
57 Correct 70 ms 4704 KB Output is correct
58 Correct 83 ms 4936 KB Output is correct
59 Correct 89 ms 4960 KB Output is correct
60 Correct 96 ms 4936 KB Output is correct
61 Correct 98 ms 4956 KB Output is correct
62 Correct 80 ms 4936 KB Output is correct
63 Correct 88 ms 4936 KB Output is correct
64 Correct 9 ms 2392 KB Output is correct
65 Correct 8 ms 2392 KB Output is correct
66 Correct 54 ms 4928 KB Output is correct
67 Correct 49 ms 4936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 2136 KB Output is correct
2 Correct 575 ms 2392 KB Output is correct
3 Correct 626 ms 2392 KB Output is correct
4 Correct 583 ms 2392 KB Output is correct
5 Correct 556 ms 2392 KB Output is correct
6 Correct 595 ms 2392 KB Output is correct
7 Correct 616 ms 2392 KB Output is correct
8 Correct 603 ms 2392 KB Output is correct
9 Correct 652 ms 2392 KB Output is correct
10 Correct 656 ms 2392 KB Output is correct
11 Correct 565 ms 2392 KB Output is correct
12 Correct 598 ms 2392 KB Output is correct
13 Correct 575 ms 2392 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 17 ms 2392 KB Output is correct
18 Correct 12 ms 2392 KB Output is correct
19 Correct 13 ms 2364 KB Output is correct
20 Correct 9 ms 2392 KB Output is correct
21 Correct 9 ms 2392 KB Output is correct
22 Correct 9 ms 2392 KB Output is correct
23 Correct 9 ms 2368 KB Output is correct
24 Correct 9 ms 2392 KB Output is correct
25 Correct 9 ms 2392 KB Output is correct
26 Correct 16 ms 2392 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 1932 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 23 ms 1880 KB Output is correct
37 Correct 33 ms 3144 KB Output is correct
38 Correct 17 ms 2392 KB Output is correct
39 Correct 23 ms 2392 KB Output is correct
40 Correct 16 ms 2392 KB Output is correct
41 Correct 67 ms 4680 KB Output is correct
42 Correct 10 ms 2392 KB Output is correct
43 Correct 9 ms 2216 KB Output is correct
44 Correct 8 ms 2392 KB Output is correct
45 Correct 17 ms 2368 KB Output is correct
46 Correct 9 ms 2392 KB Output is correct
47 Correct 10 ms 2220 KB Output is correct
48 Correct 9 ms 2392 KB Output is correct
49 Correct 15 ms 2340 KB Output is correct
50 Correct 8 ms 2392 KB Output is correct
51 Correct 9 ms 2392 KB Output is correct
52 Correct 9 ms 2368 KB Output is correct
53 Correct 9 ms 2364 KB Output is correct
54 Correct 9 ms 2392 KB Output is correct
55 Correct 8 ms 2392 KB Output is correct
56 Correct 16 ms 2392 KB Output is correct
57 Correct 70 ms 4704 KB Output is correct
58 Correct 83 ms 4936 KB Output is correct
59 Correct 89 ms 4960 KB Output is correct
60 Correct 96 ms 4936 KB Output is correct
61 Correct 98 ms 4956 KB Output is correct
62 Correct 80 ms 4936 KB Output is correct
63 Correct 88 ms 4936 KB Output is correct
64 Correct 9 ms 2392 KB Output is correct
65 Correct 8 ms 2392 KB Output is correct
66 Correct 54 ms 4928 KB Output is correct
67 Correct 49 ms 4936 KB Output is correct
68 Correct 430 ms 2136 KB Output is correct
69 Correct 575 ms 2392 KB Output is correct
70 Correct 626 ms 2392 KB Output is correct
71 Correct 583 ms 2392 KB Output is correct
72 Correct 556 ms 2392 KB Output is correct
73 Correct 595 ms 2392 KB Output is correct
74 Correct 616 ms 2392 KB Output is correct
75 Correct 603 ms 2392 KB Output is correct
76 Correct 652 ms 2392 KB Output is correct
77 Correct 656 ms 2392 KB Output is correct
78 Correct 565 ms 2392 KB Output is correct
79 Correct 598 ms 2392 KB Output is correct
80 Correct 575 ms 2392 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 17 ms 2392 KB Output is correct
85 Correct 12 ms 2392 KB Output is correct
86 Correct 13 ms 2364 KB Output is correct
87 Correct 9 ms 2392 KB Output is correct
88 Correct 9 ms 2392 KB Output is correct
89 Correct 9 ms 2392 KB Output is correct
90 Correct 9 ms 2368 KB Output is correct
91 Correct 9 ms 2392 KB Output is correct
92 Correct 9 ms 2392 KB Output is correct
93 Correct 16 ms 2392 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 0 ms 344 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 0 ms 344 KB Output is correct
100 Correct 0 ms 344 KB Output is correct
101 Correct 1 ms 344 KB Output is correct
102 Correct 0 ms 344 KB Output is correct
103 Correct 1 ms 344 KB Output is correct
104 Execution timed out 4038 ms 4880 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 293 ms 1368 KB Output is correct
2 Correct 652 ms 2392 KB Output is correct
3 Correct 619 ms 2392 KB Output is correct
4 Correct 634 ms 2392 KB Output is correct
5 Correct 570 ms 2392 KB Output is correct
6 Correct 613 ms 2392 KB Output is correct
7 Correct 591 ms 2392 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 356 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 2 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 2 ms 344 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 23 ms 1880 KB Output is correct
47 Correct 33 ms 3144 KB Output is correct
48 Correct 17 ms 2392 KB Output is correct
49 Correct 23 ms 2392 KB Output is correct
50 Correct 16 ms 2392 KB Output is correct
51 Correct 67 ms 4680 KB Output is correct
52 Correct 10 ms 2392 KB Output is correct
53 Correct 9 ms 2216 KB Output is correct
54 Correct 8 ms 2392 KB Output is correct
55 Correct 17 ms 2368 KB Output is correct
56 Correct 9 ms 2392 KB Output is correct
57 Correct 10 ms 2220 KB Output is correct
58 Correct 9 ms 2392 KB Output is correct
59 Correct 15 ms 2340 KB Output is correct
60 Correct 8 ms 2392 KB Output is correct
61 Correct 9 ms 2392 KB Output is correct
62 Correct 9 ms 2368 KB Output is correct
63 Correct 9 ms 2364 KB Output is correct
64 Correct 9 ms 2392 KB Output is correct
65 Correct 8 ms 2392 KB Output is correct
66 Correct 16 ms 2392 KB Output is correct
67 Correct 70 ms 4704 KB Output is correct
68 Correct 83 ms 4936 KB Output is correct
69 Correct 89 ms 4960 KB Output is correct
70 Correct 96 ms 4936 KB Output is correct
71 Correct 98 ms 4956 KB Output is correct
72 Correct 80 ms 4936 KB Output is correct
73 Correct 88 ms 4936 KB Output is correct
74 Correct 9 ms 2392 KB Output is correct
75 Correct 8 ms 2392 KB Output is correct
76 Correct 54 ms 4928 KB Output is correct
77 Correct 49 ms 4936 KB Output is correct
78 Correct 430 ms 2136 KB Output is correct
79 Correct 575 ms 2392 KB Output is correct
80 Correct 626 ms 2392 KB Output is correct
81 Correct 583 ms 2392 KB Output is correct
82 Correct 556 ms 2392 KB Output is correct
83 Correct 595 ms 2392 KB Output is correct
84 Correct 616 ms 2392 KB Output is correct
85 Correct 603 ms 2392 KB Output is correct
86 Correct 652 ms 2392 KB Output is correct
87 Correct 656 ms 2392 KB Output is correct
88 Correct 565 ms 2392 KB Output is correct
89 Correct 598 ms 2392 KB Output is correct
90 Correct 575 ms 2392 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 0 ms 344 KB Output is correct
93 Correct 0 ms 344 KB Output is correct
94 Correct 17 ms 2392 KB Output is correct
95 Correct 12 ms 2392 KB Output is correct
96 Correct 13 ms 2364 KB Output is correct
97 Correct 9 ms 2392 KB Output is correct
98 Correct 9 ms 2392 KB Output is correct
99 Correct 9 ms 2392 KB Output is correct
100 Correct 9 ms 2368 KB Output is correct
101 Correct 9 ms 2392 KB Output is correct
102 Correct 9 ms 2392 KB Output is correct
103 Correct 16 ms 2392 KB Output is correct
104 Correct 0 ms 344 KB Output is correct
105 Correct 0 ms 344 KB Output is correct
106 Correct 0 ms 344 KB Output is correct
107 Correct 0 ms 344 KB Output is correct
108 Correct 1 ms 344 KB Output is correct
109 Correct 0 ms 344 KB Output is correct
110 Correct 0 ms 344 KB Output is correct
111 Correct 1 ms 344 KB Output is correct
112 Correct 0 ms 344 KB Output is correct
113 Correct 1 ms 344 KB Output is correct
114 Execution timed out 4059 ms 1932 KB Time limit exceeded
115 Halted 0 ms 0 KB -