Submission #788769

# Submission time Handle Problem Language Result Execution time Memory
788769 2023-07-20T15:00:51 Z mosiashvililuka Radio Towers (IOI22_towers) C++17
56 / 100
1103 ms 21596 KB
#include<bits/stdc++.h>
#include "towers.h"
using namespace std;
const int N=2000000009;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[100009],pas,L,R,D,seg[400009],l,r,z,za,PI,bo[100009],VAL[100009],pr[100009],counter,fen[200009],fen2[200009],K[100009],HD[1000009],lf[100009],rg[100009],aris[100009];
int segLF[400009],segRG[400009],segaris[400009];
map <int, int> m;
map <int, int>::iterator TA;
vector <pair <int, int> > ANS;
multiset <int> s;
multiset <int>::iterator it,tt;
multiset <pair <int, int> > S;
multiset <pair <int, int> >::iterator IT,TT;
pair <int, int> P[100009];
//
void upd(int q, int w){
    q=200003-q;
    while(q<=200005){
        fen[q]=min(fen[q],w);
        q=q+(q&(-q));
    }
}
int READ(int q){
    q=200003-q;
    int sm=200007;
    while(q>0){
        sm=min(sm,fen[q]);
        q=q-(q&(-q));
    }
    return sm;
}

void upd2(int q, int w){
    q=200003-q;
    while(q<=200005){
        fen2[q]=max(fen2[q],w);
        q=q+(q&(-q));
    }
}
int read2(int q){
    q=200003-q;
    int sm=0;
    while(q>0){
        sm=max(sm,fen2[q]);
        q=q-(q&(-q));
    }
    return sm;
}


void upd3(int q, int w){
    while(q<=200005){
        fen[q]=max(fen[q],w);
        q=q+(q&(-q));
    }
}
int read3(int q){
    int sm=0;
    while(q>0){
        sm=max(sm,fen[q]);
        q=q-(q&(-q));
    }
    return sm;
}
//
void read(int q, int w, int rr){
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        z=max(z,seg[rr]);
        return;
    }
    read(q,(q+w)/2,rr*2);
    read((q+w)/2+1,w,rr*2+1);
}

void readLF(int q, int w, int rr){
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        z=max(z,segLF[rr]);
        return;
    }
    readLF(q,(q+w)/2,rr*2);
    readLF((q+w)/2+1,w,rr*2+1);
}
void readRG(int q, int w, int rr){
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        z=min(z,segRG[rr]);
        return;
    }
    readRG(q,(q+w)/2,rr*2);
    readRG((q+w)/2+1,w,rr*2+1);
}
void readaris(int q, int w, int rr){
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        z=max(z,segaris[rr]);
        return;
    }
    readaris(q,(q+w)/2,rr*2);
    readaris((q+w)/2+1,w,rr*2+1);
}
//
void UPD(int i){
    int D;
    multiset <int>::iterator it,tt;
    multiset <pair <int, int> >::iterator IT,TT;
    tt=s.lower_bound(i);
    tt++;


    if(tt==s.end()){
        R=a+1;
    }else{
        R=(*tt);
    }
    it=s.lower_bound(i);
    if(it==s.begin()){
        L=0;
    }else{
        it--;
        L=(*it);
    }
    L++;R--;



    z=0;
    l=i+1;r=R;
    if(l<=r) read(1,za,1);
    if(r==a) z=N;
    e=z;
    z=0;
    l=L;r=i-1;
    if(l<=r) read(1,za,1);
    if(l==1) z=N;
    e=min(e,z);
    S.erase({VAL[i],i});
    S.insert({e-f[i]+1,i});
    VAL[i]=e-f[i]+1;
}
void init(int NN, std::vector<int> HH) {
    a=NN;
    for(i=1; i<=a; i++){
        f[i]=HH[i-1];
    }
}

