Submission #788687

# Submission time Handle Problem Language Result Execution time Memory
788687 2023-07-20T13:26:57 Z mosiashvililuka Radio Towers (IOI22_towers) C++17
17 / 100
965 ms 9312 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],K,pas,L,R,D,seg[400009],l,r,z,za,PI,bo[100009],VAL[100009];
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 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 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];
    }
    za=1;
    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);

    D=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;
        s.insert(i);bo[i]=1;
    }

    ANS.push_back({1,s.size()});

    //cout<<s.size()<<"\n";

    for(i=1; i<=a; i++){
        if(bo[i]==0) continue;
        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.insert({e-f[i]+1,i});
        VAL[i]=e-f[i]+1;
    }

    /*for(i=1; i<=a; i++){
        if(bo[i]==0) continue;
        cout<<i<<" "<<VAL[i]<<"\n";
    }*/

    while(s.size()>1){
        IT=S.begin();
        D=(*IT).first;
        i=(*IT).second;
        S.erase(IT);
        s.erase(i);

        tt=s.lower_bound(i);
        if(tt!=s.end()){
            UPD((*tt));
        }
        it=tt;
        if(it!=s.begin()){
            it--;
            UPD((*it));
        }

        IT=S.begin();
        //if((*IT).first>D){
            ANS.push_back({D,s.size()});
        //}
    }
}

int max_towers(int LL, int RR, int DD) {
    pas=1;LL++;RR++;
    L=LL;R=RR;D=DD;


    c=lower_bound(ANS.begin(),ANS.end(),make_pair(D+1,0))-ANS.begin();
    c--;
    pas=ANS[c].second;
    return pas;
}

Compilation message

towers.cpp: In function 'void UPD(int)':
towers.cpp:22:9: warning: unused variable 'D' [-Wunused-variable]
   22 |     int D;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 252 ms 1872 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 576 ms 7416 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 284 ms 2116 KB Output is correct
2 Correct 799 ms 7392 KB Output is correct
3 Correct 954 ms 7496 KB Output is correct
4 Correct 833 ms 9260 KB Output is correct
5 Correct 866 ms 9312 KB Output is correct
6 Correct 862 ms 9156 KB Output is correct
7 Correct 965 ms 9256 KB Output is correct
8 Correct 668 ms 3280 KB Output is correct
9 Correct 566 ms 3152 KB Output is correct
10 Correct 678 ms 3116 KB Output is correct
11 Correct 510 ms 3144 KB Output is correct
12 Correct 144 ms 7372 KB Output is correct
13 Correct 194 ms 9176 KB Output is correct
14 Correct 183 ms 9264 KB Output is correct
15 Correct 34 ms 3156 KB Output is correct
16 Correct 39 ms 3184 KB Output is correct
17 Correct 137 ms 7240 KB Output is correct
18 Correct 141 ms 7344 KB Output is correct
19 Correct 151 ms 7472 KB Output is correct
20 Correct 179 ms 9240 KB Output is correct
21 Correct 180 ms 9200 KB Output is correct
22 Correct 183 ms 9212 KB Output is correct
23 Correct 188 ms 9288 KB Output is correct
24 Correct 38 ms 3164 KB Output is correct
25 Correct 34 ms 3132 KB Output is correct
26 Correct 43 ms 3164 KB Output is correct
27 Correct 41 ms 3156 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 4 ms 464 KB Output is correct
30 Correct 3 ms 464 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 464 KB Output is correct
37 Correct 3 ms 464 KB Output is correct
38 Correct 4 ms 464 KB Output is correct
39 Correct 3 ms 464 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 252 ms 1872 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -