Submission #613295

#TimeUsernameProblemLanguageResultExecution timeMemory
613295talant117408Two Antennas (JOI19_antennas)C++17
13 / 100
460 ms350720 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define long unsigned long #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' #define PI 2*acos(0.0) void solve(int test) { int n, q; cin >> n; vector <int> h(n), a(n), b(n); for (int i = 0; i < n; i++) { cin >> h[i] >> a[i] >> b[i]; } if (n <= 2000) { int cost[n][n][20], lg[n + 1], left[n][n], right[n][n]; lg[1] = 0; for (int i = 2; i <= n; i++) { lg[i] = lg[i / 2] + 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { right[i][j] = -1; left[i][j] = -1; for (int k = 0; k < 20; k++) { cost[i][j][k] = -1; } } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (max(a[i], a[j]) <= j - i && j - i <= min(b[i], b[j])) { right[i][j] = abs(h[i] - h[j]); } } } for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { right[j][i] = max(right[j][i], right[j + 1][i]); } } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { cost[i][j][0] = right[i][j]; } } //~ for (int i = 0; i < n; i++) { //~ for (int j = i; j < n; j++) { //~ cout << cost[i][j][0] << ' '; //~ } //~ cout << endl; //~ } for (int l = 0; l < n; l++) { for (int j = 1; j < 20; j++) { for (int i = 0; i + (1 << j) <= n; i++) { cost[l][i][j] = max(cost[l][i][j - 1], cost[l][i + (1 << (j - 1))][j - 1]); } } } int q; cin >> q; vector <pair <pii, int>> queries(q); for (int i = 0; i < q; i++) { cin >> queries[i].first.first >> queries[i].first.second; queries[i].second = i; int l = queries[i].first.first, r = queries[i].first.second; l--;r --; int j = lg[r - l + 1]; //~ cout << l << ' ' << r << ' ' << j << endl; cout << max(cost[l][l][j], cost[l][r - (1 << j) + 1][j]) << endl; } } } int main() { do_not_disturb int t = 1; //~ cin >> t; for (int i = 1; i <= t; i++) { solve(i); } return 0; }

Compilation message (stderr)

antennas.cpp: In function 'void solve(int)':
antennas.cpp:29:40: warning: variable 'left' set but not used [-Wunused-but-set-variable]
   29 |         int cost[n][n][20], lg[n + 1], left[n][n], right[n][n];
      |                                        ^~~~
antennas.cpp:22:12: warning: unused variable 'q' [-Wunused-variable]
   22 |     int n, q;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...