Submission #832513

# Submission time Handle Problem Language Result Execution time Memory
832513 2023-08-21T11:01:23 Z fatemetmhr Radio Towers (IOI22_towers) C++17
0 / 100
685 ms 18208 KB
// komak!

#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define mp       make_pair
#define pb       push_back

typedef long long ll;

const ll mod   = 1e9 + 7;
const int maxn5 = 1e5 + 10;
const int lg    = 20;

int mxid, h[maxn5];
int n, dp[maxn5], dp2[maxn5];
pair <int, int> mx[lg][maxn5];
int nolef[maxn5], norig[maxn5], ps[maxn5];

int get_max(int l, int r){
    int k = 31 - __builtin_clz(r - l + 1);
    return max(mx[k][l], mx[k][r - (1 << k) + 1]).se;
}

void solve(int l, int r){
    if(r <= l)
        return;
    int mid = get_max(l, r - 1);
    solve(l, mid);
    solve(mid + 1, r);
    if(r - l == 1)
        ps[l] = 1;
    if(l == mid)
        norig[mid] = true;
    if(r - 1 == mid)
        nolef[mid] = true;
}

void init(int N, std::vector<int> H) {

    mxid = 0;
    n = N;
    for(int i = 0; i < n; i++){
        h[i] = H[i];
        if(h[i] > h[mxid])
            mxid = i;
        mx[0][i] = {h[i], i};
    }
    for(int i = 1; i < lg; i++) for(int j = 0; j < n; j++)
        mx[i][j] = max(mx[i - 1][j], (j + (1 << (i - 1)) < n ? mx[i - 1][j + (1 << (i - 1))] : mp(0, 0)));
    solve(0, n);
    for(int i = 1; i < n; i++)
        ps[i] += ps[i - 1];
}

int max_towers(int l, int r, int d) {

    return ps[r] - (l ? ps[l - 1] : 0) + (norig[l] && !nolef[l]) + (!norig[r] + nolef[r]);

}
# Verdict Execution time Memory Grader output
1 Incorrect 426 ms 13080 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 464 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 685 ms 18208 KB 1st lines differ - on the 1st token, expected: '11903', found: '11902'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 4688 KB 1st lines differ - on the 1st token, expected: '7197', found: '8006'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 426 ms 13080 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -