This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// ROIGold.cpp
// Main calisma
//
// Created by Rakhman on 05/02/2019.
// Copyright © 2019 Rakhman. All rights reserved.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
const long long MXN = 2e5 + 200;
const long long N = 2e5 + 200;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
void gettxt(bool yes){
if(yes == 1){
freopen("problem.in", "r", stdin);
freopen("problem.out", "w", stdout);
}else{
freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
}
}
int n, Q, ans[MXN];
pair<int, int> q[MXN];
vector<int> st[MXN], en[MXN], range[MXN];
struct antenna{
int a, b, h;
}b[MXN];
struct node{
int t, mx, mod;
}t[MXN * 4];
void push(int v){
if(t[v].mod != OO){
t[v + v].mod = min(t[v + v].mod, t[v].mod);
t[v + v + 1].mod = min(t[v + v + 1].mod, t[v].mod);
}
t[v].t = max(t[v].t, t[v].mx - t[v].mod);
t[v].mod = OO;
}
void updating(int v){
t[v].mx = max(t[v + v].mx, t[v + v + 1].mx);
t[v].t = max(t[v + v].t, t[v + v + 1].t);
}
void upd(int v, int tl, int tr, int pos, int x){
push(v);
if(tl == tr){
t[v].mx = x;
return ;
}
int tm = (tl + tr) / 2;
if(pos <= tm){
upd(v + v, tl, tm, pos, x);
}else{
upd(v + v + 1, tm + 1, tr, pos, x);
}
updating(v);
}
void segupd(int v, int tl, int tr, int l, int r, int x){
push(v);
if(l <= tl && tr <= r){
t[v].mod = x;
push(v);
return ;
}
if(r < tl || tr < l) return ;
int tm = (tl + tr) / 2;
segupd(v + v, tl, tm, l, r, x);
segupd(v + v + 1, tm + 1, tr, l, r, x);
updating(v);
}
int get(int v, int tl, int tr, int l, int r){
push(v);
if(l <= tl && tr <= r){
return t[v].t;
}
if(r < tl || tr < l){
return -1;
}
int tm = (tl + tr) / 2;
return max(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}
void solve(){
for(int i = 1; i < MXN * 4; i++){
t[i].t = -1;
t[i].mx = 0;
t[i].mod = OO;
}
for(int i = 1; i <= n; i++){
st[i].clear();
en[i].clear();
range[i].clear();
}
for(int i = 1; i <= n; i++){
if(i + b[i].a <= n){
st[i + b[i].a].push_back(i);
}
if(i + b[i].b <= n){
en[i + b[i].b].push_back(i);
}
}
for(int i = 1; i <= Q; i++){
range[q[i].S].push_back(i);
}
for(int i = 1; i <= n; i++){
for(auto j : st[i]){
upd(1, 1, n, j, b[j].h);
}
if(i - b[i].a > 0){
segupd(1, 1, n, i - b[i].b, i - b[i].a, b[i].h);
}
for(auto j : range[i]){
ans[j] = max(ans[j], get(1, 1, n, q[j].F, q[j].S));
}
for(int j : en[i]){
upd(1, 1, n, j, 0);
}
}
}
int main () {
ios;
//gettxt(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> b[i].h >> b[i].a >> b[i].b;
}
cin >> Q;
for(int i = 1; i <= Q; i++){
ans[i] = -1;
cin >> q[i].F >> q[i].S;
}
solve();
reverse(b + 1, b + n + 1);
for(int i = 1; i <= Q; i++){
tie(q[i].F, q[i].S) = make_pair(n - q[i].S + 1, n - q[i].F + 1);
}
solve();
for(int i = 1; i <= Q; i++){
cout << ans[i] << nl;
}
return 0;
}
Compilation message (stderr)
antennas.cpp: In function 'void gettxt(bool)':
antennas.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("problem.in", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("problem.out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |