/*
صل عل محمد
if (u == Abdel-Aziz Mostafa ) love u <3 ;
دايما احلم ربنا المنان
*/
#include<bits/stdc++.h>
using namespace std;
#define N 300007
//#define mod 1000
#define int long long
#define F first
#define S second
#define item pair< int , int >
struct node{
// description
bool op = 0 ;
int oper =0 ;
item val ;
int lx , rx ; //when you crate the first root nd don't remeber to give it lx ,rx but other ndes take thier lft from up
//intialize nd
node (){
//intialize
oper = 0;
val = {0,0} ;
}
node * lft =NULL , *rght=NULL ; //create my two childs
void extend() //طلعي تشيلدس
{
int md = (lx+rx)/2;
if (lft==NULL){
lft = new node;
lft ->lx =lx;
lft->rx =md;
}
if (rght==NULL){
rght = new node;
rght->lx= md;
rght->rx = rx;
}
}
};
node *root ;
struct segtree{
int sz =1, org ;
segtree(int n){
while(sz<n)sz*=2;
root=new node;
root->lx = 0 ;
root->rx=sz;
root->op = 0;
}
int Neutral_elemnt = 0 ;
item merge(item m1 , item m2 ){
return {max(m1.F,m2.F+m1.S ) , m1.S+m2.S};
}
int operation (int a , int b , bool op){
if (!op)return b;
return b;
}
void apply(int& a ,int b , bool op){
a=operation (a, b ,op);
}
void update(node *nd){
if (nd->oper<0)
nd->val.F=nd->oper;
else
nd->val.F =(nd->rx -nd->lx) *nd->oper;;
nd->val.S = (nd->rx -nd->lx) *nd->oper;
}
void reset (node *nd){
int lx = nd->lx , rx =nd->rx;
if (rx- lx==1){
nd->val = make_pair(0, 0);
if (nd->op)
update(nd) ;
}
else {
if (nd->lft==NULL and nd->rght==NULL){
nd->val = {0 , 0} ;
}
else if (nd->rght==NULL){
nd->val=nd->lft->val;
}
else if (nd->lft==NULL){
nd->val=nd->rght->val;
}
else{
nd->val= merge(nd->lft->val , nd->rght->val) ;
}
if (nd->op)
update(nd) ;
}
}
void propagate(node *nd){
nd->extend();
if (nd->rx-nd->lx==1 || !nd->op)
return ;
apply(nd->lft->oper ,nd->oper , nd->lft->op) ;
apply(nd->rght->oper ,nd->oper , nd->rght->op) ;
nd->lft->op =nd->rght->op=1;
//clear op of node
nd->op= 0 ;
nd->val = {0,0} ;
//////////////////////
reset(nd->lft); //عشان هي جالها تغيرات والمفروض انها مرتبطه بتفيراتها وال تحتيها
reset(nd->rght); //same
reset(nd); //same
////////////////////////////////////////////////////
}
void change (int l , int r,int oper , node* nd){
// x lx rx val[x] oper[x] op[x] = nd || 2*x+1 >> nd->lft
if (nd->rx <=l || nd->lx >=r)
return ;
propagate(nd);
if (nd->lx >=l and nd->rx<=r){
apply( nd->oper, oper , nd->op );
nd->op = 1;
reset(nd) ;
return ;
}
change( l, r, oper, nd->lft);
change (l, r, oper , nd->rght);
nd->val= merge(nd->lft->val , nd->rght->val) ;
}
void change (int l ,int r ,int oper){
change(l,r , oper,root);
}
int cnt_rails(int h , int en , node *nd){
nd->extend();
propagate(nd);
int lx =nd->lx, rx =nd->rx;
if (rx-lx==1){
return (((nd->val.F+en)<=h)?1:0);
}
int sh =en ;
if (nd->val.F+en<=h){
return rx-lx;
}
sh+=nd->lft->val.S;
int md = (lx+rx)/2 ,len =(nd->rx-nd->lx)/2;
if (nd->lft->val.F+en<=h)
return len +cnt_rails(h , sh , nd->rght);
return cnt_rails(h ,en ,nd->lft);
}
int cnt_rails(int h){
return cnt_rails(h,0 , root);
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n ;
cin>>n;
segtree sg(n);
char q;
cin>>q;
sg.change(n , n+1,1e15);
while(q!='E'){
if (q=='Q'){
int h;
cin>>h;
cout<<sg.cnt_rails(h)<<"\n";
}
else {
int l , r , d;
cin>>l>>r>>d;
int st= d ;
l--;
sg.change( l ,r , d);
}
cin>>q;
}
}
LyoKICAg2LXZhCDYudmEINmF2K3ZhdivCiAgIGlmICh1ID09IEFiZGVsLUF6aXogTW9zdGFmYSApICAgbG92ZSB1IDwzIDsKICDYr9in2YrZhdinINin2K3ZhNmFINix2KjZhtinINin2YTZhdmG2KfZhgoKKi8KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgTiAzMDAwMDcKLy8jZGVmaW5lIG1vZCAxMDAwCiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAoKCiNkZWZpbmUgaXRlbSBwYWlyPCBpbnQgLCBpbnQgPgoKc3RydWN0IG5vZGV7CiAgICAgICAgLy8gZGVzY3JpcHRpb24KICAgICAgICBib29sIG9wID0gMCA7CiAgICAgICAgaW50ICBvcGVyID0wIDsKICAgICAgIGl0ZW0gdmFsIDsKCgogICAgICAgIGludCBseCAsIHJ4IDsgICAgICAgICAgICAvL3doZW4geW91IGNyYXRlIHRoZSBmaXJzdCByb290IG5kIGRvbid0IHJlbWViZXIgdG8gZ2l2ZSBpdCBseCAscnggYnV0IG90aGVyIG5kZXMgdGFrZSB0aGllciBsZnQgZnJvbSAgdXAKCgogICAgICAgIC8vaW50aWFsaXplIG5kCiAgICAgICAgbm9kZSAoKXsKICAgICAgICAgICAgICAgIC8vaW50aWFsaXplCiAgICAgICAgICAgICAgICBvcGVyID0gMDsKICAgICAgICAgICAgICAgIHZhbCA9ICB7MCwwfSA7CiAgICAgICAgfQoKICAgICAgICBub2RlICogIGxmdCAgPU5VTEwgICwgKnJnaHQ9TlVMTCAgOyAgIC8vY3JlYXRlIG15IHR3byBjaGlsZHMKICAgICAgICB2b2lkIGV4dGVuZCgpICAgICAgICAgIC8v2LfZhNi52Yog2KrYtNmK2YTYr9izCiAgICAgICAgewoKCiAgICAgICAgICAgICAgICAgICBpbnQgbWQgID0gKGx4K3J4KS8yOwoKICAgICAgICAgICAgICAgICAgIGlmIChsZnQ9PU5VTEwpewogICAgICAgICAgICAgICAgICAgICAgICAgICBsZnQgID0gIG5ldyBub2RlOwogICAgICAgICAgICAgICAgICAgICAgICAgICBsZnQgLT5seCA9bHg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZnQtPnJ4ID1tZDsKICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICBpZiAocmdodD09TlVMTCl7CiAgICAgICAgICAgICAgICAgICAgICAgIHJnaHQgPSBuZXcgbm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgcmdodC0+bHg9IG1kOwogICAgICAgICAgICAgICAgICAgICAgICByZ2h0LT5yeCA9IHJ4OwoKICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgfQoKfTsKbm9kZSAqcm9vdCA7CnN0cnVjdCBzZWd0cmVlewoKCgoKICAgIGludCBzeiA9MSwgb3JnIDsKICAgIHNlZ3RyZWUoaW50IG4pewogICAgICAgIHdoaWxlKHN6PG4pc3oqPTI7CiAgICAgICAgcm9vdD1uZXcgbm9kZTsKICAgICAgICByb290LT5seCA9IDAgOwogICAgICAgIHJvb3QtPnJ4PXN6OwogICAgICAgIHJvb3QtPm9wID0gMDsKCiAgICB9CiAgICBpbnQgTmV1dHJhbF9lbGVtbnQgID0gMCA7CgogICAgaXRlbSBtZXJnZShpdGVtIG0xICAsICBpdGVtIG0yICl7CiAgICAgICAgICByZXR1cm4ge21heChtMS5GLG0yLkYrbTEuUyApICwgbTEuUyttMi5TfTsKCiAgICB9CgogICAgaW50ICBvcGVyYXRpb24gKGludCAgYSAsICBpbnQgYiAsIGJvb2wgb3ApewogICAgICAgIGlmICghb3ApcmV0dXJuIGI7CiAgICAgICByZXR1cm4gYjsKICAgIH0KCiAgICB2b2lkIGFwcGx5KGludCYgYSAsaW50ICBiICwgYm9vbCBvcCl7CiAgICAgICAgICBhPW9wZXJhdGlvbiAoYSwgYiAsb3ApOwogICAgfQogICAgdm9pZCB1cGRhdGUobm9kZSAqbmQpewogICAgICAgICAgaWYgKG5kLT5vcGVyPDApCiAgICAgICAgICAgICAgIG5kLT52YWwuRj1uZC0+b3BlcjsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgbmQtPnZhbC5GID0obmQtPnJ4ICAtbmQtPmx4KSAqbmQtPm9wZXI7OwogICAgICAgICAgbmQtPnZhbC5TID0gIChuZC0+cnggIC1uZC0+bHgpICpuZC0+b3BlcjsKICAgIH0KICAgIHZvaWQgcmVzZXQgKG5vZGUgICpuZCl7CgoKICAgICAgICAgaW50IGx4ID0gbmQtPmx4ICwgcnggPW5kLT5yeDsKCiAgICAgICAgIGlmIChyeC0gbHg9PTEpewogICAgICAgICAgICAgICAgbmQtPnZhbCA9IG1ha2VfcGFpcigwLCAwKTsKICAgICAgICAgICAgIGlmIChuZC0+b3ApCiAgICAgICAgICAgICAgdXBkYXRlKG5kKSA7CiAgICAgICAgIH0KICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIGlmIChuZC0+bGZ0PT1OVUxMICBhbmQgbmQtPnJnaHQ9PU5VTEwpewogICAgICAgICAgICAgICBuZC0+dmFsID0gezAgLCAwfSA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZiAobmQtPnJnaHQ9PU5VTEwpewogICAgICAgICAgICAgICAgbmQtPnZhbD1uZC0+bGZ0LT52YWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZiAobmQtPmxmdD09TlVMTCl7CiAgICAgICAgICAgICAgICAgbmQtPnZhbD1uZC0+cmdodC0+dmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgIG5kLT52YWw9IG1lcmdlKG5kLT5sZnQtPnZhbCAsIG5kLT5yZ2h0LT52YWwpIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAobmQtPm9wKQogICAgICAgICAgICAgIHVwZGF0ZShuZCkgOwogICAgICAgICB9CiAgICB9CiAgICB2b2lkIHByb3BhZ2F0ZShub2RlICpuZCl7CiAgICAgICAgICAgbmQtPmV4dGVuZCgpOwogICAgICAgICAgaWYgKG5kLT5yeC1uZC0+bHg9PTEgfHwgIW5kLT5vcCkKICAgICAgICAgICAgcmV0dXJuICA7CgogICAgICAgICAgYXBwbHkobmQtPmxmdC0+b3BlciAsbmQtPm9wZXIgLCAgbmQtPmxmdC0+b3ApIDsKICAgICAgICAgIGFwcGx5KG5kLT5yZ2h0LT5vcGVyICxuZC0+b3BlciAsICBuZC0+cmdodC0+b3ApIDsKCgogICAgICAgICAgbmQtPmxmdC0+b3AgPW5kLT5yZ2h0LT5vcD0xOwoKICAgICAgICAgIC8vY2xlYXIgb3Agb2Ygbm9kZQogICAgICAgICAgbmQtPm9wPSAwIDsKICAgICAgICAgIG5kLT52YWwgPSB7MCwwfSA7CiAgICAgICAgICAvLy8vLy8vLy8vLy8vLy8vLy8vLy8vCgogICAgICAgICAgcmVzZXQobmQtPmxmdCk7IC8v2LnYtNin2YYg2YfZiiDYrNin2YTZh9inINiq2LrZitix2KfYqiDZiNin2YTZhdmB2LHZiNi2INin2YbZh9inINmF2LHYqtio2LfZhyDYqNiq2YHZitix2KfYqtmH2Kcg2YjYp9mEINiq2K3YqtmK2YfYpwogICAgICAgICAgcmVzZXQobmQtPnJnaHQpOyAvL3NhbWUKICAgICAgICAgIHJlc2V0KG5kKTsgICAgLy9zYW1lCiAgICAgICAgICAvLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vCgoKICAgIH0KCiAgICB2b2lkIGNoYW5nZSAgKGludCAgbCAsIGludCByLGludCBvcGVyICwgbm9kZSogbmQpewoKICAgICAgICAvLyB4IGx4IHJ4IHZhbFt4XSAgb3Blclt4XSAgb3BbeF0gICA9ICBuZCAgfHwgIDIqeCsxID4+IG5kLT5sZnQKCiAgICAgICAgaWYgKG5kLT5yeCA8PWwgfHwgbmQtPmx4ID49cikKICAgICAgICAgICAgcmV0dXJuICA7CgogICAgICAgIHByb3BhZ2F0ZShuZCk7CgogICAgICAgIGlmIChuZC0+bHggPj1sIGFuZCBuZC0+cng8PXIpewogICAgICAgICAgICAgICAgIGFwcGx5KCBuZC0+b3Blciwgb3BlciAsIG5kLT5vcCApOwogICAgICAgICAgICAgICAgIG5kLT5vcCA9IDE7CiAgICAgICAgICAgICAgICAgcmVzZXQobmQpIDsKICAgICAgICAgICAgICAgICByZXR1cm4gOwogICAgICAgIH0KCgogICAgICAgIGNoYW5nZSggbCwgciwgb3BlciwgbmQtPmxmdCk7CiAgICAgICAgY2hhbmdlIChsLCByLCBvcGVyICwgbmQtPnJnaHQpOwogICAgICAgIG5kLT52YWw9IG1lcmdlKG5kLT5sZnQtPnZhbCAsIG5kLT5yZ2h0LT52YWwpIDsKICAgIH0KICAgIHZvaWQgY2hhbmdlIChpbnQgIGwgLGludCByICxpbnQgb3Blcil7CiAgICAgICAgY2hhbmdlKGwsciAsIG9wZXIscm9vdCk7CiAgICB9CgogICAgaW50IGNudF9yYWlscyhpbnQgICBoICAgLCBpbnQgZW4gLCAgICBub2RlICpuZCl7CgogICAgICAgIG5kLT5leHRlbmQoKTsKICAgICAgICBwcm9wYWdhdGUobmQpOwoKCiAgICAgICAgaW50IGx4ICA9bmQtPmx4LCByeCA9bmQtPnJ4OwogICAgICAgIGlmIChyeC1seD09MSl7CiAgICAgICAgICAgIHJldHVybiAoKChuZC0+dmFsLkYrZW4pPD1oKT8xOjApOwogICAgICAgIH0KICAgICAgICBpbnQgc2ggPWVuICA7CgogICAgICAgIGlmIChuZC0+dmFsLkYrZW48PWgpewogICAgICAgICAgICByZXR1cm4gcngtbHg7CiAgICAgICAgfQogICAgICAgIHNoKz1uZC0+bGZ0LT52YWwuUzsKCiAgICAgICAgaW50IG1kICA9ICAobHgrcngpLzIgLGxlbiAgPShuZC0+cngtbmQtPmx4KS8yOwoKICAgICAgICBpZiAobmQtPmxmdC0+dmFsLkYrZW48PWgpCiAgICAgICAgICByZXR1cm4gIGxlbiArY250X3JhaWxzKGggLCBzaCAgLCBuZC0+cmdodCk7CgogICAgICAgIHJldHVybiBjbnRfcmFpbHMoaCAsZW4gLG5kLT5sZnQpOwogICAgfQogICAgaW50IGNudF9yYWlscyhpbnQgaCl7CgogICAgICAgICAgICAgICByZXR1cm4gY250X3JhaWxzKGgsMCAsIHJvb3QpOwogICAgfQoKCgp9OwpzaWduZWQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CgoKICAgIGludCBuIDsKICAgIGNpbj4+bjsKCiAgICBzZWd0cmVlIHNnKG4pOwoKCgoKICAgIGNoYXIgcTsKICAgIGNpbj4+cTsKCiAgIHNnLmNoYW5nZShuICwgbisxLDFlMTUpOwoKICAgIHdoaWxlKHEhPSdFJyl7CgogICAgICAgIGlmIChxPT0nUScpewogICAgICAgICAgICBpbnQgaDsKICAgICAgICAgICAgY2luPj5oOwogICAgICAgICAgICAgY291dDw8c2cuY250X3JhaWxzKGgpPDwiXG4iOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgaW50IGwgICwgciAsIGQ7CiAgICAgICAgICAgIGNpbj4+bD4+cj4+ZDsKICAgICAgICAgICAgaW50IHN0PSBkIDsKICAgICAgICAgICAgbC0tOwogICAgICAgICAgICBzZy5jaGFuZ2UoIGwgLHIgLCBkKTsKICAgICAgICB9CiAgICAgICAgY2luPj5xOwogICAgfQoKfQ==