Hey guys can someone please help me finding error in my code. 12/22 testcase are getting AC and other WA and that also alternate testcases.
Although all testcases of every other rated contest are found on atcoder dropbox but i couldn’t find testcases for Atcder Library Practice contest.
I’m particularly concerned about question J segment tree.
Link for question: segment_tree_practice
Link of my submission:Abhishek’s submission
the code i wrote is this:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 200006
ll t[4*MAXN]; ll nn;
//==========================FOR MAX/MIN==============================//
//\/\/\/\/\--------------for min just change max fn to min---------------------/\/\/\/\/\/\/\/\==============//
//------------array a[], current vertex(v), current index ranges of segment tree tl and tr-------------------------------------//
void mx_build(ll a[], ll v, ll tl, ll tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
ll tm = (tl + tr) / 2;
mx_build(a, v*2, tl, tm);
mx_build(a, v*2+1, tm+1, tr);
t[v] = max(t[v*2],t[v*2+1]);
}
}
//------------------------------query function f max-----------------------------------------//
ll maax(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
ll tm = (tl + tr) / 2;
return max(maax(v*2, tl, tm, l, min(r, tm))
, maax(v*2+1, tm+1, tr, max(l, tm+1), r));
}
//--------------------------update fun of max-------------------------------//
void mx_update(ll v, ll tl, ll tr, ll pos, ll new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
ll tm = (tl + tr) / 2;
if (pos <= tm)
mx_update(v*2, tl, tm, pos, new_val);
else
mx_update(v*2+1, tm+1, tr, pos, new_val);
t[v] = max(t[v*2],t[v*2+1]);
}
}
//-----------------------first number geater than equal to x----------------------------//
ll get_first(ll v, ll lv, ll rv, ll l, ll r, ll x) {
if(lv > r || rv < l) return nn;
if(l <= lv && rv <= r) {
if(t[v] < x) return nn;
while(lv != rv) {
ll mid = lv + (rv-lv)/2;
if(t[2*v] > x) {
v = 2*v;
rv = mid;
}else {
v = 2*v+1;
lv = mid+1;
}
}
return lv;
}
ll mid = lv + (rv-lv)/2;
ll rs = get_first(2*v, lv, mid, l, r, x);
if(rs != nn) return rs;
return get_first(2*v+1, mid+1, rv, l ,r, x);
}
int main(){
fastio;
ll n,q; cin>>n>>q; nn=n;
ll A[n];
FOR(i,0,n){cin>>A[i];}
mx_build(A,1,0,n-1);
ll a,l,r,x;
FOR(i,0,q){
cin>>a;
if(a==1){
cin>>r>>x;
mx_update(1,0,n-1,r-1,x);
}
else if(a==2){
cin>>l>>r;
cout<<maax(1,0,n-1,l-1,r-1)<<"\n";
}
else{
cin>>r>>x;
cout<<get_first(1,0,n-1,r-1,n-1,x)+1LL<<"\n";
}
}
return 0;}

