#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 200'001;
const long long INF = (1LL << 63);
struct aintnode{
long long minimp, minpar, maximp, maxpar;
}aint[4 * MAXN + 1];
long long lazy[4 * MAXN + 1];
long long minipar, maximpar;
static inline void nodeupd(int node, int val){
if(aint[node].minpar != INF){
aint[node].minpar += val;
aint[node].maxpar += val;
}
if(aint[node].minimp != INF){
aint[node].minimp += val;
aint[node].maximp += val;
}
if(val % 2 == 1){
swap(aint[node].minimp, aint[node].minpar);
swap(aint[node].maximp, aint[node].maxpar);
}
}
static inline void propagate(int node){
if(lazy[node] > 0){
lazy[2 * node] += lazy[node];
nodeupd(2 * node, lazy[node]);
lazy[2 * node + 1] += lazy[node];
nodeupd(2 * node + 1, lazy[node]);
lazy[node] = 0;
}
}
void build(int node, int st, int dr){
if(st == dr){
int x;
scanf("%lld", &x);
if(x % 2 == 0)
aint[node].minpar = aint[node].maxpar = x;
else
aint[node].minimp = aint[node].maximp = x;
}
else{
int mij = (st + dr) / 2;
build(2 * node, st, mij);
build(2 * node + 1, mij + 1, dr);
aint[node].minpar = min(aint[2 * node].minpar, aint[2 * node + 1].minpar);
aint[node].minimp = min(aint[2 * node].minimp, aint[2 * node + 1].minimp);
aint[node].maxpar = max(aint[2 * node].maxpar, aint[2 * node + 1].maxpar);
aint[node].maximp = max(aint[2 * node].maximp, aint[2 * node + 1].maximp);
}
}
void update(int node, int st, int dr, int l, int r, int val){
if( l <= st && dr <= r ){
lazy[node] += val;
nodeupd(node, val);
}
else{
propagate(node);
int mij = (st + dr) / 2;
if( l <= mij )
update(2 * node, st, mij, l, r, val);
if(r > mij)
update(2 * node + 1, mij + 1, dr, l, r, val);
aint[node].minpar = min(aint[2 * node].minpar, aint[2 * node + 1].minpar);
aint[node].minimp = min(aint[2 * node].minimp, aint[2 * node + 1].minimp);
aint[node].maxpar = max(aint[2 * node].maxpar, aint[2 * node + 1].maxpar);
aint[node].maximp = max(aint[2 * node].maximp, aint[2 * node + 1].maximp);
}
}
void query(int node, int st, int dr, int l, int r){
if( l <= st && dr <= r ){
minipar = min(minipar, aint[node].minpar);
maximpar = max(maximpar, aint[node].maximp);
}
else{
propagate(node);
int mij = (st + dr) / 2;
if( l <= mij )
query(2 * node, st, mij, l, r);
if(r > mij)
query(2 * node + 1, mij + 1, dr, l, r);
}
}
signed main() {
int n, q, i, l, r, val, tip;
scanf("%lld", &n);
for( i = 0; i <= 4 * MAXN; i++ ){
aint[i].minimp = aint[i].minpar = INF;
aint[i].maximp = aint[i].maxpar = -1;
}
build(1, 1, n);
scanf("%lld", &q);
for( i = 0; i < q; i++ ){
scanf("%lld%lld%lld", &tip, &l, &r);
if(tip == 0){
scanf("%lld", &val);
update(1, 1, n, l, r, val);
}
else{
minipar = INF;
maximpar = -1;
query(1, 1, n, l, r);
printf("%lld %lld\n", (minipar == INF ? -1 : minipar), maximpar);
}
}
return 0;
}
Compilation message
subway.cpp: In function 'void build(long long int, long long int, long long int)':
subway.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
subway.cpp: In function 'int main()':
subway.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
subway.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | scanf("%lld", &q);
| ~~~~~^~~~~~~~~~~~
subway.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%lld%lld%lld", &tip, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subway.cpp:99:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf("%lld", &val);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
25692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
28496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
25692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |