Submission #825032

#TimeUsernameProblemLanguageResultExecution timeMemory
825032becaidoRadio Towers (IOI22_towers)C++17
11 / 100
4066 ms1488 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "towers.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1e5 + 5;

int n;
int a[SIZE];

void init(int N, vector<int> H) {
    n = N;
    FOR (i, 0, n - 1) a[i] = H[i];
}

int dp[SIZE];
int max_towers(int L, int R, int D) {
    FOR (i, L, R) {
        int mx = 0, h = 0;
        for (int j = i - 1; j >= L; j--) {
            if (h - D >= max(a[i], a[j])) mx = max(mx, dp[j]);
            h = max(h, a[j]);
        }
        dp[i] = mx + 1;
    }
    return *max_element(dp + L, dp + R + 1);
}

/*
in1
7 3
10 20 60 40 50 30 70
1 5 10
2 2 100
0 6 17
out1
3
1
2
*/

#ifdef WAIMAI
int main() {
  int N, Q;
  assert(2 == scanf("%d %d", &N, &Q));
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    assert(1 == scanf("%d", &H[i]));
  }
  init(N, H);

  for (int i = 0; i < Q; ++i) {
    int L, R, D;
    assert(3 == scanf("%d %d %d", &L, &R, &D));
    printf("%d\n", max_towers(L, R, D));
  }
  return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...