This is the hard version of the problem. The only difference between the versions is the upper bound on $$$n$$$ and $$$m$$$. In this version, $$$n \le 3 \cdot 10^5$$$ and $$$m \le 3 \cdot 10^5$$$.
You have a herd of $$$n$$$ Christmas reindeer. The strength of the $$$i$$$-th reindeer is $$$2^{c_i}$$$.
The carrying capacity of a group of $$$k$$$ Christmas reindeer is calculated as follows:
Note that some reindeer may contribute zero to the carrying capacity of the group.
You have to process queries of three types:
If there are multiple reindeer with the same strength in the herd, they are considered different. For example, if you have two reindeer with strength $$$1$$$ each, and you need to calculate the number of ways to choose a group with carrying capacity of at least $$$1$$$, there are $$$3$$$ ways to choose it: choose the first reindeer, the second reindeer, or both of them.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 3 \cdot 10^5$$$) — the initial number of reindeer in the herd and the number of queries, respectively.
The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$0 \le c_i \le 60$$$) denoting the strengths of the reindeer in the herd: the strength of the $$$i$$$-th reindeer is $$$2^{c_i}$$$.
The next $$$m$$$ lines describe the queries in one of the following formats:
Additional constraint on the input: whenever a query of type $$$2$$$ is given, the herd currently contains at least one reindeer with strength equal to $$$2^x$$$.
For each query of the third type, print a single integer — the number of ways to choose a group of reindeer from the herd (possibly the whole herd) so that the carrying capacity of the chosen group is at least $$$x$$$. Since it can be huge, print it modulo $$$998244353$$$.
3 72 1 13 53 61 23 63 52 13 5
3 0 4 10 4
5 56 9 2 3 53 5181 42 91 103 1016
12 32
5 2056 58 31 56 573 5841336999156136981 263 7189345176981336441 433 8537955255658039343 3711289078856020071 541 253 122834517782167712 253 2698374054237693401 03 813328844310754681 233 42569849624440223 6684080039827661023 9234102226533745503 3403137432353114153 5501662824407757693 445344499963496530
0 0 0 24 496 128 416 992 0 0 320 0 0
Let's consider the first example. Initially, there are three reindeer with strength equal to $$$4$$$, $$$2$$$ and $$$2$$$, respectively.
| Name |
|---|


