Submission #787713

# Submission time Handle Problem Language Result Execution time Memory
787713 2023-07-19T11:29:54 Z andrei_boaca Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 17096 KB
#include "towers.h"
#include <bits/stdc++.h>
//#include "stub.cpp"
using namespace std;
typedef pair<int,int> pii;
int n;
int v[100005];
int rmq[22][100005];
int loga[100005];
int lft[100005],rgt[100005];
int getmax(int l,int r)
{
    int lg=loga[r-l+1];
    return max(rmq[lg][l],rmq[lg][r-(1<<lg)+1]);
}
int getR(int poz,int delta)
{
    int st=poz+2;
    int dr=n;
    int ans=1e9;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(getmax(poz+1,mij-1)-delta>=v[poz])
        {
            ans=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    return ans;
}
int getL(int poz,int delta)
{
    int st=1;
    int dr=poz-2;
    int ans=0;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(getmax(mij+1,poz-1)-delta>=v[poz])
        {
            ans=mij;
            st=mij+1;
        }
        else
            dr=mij-1;
    }
    return ans;
}
int bin[22][100005];
int maxbin[22][22][100005];
int getmaxbin(int k,int l,int r)
{
    if(r<=0)
        return 0;
    int lg=loga[r-l+1];
    return max(maxbin[k][lg][l],maxbin[k][lg][r-(1<<lg)+1]);
}
void init(int N, std::vector<int> H) {
    n=N;
    for(int i=1;i<=n;i++)
    {
        v[i]=H[i-1];
        for(int j=0;j<=20;j++)
            if((1<<j)<=i)
                loga[i]=j;
    }
    for(int i=n;i>=1;i--)
    {
        rmq[0][i]=v[i];
        for(int j=1;j<=20;j++)
        {
            rmq[j][i]=rmq[j-1][i];
            int poz=i+(1<<(j-1));
            if(poz<=n)
                rmq[j][i]=max(rmq[j][i],rmq[j-1][poz]);
        }
    }
}
int dp[100005];
int arb[4*100005];
vector<int> add[100005];
void update(int nod,int st,int dr,int poz,int val)
{
    if(st==dr)
    {
        arb[nod]=val;
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij)
        update(nod*2,st,mij,poz,val);
    else
        update(nod*2+1,mij+1,dr,poz,val);
    arb[nod]=max(arb[nod*2],arb[nod*2+1]);
}
int query(int nod,int st,int dr,int a,int b)
{
    if(st>=a&&dr<=b)
        return arb[nod];
    int mij=(st+dr)/2;
    int rez=0;
    if(a<=mij)
        rez=max(rez,query(nod*2,st,mij,a,b));
    if(b>mij)
        rez=max(rez,query(nod*2+1,mij+1,dr,a,b));
    return rez;
}
int max_towers(int L, int R, int D)
{
    L++;
    R++;
    for(int i=1;i<=4*n;i++)
        arb[i]=0;
    for(int i=1;i<=n;i++)
        add[i].clear();
    int ans=1;
    for(int i=L;i<=R;i++)
    {
        for(int j:add[i])
            update(1,1,n,j,dp[j]);
        dp[i]=1;
        int r=getR(i,D);
        int l=getL(i,D);
        if(l>=L)
            dp[i]=1+query(1,1,n,L,l);
        ans=max(ans,dp[i]);
        if(r<=R)
            add[r].push_back(i);
    }
    if(D==1)
    {
        int rez=1;
        for(int i=R;i>=L;i--)
            if(v[i]<=v[i-1])
            {
                rez=dp[i];
                break;
            }
        assert(rez==ans);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 11520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2768 KB Output is correct
2 Correct 2 ms 2892 KB Output is correct
3 Correct 2 ms 2896 KB Output is correct
4 Correct 2 ms 2896 KB Output is correct
5 Correct 2 ms 2896 KB Output is correct
6 Correct 2 ms 2896 KB Output is correct
7 Correct 2 ms 2896 KB Output is correct
8 Correct 2 ms 2896 KB Output is correct
9 Correct 2 ms 2896 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2896 KB Output is correct
14 Correct 2 ms 2896 KB Output is correct
15 Correct 2 ms 2904 KB Output is correct
16 Correct 2 ms 2896 KB Output is correct
17 Correct 2 ms 2896 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 3024 KB Output is correct
21 Correct 2 ms 3024 KB Output is correct
22 Correct 2 ms 3024 KB Output is correct
23 Correct 2 ms 2896 KB Output is correct
24 Correct 2 ms 3024 KB Output is correct
25 Correct 2 ms 2896 KB Output is correct
26 Correct 2 ms 2896 KB Output is correct
27 Correct 2 ms 2896 KB Output is correct
28 Correct 2 ms 2896 KB Output is correct
29 Correct 2 ms 2896 KB Output is correct
30 Correct 2 ms 2896 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 3024 KB Output is correct
33 Correct 2 ms 2896 KB Output is correct
34 Correct 2 ms 2896 KB Output is correct
35 Correct 2 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2768 KB Output is correct
2 Correct 2 ms 2892 KB Output is correct
3 Correct 2 ms 2896 KB Output is correct
4 Correct 2 ms 2896 KB Output is correct
5 Correct 2 ms 2896 KB Output is correct
6 Correct 2 ms 2896 KB Output is correct
7 Correct 2 ms 2896 KB Output is correct
8 Correct 2 ms 2896 KB Output is correct
9 Correct 2 ms 2896 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2896 KB Output is correct
14 Correct 2 ms 2896 KB Output is correct
15 Correct 2 ms 2904 KB Output is correct
16 Correct 2 ms 2896 KB Output is correct
17 Correct 2 ms 2896 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 3024 KB Output is correct
21 Correct 2 ms 3024 KB Output is correct
22 Correct 2 ms 3024 KB Output is correct
23 Correct 2 ms 2896 KB Output is correct
24 Correct 2 ms 3024 KB Output is correct
25 Correct 2 ms 2896 KB Output is correct
26 Correct 2 ms 2896 KB Output is correct
27 Correct 2 ms 2896 KB Output is correct
28 Correct 2 ms 2896 KB Output is correct
29 Correct 2 ms 2896 KB Output is correct
30 Correct 2 ms 2896 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 3024 KB Output is correct
33 Correct 2 ms 2896 KB Output is correct
34 Correct 2 ms 2896 KB Output is correct
35 Correct 2 ms 2896 KB Output is correct
36 Correct 20 ms 10216 KB Output is correct
37 Correct 25 ms 13776 KB Output is correct
38 Correct 29 ms 13768 KB Output is correct
39 Correct 23 ms 13776 KB Output is correct
40 Correct 34 ms 13720 KB Output is correct
41 Correct 40 ms 14652 KB Output is correct
42 Correct 19 ms 13644 KB Output is correct
43 Correct 28 ms 14272 KB Output is correct
44 Correct 20 ms 13608 KB Output is correct
45 Correct 19 ms 13516 KB Output is correct
46 Correct 22 ms 13576 KB Output is correct
47 Correct 39 ms 14236 KB Output is correct
48 Correct 31 ms 14032 KB Output is correct
49 Correct 28 ms 13772 KB Output is correct
50 Correct 23 ms 13628 KB Output is correct
51 Correct 35 ms 14944 KB Output is correct
52 Correct 61 ms 15560 KB Output is correct
53 Correct 54 ms 15568 KB Output is correct
54 Correct 55 ms 15560 KB Output is correct
55 Correct 45 ms 13916 KB Output is correct
56 Correct 57 ms 17096 KB Output is correct
57 Correct 39 ms 14172 KB Output is correct
58 Correct 44 ms 14784 KB Output is correct
59 Correct 51 ms 15088 KB Output is correct
60 Correct 53 ms 15572 KB Output is correct
61 Correct 48 ms 15428 KB Output is correct
62 Correct 44 ms 15044 KB Output is correct
63 Correct 54 ms 15464 KB Output is correct
64 Correct 35 ms 14684 KB Output is correct
65 Correct 31 ms 13888 KB Output is correct
66 Correct 41 ms 14792 KB Output is correct
67 Correct 39 ms 13956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 15596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 5888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2768 KB Output is correct
2 Correct 2 ms 2892 KB Output is correct
3 Correct 2 ms 2896 KB Output is correct
4 Correct 2 ms 2896 KB Output is correct
5 Correct 2 ms 2896 KB Output is correct
6 Correct 2 ms 2896 KB Output is correct
7 Correct 2 ms 2896 KB Output is correct
8 Correct 2 ms 2896 KB Output is correct
9 Correct 2 ms 2896 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2896 KB Output is correct
14 Correct 2 ms 2896 KB Output is correct
15 Correct 2 ms 2904 KB Output is correct
16 Correct 2 ms 2896 KB Output is correct
17 Correct 2 ms 2896 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 3024 KB Output is correct
21 Correct 2 ms 3024 KB Output is correct
22 Correct 2 ms 3024 KB Output is correct
23 Correct 2 ms 2896 KB Output is correct
24 Correct 2 ms 3024 KB Output is correct
25 Correct 2 ms 2896 KB Output is correct
26 Correct 2 ms 2896 KB Output is correct
27 Correct 2 ms 2896 KB Output is correct
28 Correct 2 ms 2896 KB Output is correct
29 Correct 2 ms 2896 KB Output is correct
30 Correct 2 ms 2896 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 3024 KB Output is correct
33 Correct 2 ms 2896 KB Output is correct
34 Correct 2 ms 2896 KB Output is correct
35 Correct 2 ms 2896 KB Output is correct
36 Correct 20 ms 10216 KB Output is correct
37 Correct 25 ms 13776 KB Output is correct
38 Correct 29 ms 13768 KB Output is correct
39 Correct 23 ms 13776 KB Output is correct
40 Correct 34 ms 13720 KB Output is correct
41 Correct 40 ms 14652 KB Output is correct
42 Correct 19 ms 13644 KB Output is correct
43 Correct 28 ms 14272 KB Output is correct
44 Correct 20 ms 13608 KB Output is correct
45 Correct 19 ms 13516 KB Output is correct
46 Correct 22 ms 13576 KB Output is correct
47 Correct 39 ms 14236 KB Output is correct
48 Correct 31 ms 14032 KB Output is correct
49 Correct 28 ms 13772 KB Output is correct
50 Correct 23 ms 13628 KB Output is correct
51 Correct 35 ms 14944 KB Output is correct
52 Correct 61 ms 15560 KB Output is correct
53 Correct 54 ms 15568 KB Output is correct
54 Correct 55 ms 15560 KB Output is correct
55 Correct 45 ms 13916 KB Output is correct
56 Correct 57 ms 17096 KB Output is correct
57 Correct 39 ms 14172 KB Output is correct
58 Correct 44 ms 14784 KB Output is correct
59 Correct 51 ms 15088 KB Output is correct
60 Correct 53 ms 15572 KB Output is correct
61 Correct 48 ms 15428 KB Output is correct
62 Correct 44 ms 15044 KB Output is correct
63 Correct 54 ms 15464 KB Output is correct
64 Correct 35 ms 14684 KB Output is correct
65 Correct 31 ms 13888 KB Output is correct
66 Correct 41 ms 14792 KB Output is correct
67 Correct 39 ms 13956 KB Output is correct
68 Execution timed out 4022 ms 15596 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 11520 KB Time limit exceeded
2 Halted 0 ms 0 KB -