int max_towers(int LL, int RR, int DD) {
    counter++;
    if(counter==1){
        za=1;D=DD;
        while(za<a) za*=2;
        for(i=1; i<=a; i++){
            seg[za+i-1]=f[i];
        }
        for(i=za-1; i>=1; i--){
            seg[i]=max(seg[i*2],seg[i*2+1]);
        }

        for(i=1; i<=a; i++){
            PI++;P[PI]={f[i],i};
        }
        sort(P+1,P+PI+1);


        for(ii=1; ii<=PI; ii++){
            i=P[ii].second;
            tt=s.lower_bound(i);
            if(tt==s.end()){
                R=a+1;
            }else{
                R=(*tt);
            }
            it=s.lower_bound(i);
            if(it==s.begin()){
                L=0;
            }else{
                it--;
                L=(*it);
            }
            L++;R--;

            e=0;
            z=0;
            l=i+1;r=R;
            if(l<=r) read(1,za,1);
            if(r==a) z=N;
            if(z<f[i]+D){
                e++;
            }
            z=0;
            l=L;r=i-1;
            if(l<=r) read(1,za,1);
            if(l==1) z=N;
            if(z<f[i]+D){
                e++;
            }
            if(e>0) continue;
            //cout<<i<<" "<<z<<" "<<f[i]<<" "<<D<<"\n";
            s.insert(i);bo[i]=1;
        }


        for(i=1; i<=a; i++){
            pr[i]=pr[i-1]+bo[i];
        }
        /*for(i=1; i<=a; i++){
            cout<<pr[i]<<" pr ";
        }
        cout<<"\n";*/


        //
        m.clear();
        for(i=1; i<=a; i++){
            m[f[i]]=1;m[f[i]+D]=1;
        }
        zx=0;
        for(TA=m.begin(); TA!=m.end(); TA++){
            zx++;
            (*TA).second=zx;
        }

        for(i=1; i<=a; i++){
            HD[i]=m[f[i]+D];
            K[i]=m[f[i]];
        }

        for(i=1; i<=a; i++){
            lf[i]=read2(HD[i]);
            upd2(K[i],i);
        }

        /*for(i=1; i<=a; i++){
            cout<<lf[i]<<" lf ";
        }
        cout<<"\n";*/

        for(i=0; i<=200007; i++){
            fen[i]=a+1;
        }
        for(i=a; i>=1; i--){
            rg[i]=READ(HD[i]);
            upd(K[i],i);
        }

        for(i=1; i<=a; i++){
            segLF[za+i-1]=lf[i];
        }

        for(i=za-1; i>=1; i--){
            segLF[i]=max(segLF[i*2],segLF[i*2+1]);
        }

        for(i=1; i<=a; i++){
            segRG[za+i-1]=rg[i];
        }
        for(i=za-1; i>=1; i--){
            segRG[i]=min(segRG[i*2],segRG[i*2+1]);
        }



        //return 0;

        for(i=0; i<=200007; i++){
            fen[i]=fen2[i]=0;
        }
        for(i=1; i<=a; i++){
            aris[i]=read2(HD[i]);
            zx=read3(K[i]);
            /*cout<<i<<" "<<zx<<"\n";
            cout<<K[i]<<" "<<HD[i]<<"\n";*/
            upd2(K[i],zx);
            upd3(HD[i],i);
        }
        //return 0;

        for(i=1; i<=a; i++){
            segaris[za+i-1]=aris[i];
        }
        for(i=za-1; i>=1; i--){
            segaris[i]=max(segaris[i*2],segaris[i*2+1]);
        }
        //return 0;
    }











    //




    pas=1;LL++;RR++;
    L=LL;R=RR;D=DD;
    if(L==R) return 1;

    zx=pr[R]-pr[L-1];
    //cout<<zx<<"\n";
    it=s.lower_bound(L);

    l=L;r=lf[(*it)]-1;z=a+2;
    if(l<=r) readRG(1,za,1);
    if(z<(*it)) zx++;

    it=s.lower_bound(R+1);
    if(it!=s.end()){
        it--;

        l=rg[(*it)]+1;r=R;z=0;
        if(l<=r) readLF(1,za,1);
        if((*it)<z) zx++;
    }

    pas=max(pas,zx);

    //da-check-e 2-ic tu sheidzleba

    l=L;r=R;z=0;
    readaris(1,za,1);
    if(z>=L) pas=max(pas,2);
    return pas;
}

Compilation message

towers.cpp: In function 'void UPD(int)':
towers.cpp:105:9: warning: unused variable 'D' [-Wunused-variable]
  105 |     int D;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 11728 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2000 KB Output is correct
2 Correct 3 ms 2256 KB Output is correct
3 Correct 3 ms 2256 KB Output is correct
4 Correct 3 ms 2256 KB Output is correct
5 Correct 4 ms 2256 KB Output is correct
6 Correct 3 ms 2256 KB Output is correct
7 Correct 4 ms 2184 KB Output is correct
8 Correct 2 ms 2256 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2256 KB Output is correct
11 Correct 2 ms 2256 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 3 ms 2256 KB Output is correct
14 Correct 2 ms 2256 KB Output is correct
15 Correct 3 ms 2256 KB Output is correct
16 Correct 3 ms 2256 KB Output is correct
17 Correct 3 ms 2256 KB Output is correct
18 Correct 2 ms 2256 KB Output is correct
19 Correct 2 ms 2256 KB Output is correct
20 Correct 3 ms 2256 KB Output is correct
21 Correct 3 ms 2256 KB Output is correct
22 Correct 3 ms 2256 KB Output is correct
23 Correct 3 ms 2256 KB Output is correct
24 Correct 2 ms 2180 KB Output is correct
25 Correct 2 ms 2000 KB Output is correct
26 Correct 3 ms 2256 KB Output is correct
27 Correct 3 ms 2256 KB Output is correct
28 Correct 3 ms 2256 KB Output is correct
29 Correct 3 ms 2256 KB Output is correct
30 Correct 3 ms 2256 KB Output is correct
31 Correct 3 ms 2256 KB Output is correct
32 Correct 3 ms 2256 KB Output is correct
33 Correct 2 ms 2256 KB Output is correct
34 Correct 2 ms 2256 KB Output is correct
35 Correct 3 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2000 KB Output is correct
2 Correct 3 ms 2256 KB Output is correct
3 Correct 3 ms 2256 KB Output is correct
4 Correct 3 ms 2256 KB Output is correct
5 Correct 4 ms 2256 KB Output is correct
6 Correct 3 ms 2256 KB Output is correct
7 Correct 4 ms 2184 KB Output is correct
8 Correct 2 ms 2256 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2256 KB Output is correct
11 Correct 2 ms 2256 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 3 ms 2256 KB Output is correct
14 Correct 2 ms 2256 KB Output is correct
15 Correct 3 ms 2256 KB Output is correct
16 Correct 3 ms 2256 KB Output is correct
17 Correct 3 ms 2256 KB Output is correct
18 Correct 2 ms 2256 KB Output is correct
19 Correct 2 ms 2256 KB Output is correct
20 Correct 3 ms 2256 KB Output is correct
21 Correct 3 ms 2256 KB Output is correct
22 Correct 3 ms 2256 KB Output is correct
23 Correct 3 ms 2256 KB Output is correct
24 Correct 2 ms 2180 KB Output is correct
25 Correct 2 ms 2000 KB Output is correct
26 Correct 3 ms 2256 KB Output is correct
27 Correct 3 ms 2256 KB Output is correct
28 Correct 3 ms 2256 KB Output is correct
29 Correct 3 ms 2256 KB Output is correct
30 Correct 3 ms 2256 KB Output is correct
31 Correct 3 ms 2256 KB Output is correct
32 Correct 3 ms 2256 KB Output is correct
33 Correct 2 ms 2256 KB Output is correct
34 Correct 2 ms 2256 KB Output is correct
35 Correct 3 ms 2256 KB Output is correct
36 Correct 114 ms 13816 KB Output is correct
37 Correct 188 ms 19512 KB Output is correct
38 Correct 226 ms 20160 KB Output is correct
39 Correct 178 ms 19392 KB Output is correct
40 Correct 185 ms 21024 KB Output is correct
41 Correct 221 ms 20288 KB Output is correct
42 Correct 192 ms 21528 KB Output is correct
43 Correct 101 ms 18792 KB Output is correct
44 Correct 98 ms 18776 KB Output is correct
45 Correct 102 ms 18808 KB Output is correct
46 Correct 104 ms 18880 KB Output is correct
47 Correct 161 ms 20672 KB Output is correct
48 Correct 166 ms 21476 KB Output is correct
49 Correct 162 ms 21556 KB Output is correct
50 Correct 89 ms 18764 KB Output is correct
51 Correct 95 ms 18784 KB Output is correct
52 Correct 204 ms 20748 KB Output is correct
53 Correct 157 ms 21544 KB Output is correct
54 Correct 168 ms 21576 KB Output is correct
55 Correct 97 ms 18772 KB Output is correct
56 Correct 92 ms 18800 KB Output is correct
57 Correct 161 ms 19232 KB Output is correct
58 Correct 180 ms 20004 KB Output is correct
59 Correct 186 ms 20260 KB Output is correct
60 Correct 204 ms 21512 KB Output is correct
61 Correct 225 ms 21048 KB Output is correct
62 Correct 220 ms 20472 KB Output is correct
63 Correct 217 ms 21156 KB Output is correct
64 Correct 122 ms 18768 KB Output is correct
65 Correct 113 ms 18728 KB Output is correct
66 Correct 110 ms 18736 KB Output is correct
67 Correct 122 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 950 ms 20632 KB Output is correct
2 Correct 1004 ms 20732 KB Output is correct
3 Correct 929 ms 20768 KB Output is correct
4 Correct 853 ms 21584 KB Output is correct
5 Correct 977 ms 21596 KB Output is correct
6 Correct 1099 ms 21488 KB Output is correct
7 Correct 1103 ms 21564 KB Output is correct
8 Correct 885 ms 18780 KB Output is correct
9 Correct 896 ms 18804 KB Output is correct
10 Correct 963 ms 18724 KB Output is correct
11 Correct 850 ms 18752 KB Output is correct
12 Correct 768 ms 18776 KB Output is correct
13 Correct 759 ms 18920 KB Output is correct
14 Correct 1 ms 1872 KB Output is correct
15 Correct 3 ms 2256 KB Output is correct
16 Correct 2 ms 2256 KB Output is correct
17 Correct 178 ms 20664 KB Output is correct
18 Correct 201 ms 21544 KB Output is correct
19 Correct 176 ms 21548 KB Output is correct
20 Correct 87 ms 18772 KB Output is correct
21 Correct 108 ms 18720 KB Output is correct
22 Correct 168 ms 20776 KB Output is correct
23 Correct 162 ms 21552 KB Output is correct
24 Correct 166 ms 21512 KB Output is correct
25 Correct 110 ms 18784 KB Output is correct
26 Correct 97 ms 18736 KB Output is correct
27 Correct 3 ms 2256 KB Output is correct
28 Correct 3 ms 2216 KB Output is correct
29 Correct 3 ms 2256 KB Output is correct
30 Correct 2 ms 2256 KB Output is correct
31 Correct 2 ms 2256 KB Output is correct
32 Correct 3 ms 2256 KB Output is correct
33 Correct 3 ms 2256 KB Output is correct
34 Correct 3 ms 2256 KB Output is correct
35 Correct 2 ms 2256 KB Output is correct
36 Correct 2 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 6316 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2000 KB Output is correct
2 Correct 3 ms 2256 KB Output is correct
3 Correct 3 ms 2256 KB Output is correct
4 Correct 3 ms 2256 KB Output is correct
5 Correct 4 ms 2256 KB Output is correct
6 Correct 3 ms 2256 KB Output is correct
7 Correct 4 ms 2184 KB Output is correct
8 Correct 2 ms 2256 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2256 KB Output is correct
11 Correct 2 ms 2256 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 3 ms 2256 KB Output is correct
14 Correct 2 ms 2256 KB Output is correct
15 Correct 3 ms 2256 KB Output is correct
16 Correct 3 ms 2256 KB Output is correct
17 Correct 3 ms 2256 KB Output is correct
18 Correct 2 ms 2256 KB Output is correct
19 Correct 2 ms 2256 KB Output is correct
20 Correct 3 ms 2256 KB Output is correct
21 Correct 3 ms 2256 KB Output is correct
22 Correct 3 ms 2256 KB Output is correct
23 Correct 3 ms 2256 KB Output is correct
24 Correct 2 ms 2180 KB Output is correct
25 Correct 2 ms 2000 KB Output is correct
26 Correct 3 ms 2256 KB Output is correct
27 Correct 3 ms 2256 KB Output is correct
28 Correct 3 ms 2256 KB Output is correct
29 Correct 3 ms 2256 KB Output is correct
30 Correct 3 ms 2256 KB Output is correct
31 Correct 3 ms 2256 KB Output is correct
32 Correct 3 ms 2256 KB Output is correct
33 Correct 2 ms 2256 KB Output is correct
34 Correct 2 ms 2256 KB Output is correct
35 Correct 3 ms 2256 KB Output is correct
36 Correct 114 ms 13816 KB Output is correct
37 Correct 188 ms 19512 KB Output is correct
38 Correct 226 ms 20160 KB Output is correct
39 Correct 178 ms 19392 KB Output is correct
40 Correct 185 ms 21024 KB Output is correct
41 Correct 221 ms 20288 KB Output is correct
42 Correct 192 ms 21528 KB Output is correct
43 Correct 101 ms 18792 KB Output is correct
44 Correct 98 ms 18776 KB Output is correct
45 Correct 102 ms 18808 KB Output is correct
46 Correct 104 ms 18880 KB Output is correct
47 Correct 161 ms 20672 KB Output is correct
48 Correct 166 ms 21476 KB Output is correct
49 Correct 162 ms 21556 KB Output is correct
50 Correct 89 ms 18764 KB Output is correct
51 Correct 95 ms 18784 KB Output is correct
52 Correct 204 ms 20748 KB Output is correct
53 Correct 157 ms 21544 KB Output is correct
54 Correct 168 ms 21576 KB Output is correct
55 Correct 97 ms 18772 KB Output is correct
56 Correct 92 ms 18800 KB Output is correct
57 Correct 161 ms 19232 KB Output is correct
58 Correct 180 ms 20004 KB Output is correct
59 Correct 186 ms 20260 KB Output is correct
60 Correct 204 ms 21512 KB Output is correct
61 Correct 225 ms 21048 KB Output is correct
62 Correct 220 ms 20472 KB Output is correct
63 Correct 217 ms 21156 KB Output is correct
64 Correct 122 ms 18768 KB Output is correct
65 Correct 113 ms 18728 KB Output is correct
66 Correct 110 ms 18736 KB Output is correct
67 Correct 122 ms 18780 KB Output is correct
68 Correct 950 ms 20632 KB Output is correct
69 Correct 1004 ms 20732 KB Output is correct
70 Correct 929 ms 20768 KB Output is correct
71 Correct 853 ms 21584 KB Output is correct
72 Correct 977 ms 21596 KB Output is correct
73 Correct 1099 ms 21488 KB Output is correct
74 Correct 1103 ms 21564 KB Output is correct
75 Correct 885 ms 18780 KB Output is correct
76 Correct 896 ms 18804 KB Output is correct
77 Correct 963 ms 18724 KB Output is correct
78 Correct 850 ms 18752 KB Output is correct
79 Correct 768 ms 18776 KB Output is correct
80 Correct 759 ms 18920 KB Output is correct
81 Correct 1 ms 1872 KB Output is correct
82 Correct 3 ms 2256 KB Output is correct
83 Correct 2 ms 2256 KB Output is correct
84 Correct 178 ms 20664 KB Output is correct
85 Correct 201 ms 21544 KB Output is correct
86 Correct 176 ms 21548 KB Output is correct
87 Correct 87 ms 18772 KB Output is correct
88 Correct 108 ms 18720 KB Output is correct
89 Correct 168 ms 20776 KB Output is correct
90 Correct 162 ms 21552 KB Output is correct
91 Correct 166 ms 21512 KB Output is correct
92 Correct 110 ms 18784 KB Output is correct
93 Correct 97 ms 18736 KB Output is correct
94 Correct 3 ms 2256 KB Output is correct
95 Correct 3 ms 2216 KB Output is correct
96 Correct 3 ms 2256 KB Output is correct
97 Correct 2 ms 2256 KB Output is correct
98 Correct 2 ms 2256 KB Output is correct
99 Correct 3 ms 2256 KB Output is correct
100 Correct 3 ms 2256 KB Output is correct
101 Correct 3 ms 2256 KB Output is correct
102 Correct 2 ms 2256 KB Output is correct
103 Correct 2 ms 2256 KB Output is correct
104 Correct 766 ms 18732 KB Output is correct
105 Correct 997 ms 20240 KB Output is correct
106 Correct 919 ms 19840 KB Output is correct
107 Correct 968 ms 20668 KB Output is correct
108 Correct 999 ms 19280 KB Output is correct
109 Correct 1088 ms 20556 KB Output is correct
110 Correct 916 ms 21440 KB Output is correct
111 Correct 815 ms 18804 KB Output is correct
112 Correct 880 ms 18724 KB Output is correct
113 Correct 845 ms 18976 KB Output is correct
114 Correct 795 ms 18740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 11728 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -