Problem:
B: AddMulSubDiv
Problem Statement
You have an array
A
of
N
integers.
A_i
denotes the
i
-th element of
A
.
You have to process one of the following queries
Q
times:
Query 1: The query consists of non-negative integer
x
, and two positive integers
s, t
. For all the elements
greater
than or equal to
x
in
A
, you have to add
s
to the elements, and then multiply them by
t
. That is, an element with
v (v \geq x)
becomes
t(v + s)
after this query.
Query 2: The query consists of non-negative integer
x
, and two positive integers
s, t
. For all the elements
less
than or equal to
x
in
A
, you have to subtract
s
from the elements, and then divide them by
t
. If the result is not an integer, you truncate it towards zero. That is, an element with
v (v \leq x)
becomes $\mathrm{trunc}$
( \frac{v - s}{t} )
after this query, where $\mathrm{trunc}$
( y )
is the integer obtained by truncating
y
towards zero.
"Truncating towards zero" means converting a decimal number to an integer so that if
x = 0.0
then
0
, otherwise an integer whose absolute value is the maximum integer no more than
|x|
and whose sign is same as
x
. For example, truncating
3.5
towards zero is
3
, and truncating
-2.8
towards zero is
-2
.
After applying
Q
queries one by one, how many elements in
A
are no less than
L
and no more than
R
?
Input
N
Q
L
R
A_1
A_2
...
A_N
q_1
x_1
s_1
t_1
:
q_Q
x_Q
s_Q
t_Q
The first line contains four integers
N
,
Q
,
L
, and
R
.
N
is the number of elements in an integer array
A
,
Q
is the number of queries, and
L
and
R
specify the range of integers you want to count within after the queries.
The second line consists of
N
integers, the
i
-th of which is the
i
-th element of
A
.
The following
Q
lines represent information of queries. The
j
-th line of them corresponds to the
j
-th query and consists of four integers
q_j
,
x_j
,
s_j
, and
t_j
.  Here,
q_j = 1
stands for the
j
-th query is Query 1, and
q_j = 2
stands for the
j
-th query is Query 2.
x_j
,
s_j
, and
t_j
are parameters used for the
j
-th query.
Constraints
1 \leq N \leq 2 \times 10^5
1 \leq Q \leq 2 \times 10^5
-2^{63} < L \leq R < 2^{63}
0 \leq |A_i| \leq 10^9
q_j \in \{ 1, 2 \}
0 \leq x_j < 2^{63}
1 \leq s_j, t_j \leq 10^9
Inputs consist only of integers.
The absolute value of any element in the array dosen't exceed
2^{63}
at any point during query processing.
Output
Output the number of elements in
A
that are no less than
L
and no more than
R
after processing all given queries in one line.
Sample Input 1
3 3 3 10
1 -2 3
1 2 2 3
2 20 1 3
2 1 20 5
Output for Sample Input 1
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n, q, l, r;
    cin >> n >> q >> l >> r;
    vector<ll> a(n);
    for (auto& x : a) cin >> x;
    vector<array<ll, 4>> query(q);
    for (auto& x : query)
        cin >> x[0] >> x[1] >> x[2] >> x[3];

    sort(a.begin(), a.end());
    ll rp = -1, rq = n;
    while (rq - rp > 1) {
        ll mid = (rp + rq) / 2;
        ll now = a[mid];
        for (auto [typ, x, s, t] : query) {
            if (typ == 1) {
                if (now >= x) {
                    now += s;
                    now *= t;
                }
            } else {
                if (now <= x) {
                    now -= s;
                    now /= t;
                }
            }
        }
        (now <= r ? rp : rq) = mid;
    }

    ll lp = -1, lq = n;
    while (lq - lp > 1) {
        ll mid = (lp + lq) / 2;
        ll now = a[mid];
        for (auto [typ, x, s, t] : query) {
            if (typ == 1) {
                if (now >= x) {
                    now += s;
                    now *= t;
                }
            } else {
                if (now <= x) {
                    now -= s;
                    now /= t;
                }
            }
        }
        (now >= l ? lq : lp) = mid;
    }
    cout << rp - lp << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 11044
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)n; ++i)

ll binary_search(const vector<ll>& a){
    return 0;
}

int main() {
    ll n, q, L, R;
    cin >> n >> q >> L >> R;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<ll> mode(q), x(q), s(q), t(q);
    rep(i, q){
        cin >> mode[i] >> x[i] >> s[i] >> t[i];
    }
    // 答えがL以上になる最小のiを見つける
    ll left = -1, right = n;
    while(right - left > 1){
        ll mid = (left + right) / 2;

        ll ans = a[mid];
        if (0 <= mid && mid < n) {
            rep(i, q){
                if(mode[i] == 1){
                    if(ans < x[i])continue;
                    ans = (ans + s[i]) * t[i];
                }else if(mode[i] == 2){
                    if(ans > x[i])continue;
                    ans = (ans - s[i]) / t[i];
                }
            }
        }
        else {
            if (mid == n) ans = (1LL << 63) + 1;
        }

        if(ans < L || mid == -1){
            left = mid;
        }else{
            right = mid;
        }
    }
    ll leftans = right;

    // 答えがR以下になる最大のiを見つける
    left = -1, right = n;
    while(right - left > 1){
        ll mid = (left + right) / 2;

        ll ans = a[mid];
        if (0 <= mid && mid < n) {
            rep(i, q){
                if(mode[i] == 1){
                    if(ans < x[i])continue;
                    ans = (ans + s[i]) * t[i];
                }else if(mode[i] == 2){
                    if(ans > x[i])continue;
                    ans = (ans - s[i]) / t[i];
                }
            }
        }
        else {
            if (mid == n) ans = (1LL << 63) + 1;
        }

        if(ans <= R || mid == -1){
            left = mid;
        }else{
            right = mid;
        }
    }
    ll rightans = left;

    cout << rightans - leftans + 1 << endl;
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 10676
final_rank: 14

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}

struct e{
  ll q,x,s,t;
};

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  ll n,Q,L,R;cin >> n >> Q >> L >> R;
  vi a(n);cin >> a;
  sort(ALL(a));
  vector<e> qry(Q);
  rep(i,0,Q)cin >> qry[i].q >> qry[i].x >> qry[i].s >> qry[i].t;
  auto lb = [&](ll val){
    ll l = -1,r = n;
    while(r-l > 1){
      ll md = (l + r)/2;
      ll k = a[md];
      rep(i,0,Q){
        auto [q,x,s,t] = qry[i];
        if(q == 1){
          if(k >= x)k = (k + s)*t;
        }else{
          if(k <= x)k = (k-s)/t;
        }
      }
      if(k >= val)r = md;
      else l = md;
    }
    return r;
  };
  cout << lb(R+1)-lb(L) << endl;
  

  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 10572
final_rank: 5

code_snippet: #include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{int q,x,s,t;}q[200005];
int n,m,l,r,r1=0,r2=0,a[200005];
inline bool cmp(int x,int y) {return x>y;}
signed main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&l,&r);
	for(int i=1;i<=n;i++) scanf("%lld",a+i);
	sort(a+1,a+n+1,cmp),a[0]=2000000000,a[n+1]=-2000000000;
	for(int i=1;i<=m;i++) scanf("%lld%lld%lld%lld",&q[i].q,&q[i].x,&q[i].s,&q[i].t);
	int dl=0,dr=n+1;
	while(dl<=dr)
	{
		int mid=(dl+dr)>>1,x=a[mid];
		for(int i=1;i<=m;i++)
		{
			if(q[i].q==1&&x>=q[i].x) x=(x+q[i].s)*q[i].t;
			if(q[i].q==2&&x<=q[i].x) x=(x-q[i].s)/q[i].t;
		}
		if(x>=l) r1=dl,dl=mid+1;else dr=mid-1;
	}
	dl=0,dr=n+1,r1=min(r1,n);
	while(dl<=dr)
	{
		int mid=(dl+dr)>>1,x=a[mid];
		for(int i=1;i<=m;i++)
		{
			if(q[i].q==1&&x>=q[i].x) x=(x+q[i].s)*q[i].t;
			if(q[i].q==2&&x<=q[i].x) x=(x-q[i].s)/q[i].t;
		}
		if(x<=r) r2=dl,dr=mid-1;else dl=mid+1;
	}
	return r2=min(n-r2+1,n),printf("%lld\n",r1+r2-n),0;
}
accuracy: 0.3870967741935484
time_ms: 80
memory_kb: 10792
final_rank: 19

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"


#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa

#include <cmath>
#include <functional>
#include <type_traits>

namespace zawa {

namespace internal {

template <class T>
T MidPoint(T a, T b) {
    if (a > b) std::swap(a, b);
    return a + ((b - a) >> 1);
}

template <class T>
T Abs(T a, T b) {
    return (a >= b ? a - b : b - a);
}

} // namespace zawa::internal

template <class T, class Function>
T BinarySearch(T ok, T ng, const Function& f) {
    static_assert(std::is_integral_v<T>, "T must be integral type");
    static_assert(std::is_convertible_v<Function, std::function<bool(T)>>, "f must be function bool(T)");
    while (internal::Abs(ok, ng) > 1) {
        T mid{ internal::MidPoint(ok, ng) };
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template <class T, class Function>
T BinarySearch(T ok, T ng, const Function& f, u32 upperLimit) {
    static_assert(std::is_signed_v<T>, "T must be signed arithmetic type");
    static_assert(std::is_convertible_v<Function, std::function<bool(T)>>, "f must be function bool(T)");
    for (u32 _{} ; _ < upperLimit ; _++) {
        T mid{ (ok + ng) / (T)2 };
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

} // namespace zawa
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, Q, TYPE[200020];
long long L, R, A[200020], X[200020], S[200020], T[200020];
static const long long MAX = std::numeric_limits<long long>::max(); // 2^63-1
static const long long MIN = std::numeric_limits<long long>::min() + 1; // -(2^63-1)
bool is_lower(const int idx, const long long t, const bool strictly) {
    assert(-1 <= idx and idx <= N);
    if (idx == -1) return true;
    if (idx == N) return false;
    long long v = A[idx];
    bool big = false, sm = false;
    for (int i = 0 ; !big and !sm and i < Q ; i++) {
        if (TYPE[i] == 1) {
            if (v < X[i]) continue; 
            big |= v > MAX - S[i];
            v += S[i];
            big |= v > MAX / T[i];
            v *= T[i];
        }
        else if (TYPE[i] == 2) {
            if (X[i] < v) continue;
            sm |= v < MIN + S[i];
            v = (v - S[i]) / T[i];
        }
        else assert(false);
    }
    if (big and sm) assert(false);
    if (big) return false;
    if (sm) return true;
    if (strictly) return v < t;
    else return v <= t;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> Q >> L >> R;
    for (int i = 0 ; i < N ; i++) std::cin >> A[i];
    ranges::sort(A, A + N);
    for (int i = 0 ; i < Q ; i++) std::cin >> TYPE[i] >> X[i] >> S[i] >> T[i];
    int ans = 0;
    ans += BinarySearch(-1, N, [&](int i) { return is_lower(i, R, false); });
    ans -= BinarySearch(-1, N, [&](int i) { return is_lower(i, L, true); });
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 70
memory_kb: 10464
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,s,t) for(ll i=s;i<t;i++)
#define all(A) A.begin(),A.end()
using ll=long long;

ll f(ll x,vector<array<ll,4>>&query){
  for(auto q:query){
    if(q[0]==1){
      if(x>=q[1])x=q[3]*(x+q[2]);
    }
    else{
      if(x<=q[1])x=(x-q[2])/q[3];
    }
  }
  return x;
}

ll calc(vector<ll> &A,vector<array<ll,4>>&query,ll X){
  ll N=A.size();
  ll L=-1,R=N;
  while(R-L>1){
    ll mid=(R+L)/2;
    if(f(A[mid],query)<=X)L=mid;
    else R=mid;
  }
  return L;
}

int main(){
    
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N,Q,L,R;
    cin>>N>>Q>>L>>R;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    sort(all(A));
    vector<array<ll,4>> query(Q);
    rep(q,Q)rep(d,4)cin>>query[q][d];
    cout<<calc(A,query,R)-calc(A,query,L-1)<<endl;
    
}
accuracy: 1
time_ms: 90
memory_kb: 10528
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1ll*1e17;
const ll N=300010;
ll n,q,l,r;
ll a[N],ty[N],s[N],t[N],x[N];
bool check(ll mid,ll maxn){
	ll tmp=a[mid];
	for(ll i=1;i<=q;i++){
		if(ty[i]==1&&tmp>=x[i]) tmp=(tmp+s[i])*t[i];
		else if(ty[i]==2&&tmp<=x[i]) tmp=(tmp-s[i])/t[i];
	}
	return tmp<=maxn;
}
ll bound(ll maxn){
	ll L=1LL,R=n,mid,ans=0;
	while(L<=R){
		mid=(L+R)>>1;
		if(check(mid,maxn)) L=mid+1,ans=mid;
		else R=mid-1;
	}
	return ans;
}
int main(){
	scanf("%lld%lld%lld%lld",&n,&q,&l,&r);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(ll i=1;i<=q;i++) scanf("%lld%lld%lld%lld",&ty[i],&x[i],&s[i],&t[i]);
	printf("%lld\n",bound(r)-bound(l-1)); 
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 13880
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct node{
	int q,s,t;
    long long x;
}q[N];
int n,Q;
long long L,R;
int a[N];
long long check(int k){
	long long v = a[k];
	for(int i=1;i<=Q;i++){
		if(q[i].q==1 && v>=q[i].x)
	        v = (v+q[i].s)*q[i].t;
        else if(q[i].q == 2 && v <= q[i].x){
			if(a<0) v=-((-(v-q[i].s))/q[i].t);
			else v=(v-q[i].s)/q[i].t;
        }
	}
	return v;
}
int work1(){
    int l=1,r=n;
    while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)>=L) r=mid-1;
		else l=mid+1;
    }
	return l;
}
int work2(){
    int l=1,r=n;
    while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)<=R) l=mid+1;
		else r=mid-1;
    }
	return r;
}
int main(){
	scanf("%d%d%lld%lld",&n,&Q,&L,&R);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1,k,s,t;i<=Q;i++)
		scanf("%d%lld%d%d",&q[i].q,&q[i].x,&q[i].s,&q[i].t);
	int l=work1(),r=work2();
	if(l<=r)
        printf("%d\n",r-l+1);
	else 
        puts("0");
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 8804
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
long long n, m, p, q, res, a[200005];
struct node {
	long long opt, x, s, t;
}b[200005];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> p >> q;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= m; i++)
		cin >> b[i].opt >> b[i].x >> b[i].s >> b[i].t;
	int l = 0, r = n + 1;
	while(l + 1 < r) {
		long long mid = l + r >> 1, x = a[mid];
		for(int i = 1; i <= m; i++)
			if(b[i].opt & 1) {
				if(x >= b[i].x)
					x = (x + b[i].s) * b[i].t;
			}
			else if(x <= b[i].x)
				x = (x - b[i].s) / b[i].t;
		if(x >= p)
			r = mid;
		else
			l = mid;
	}
	res = r, l = 0, r = n + 1;
	while(l + 1 < r) {
		long long mid = l + r >> 1, x = a[mid];
		for(int i = 1; i <= m; i++)
			if(b[i].opt & 1) {
				if(x >= b[i].x)
					x = (x + b[i].s) * b[i].t;
			}
			else if(x <= b[i].x)
				x = (x - b[i].s) / b[i].t;
		if(x <= q)
			l = mid;
		else
			r = mid;
	}
	cout << max(0ll, l - res + 1) << '\n';
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 11120
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

ll Query(int Type, ll X, ll S, ll T, ll A) {
    if (Type == 1) {
        return (X <= A ? (A+S)*T : A);
    }
    if (Type == 2) {
        if (X<A) return A;
        A -= S;
        if (A >= 0) return A/T;
        else return -((-A)/T);
    }
    return 0;
}

int main() {
    int N, Q;
    ll L, R;
    cin >> N >> Q >> L >> R;
    vector<ll> A(N);
    rep(i,0,N) cin >> A[i];
    sort(ALL(A));
    vector<int> Type(Q);
    vector<ll> X(Q), S(Q), T(Q);
    rep(i,0,Q) cin >> Type[i] >> X[i] >> S[i] >> T[i];
    int NG = -1, OK = N;
    while(OK-NG > 1) {
        int MID = (OK+NG)/2;
        ll Cur = A[MID];
        rep(i,0,Q) Cur = Query(Type[i],X[i],S[i],T[i],Cur);
        if (Cur >= L) OK = MID;
        else NG = MID;
    }
    int AL = OK;
    OK = -1, NG = N;
    while(NG-OK > 1) {
        int MID = (OK+NG)/2;
        ll Cur = A[MID];
        rep(i,0,Q) Cur = Query(Type[i],X[i],S[i],T[i],Cur);
        if (Cur <= R) OK = MID;
        else NG = MID;
    }
    int AR = OK;
    cout << AR-AL+1 << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 9996
final_rank: 15

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int N = in(), Q = in(); i128 L = in(), R = in();
    vector<i128> A = in(N);
    sort(A);
    vector<tuple<int,i128,i128,i128>> query(Q);
    for(auto& [q, x, s, t] : query) q = in(), x = in(), s = in(), t = in();

    A.insert(A.begin(), {-(i128(1) << 63)});
    A.insert(A.end  (), {+(i128(1) << 63)});
    auto get_value = [&](int i) {
        if(i == 0 or i == N + 1) return A[i];
        assert(1 <= i and i <= N);
        i128 v = A[i];
        for(auto [q, x, s, t] : query) {
            if(q == 1) {
                if(v >= x) v = (v + s) * t;
            } else {
                if(v <= x) v = (v - s) / t;
            }
        }
        return v;
    };

    int li = bin_search<int>(N + 1, 0, [&](int i) { return L <= get_value(i); });
    int ri = bin_search<int>(0, N + 1, [&](int i) { return get_value(i) <= R; });
    print(ri - li + 1);
}
accuracy: 1
time_ms: 100
memory_kb: 22720
final_rank: 18

code_snippet: #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef RUTHEN_LOCAL
#include <debug.hpp>
#else
#define show(x) true
#endif

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long N, Q, L, R;
    cin >> N >> Q >> L >> R;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    vector<tuple<int, long long, long long, long long>> query(Q);
    REP(i, Q) {
        int q;
        long long x, s, t;
        cin >> q >> x >> s >> t;
        query[i] = {q, x, s, t};
    }
    auto apply = [&](long long v) -> long long {
        for (auto& [q, x, s, t] : query) {
            if (q == 1) {
                if (v >= x) {
                    v = (v + s) * t;
                }
            }
            if (q == 2) {
                if (v <= x) {
                    v = (v - s) / t;
                }
            }
        }
        return v;
    };
    int l, r;
    {
        // min i s.t. op(A[i]) > R
        int ok = N - 1, ng = -1;
        while (ok - ng > 1) {
            int i = (ok + ng) / 2;
            if (apply(A[i]) > R) {
                ok = i;
            } else {
                ng = i;
            }
        }
        if (apply(A[ok]) <= R) {
            assert(ok == N - 1);
            r = ok + 1;
        } else {
            r = ok;
        }
    }
    {
        // max i s.t. op(A[i]) < L
        int ok = 0, ng = N;
        while (ng - ok > 1) {
            int i = (ok + ng) / 2;
            if (apply(A[i]) < L) {
                ok = i;
            } else {
                ng = i;
            }
        }
        if (apply(A[ok]) >= L) {
            assert(ok == 0);
            l = ok - 1;
        } else {
            l = ok;
        }
    }
    cout << r - l - 1 << '\n';
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 10588
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    ll L,R; cin >> L >> R;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> q(m);
    vector<ll> x(m),s(m),t(m);
    for (int i = 0; i < m; ++i) {
        cin >> q[i] >> x[i] >> s[i] >> t[i];
    }
    // u以下になる場合
    auto solve = [&](ll u)->int{
        int l = -1, r = n;
        while(r-l>1){
            int mid = (l+r)/2;
            ll cur = a[mid];
            for (int i = 0; i < m; ++i) {
                if(q[i] == 1){
                    if(cur >= x[i]){
                        cur = t[i]*(cur+s[i]);
                    }
                }
                else{
                    if(cur <= x[i]){
                        cur = (cur-s[i])/t[i];
                    }
                }
            }
            if(cur <= u) l = mid;
            else r = mid;
        }
        return l+1;
    };
    int ans = solve(R);
    if(L != (1LL<<63)){
        ans -= solve(L-1);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 9960
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, Q, L, R;
ll A[200500];
ll q[205000], x[200500], s[200050], t[200050];

ll f(ll now) {
    for(int i = 1; i <= Q; i++) {
        if(q[i] == 1) {
            if(now >= x[i]) {
                now = t[i] * (now + s[i]);
            }
        } else {
            if(now <= x[i]) {
                now = (now - s[i]) / t[i];
            }
        }
    }
    return now;
}

int main() {
    cin >> N >> Q >> L >> R;
    for(int i = 1; i <= N; i++) cin >> A[i];
    for(int i = 1; i <= Q; i++) {
        cin >> q[i] >> x[i] >> s[i] >> t[i];
    }
    ll overok = 1e9+1;
    ll overng = -1e9-1;
    ll underok = -1e9-1;
    ll underng = 1e9+1;
    while(overok - overng > 1) {
        ll mid = (overok + overng) / 2;
        ll tmp = f(mid);
        if(tmp > R) overok = mid;
        else overng = mid;
    }
    while(underng - underok > 1) {
        ll mid = (underok + underng) / 2;
        ll tmp = f(mid);
        if(tmp < L) underok = mid;
        else underng = mid;
    }
    //cerr << overok << " " << underok << endl;
//    cerr << f(overok) << " " << f(overng) << endl;
//    cerr << f(underok) << " " << f(underng) << endl;
    ll ans = 0;
    for(int i = 1; i <= N; i++) {
        if(A[i] < overok && A[i] > underok) {
            ans++;
            //cerr << i << endl;
        }
        //cerr << f(A[i]) << endl;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 240
memory_kb: 11072
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;

using Int = long long;
using ll = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,q,l,r;
  cin>>n>>q>>l>>r;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  vector<Int> qs(q),xs(q),ss(q),ts(q);
  for(Int i=0;i<q;i++) cin>>qs[i]>>xs[i]>>ss[i]>>ts[i];

  sort(as.begin(),as.end());

  // number of elements whose value is no more than d
  auto calc=
    [&](Int d)->Int{
      auto check=
        [&](Int a)->Int{
          for(Int i=0;i<q;i++){
            if(qs[i]==1){
              if(a>=xs[i]) a=ts[i]*(a+ss[i]);
            }else{
              if(a<=xs[i]) a=(a-ss[i])/ts[i];
            }
          }
          return a<=d;
        };
      Int L=-1,R=n;
      while(L+1<R){
        Int M=(L+R)>>1;
        if(check(as[M])) L=M;
        else R=M;
      }
      return R;
    };
  Int ans=calc(r)-(l==LLONG_MIN?0:calc(l-1));
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 10632
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
//define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#    define debug(x) cout << #    x << '\t' << x << endl
#else
#    define debug(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0)
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
#define lowbit(x) ((x) & -(x))
#define mem(a, b) memset(a, b, sizeof(a))
#define PI acos(-1)
#define endl '\n'
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define int long long
//ll gcd(ll a, ll b){a = abs(a);b = abs(b);return a == 0 ? b : gcd(b % a, a);}
//inline ll mul(ll x, ll y, ll mod) { return x * y - (ll)((long double)x / mod * y) * mod; }
//inline ll Pow(ll a, ll n, ll mod){ll t = 1;while (n > 0){if (n & 1)t = mul(t, a, mod);a = mul(a, a, mod), n >>= 1;}return t;}
const int maxn = 2e5+100;
int a[maxn];
int s[maxn], t[maxn], q[maxn], x[maxn];
int n,Q,l,r;
ll check(ll v){
    for(int i=0; i<Q; ++i){
        if(q[i]==1){
            if(v>=x[i]){
                v = (v+s[i])*t[i];
            }
        }else{
            if(v<=x[i]){
                v = (v-s[i])/t[i];
            }
        }
    }
    return v;
}

int solve(ll x){
    int l=0, r = n-1, ans=-1;
    //if(check(a[r]<=x)) return r;
    while(l<=r){
        int mid = l+r>>1;
        if(check(a[mid]) <= x){
            ans = mid;
            l = mid+1;
        }else{
            r = mid-1;
        }
    }
    return ans+1;
}
signed main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
    fast;
    
    cin>>n>>Q>>l>>r;
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> q[i] >> x[i] >> s[i] >> t[i];
    }
    sort(a, a+n);
    cout << solve(r) - solve(l-1) <<"\n";

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 10808
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0)
#define int long long
const int maxn = 2e5+100;
int a[maxn];
int s[maxn], t[maxn], tp[maxn], x[maxn];
int n,Q,l,r;
ll ca(ll b) {
	for (int j = 0; j < Q; j++) {
		if (tp[j] == 1 && b >= x[j])
			b = (b + s[j]) * t[j];
		if (tp[j] == 2 && b <= x[j])
			b = (b - s[j]) / t[j];
	}
	return b;
}
ll cal(ll k) {
	// 多少个 <= k 
	int l = 0, r = n - 1;
	if (ca(a[r]) <= k) return n; 
	while (l < r) {
		int mid = (l + r) >> 1;
		if (ca(a[mid]) > k) r = mid;
		else l = mid + 1;
	}
	return l;
}

signed main()
{
#ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
    fast;
    ll tmp = 0;
    cin>>n>>Q>>l>>r;
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> tp[i] >> x[i] >> s[i] >> t[i];
    }
    sort(a, a+n);
    cout << cal(r) - cal(l-1) <<"\n";

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 10808
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll L, R;
int n, q;
ll a[maxn];
ll tp[maxn], s[maxn], x[maxn], t[maxn];
ll ca(ll b) {
	for (int j = 0; j < q; j++) {
		if (tp[j] == 1 && b >= x[j])
			b = (b + s[j]) * t[j];
		if (tp[j] == 2 && b <= x[j])
			b = (b - s[j]) / t[j];
	}
	return b;
}
ll cal(ll k) {
	// 多少个 <= k 
	int l = 0, r = n - 1;
	if (ca(a[r]) <= k) return n; 
	while (l < r) {
		int mid = (l + r) >> 1;
		if (ca(a[mid]) > k) r = mid;
		else l = mid + 1;
	}
	return l;
}
int main() {
	cin >> n >> q >> L >> R;
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sort(a, a + n);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld%lld%lld", &tp[i], &x[i], &s[i], &t[i]);
	}
	ll ans = cal(R) - cal(L - 1);
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 10856
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using std::sort;using std::lower_bound;using std::upper_bound;
#define int long long
int n,m,L,R,q[100001],x[1000001],s[100001],t[100001],a[100001],b[100001];
void fix(int &_x){
	for(int i=1;i<=m;i++){
		if(q[i]==1)if(_x>=x[i])_x=(_x+s[i])*t[i];
		if(q[i]==2)if(_x<=x[i])_x=(_x-s[i])/t[i];
	}
}
signed main() {
	scanf("%lld%lld%lld%lld",&n,&m,&L,&R);
	for(int i=1;i<=n;i++)scanf("%lld",a+i);
	for(int i=1;i<=m;i++)scanf("%lld%lld%lld%lld",q+i,x+i,s+i,t+i);
	for(int i=1;i<=n;i++)fix(a[i]);
	sort(a+1,a+1+n);
	//for(int i=1;i<=n;i++)printf("%lld ",a[i]);
	printf("%lld\n",upper_bound(a+1,a+1+n,R)-lower_bound(a+1,a+1+n,L));
	return 0;
}
accuracy: 0.3548387096774194
time_ms: 40
memory_kb: 7056
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1000005;
int a[maxn],b[maxn],opt[maxn],limit[maxn],x[maxn],y[maxn],L,R,n,m;
int check(int mid)
{
//	cout<<mid<<" "<<a[mid]<<" ";
	int now=a[mid];
	for(int i=1;i<=m;i++)
	{
		if(opt[i]==1)
		{
			if(now>=limit[i])now=(now+x[i])*y[i];
		}
		else if(now<=limit[i])now=(now-x[i])/y[i];	
	}
	
//	cout<<now<<endl;
	return now;
}
signed main()
{
	cin>>n>>m>>L>>R;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>opt[i]>>limit[i]>>x[i]>>y[i];
	sort(a+1,a+1+n);
	int l=1,r=n,ans1=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)<=R)ans1=mid,l=mid+1;
		else r=mid-1; 
	} 
//	cout<<ans1<<endl;
	l=1,r=n;int ans2=n+1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)>=L)ans2=mid,r=mid-1;
		else l=mid+1; 
	} //cout<<ans2<<endl;
	cout<<ans1-ans2+1<<endl;
	
}
/*
3 3 3 10
1 -2 3
1 2 2 3
2 20 1 3
2 1 20 5
首先那些不构成约束的边直接就是2^k/2，随便取，然后有一半的概率是不合法的
对于有约束的边就看下约束
每次枚举一个点，然后开始检查所有边 
 
 */
accuracy: 1
time_ms: 270
memory_kb: 10764
final_rank: 17