#P3710. 方方方的数据结构

    ID: 2683 远端评测题 4500ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树平衡树洛谷原创O2优化枚举,暴力块状链表,块状数组,分块洛谷月赛

方方方的数据结构

Description

A long time ago, there was a sequence of length nn, initially all zeros.

Fangfangfang thought the sequence was too monotonous and planned to perform mm operations on it. Each operation is either a range addition or a range multiplication.

After performing some operations, Fangfangfang might also query a certain number.

However, after some operations, Fangfangfang might find that a previous operation was mistaken and needs to undo that operation. The other operations and their relative order remain unchanged.

After planning these operations, Fangfangfang immediately thought of an excellent data structure to maintain them. But he was too lazy to write the solution, so he generated 1010 random testdata and threw this problem to you.

All the testdata are random; see the generator in the hint below.

Input Format

The first line contains two integers n,mn, m, the length of the sequence and the number of operations.

Each of the next mm lines contains 22 or 44 integers.

  1. If the first integer is 11, then three integers l,r,dl, r, d follow, meaning add dd to every number in the range [l,r][l, r].
  2. If the first integer is 22, then three integers l,r,dl, r, d follow, meaning multiply every number in the range [l,r][l, r] by dd.
  3. If the first integer is 33, then one integer pp follows, meaning query the number at position pp mod 998244353\bmod\ 998244353.
  4. If the first integer is 44, then one integer pp follows, meaning undo the operation given on input line pp (guaranteed to be an addition or multiplication; no operation will be undone twice).

Output Format

For each type 33 operation, output one line with the answer.

6 14
1 1 5 1
2 2 4 3
1 2 6 5
3 2
4 1
3 3
2 1 3 4
3 3
1 2 2 3
3 2
4 7
3 1
3 2
3 3
8
5
20
23
0
8
5

Hint

For 20%20\% of the testdata, n,m500n, m \leq 500, time limit 11 s.

For 50%50\% of the testdata, n,m30000n, m \leq 30000, time limit 11 s.

For 100%100\% of the testdata, 1n,m1500001 \leq n, m \leq 150000, 1lrn1 \le l \le r \le n, for type 33 operations 1pn1 \le p \le n, for type 44 operations 1pm1 \le p \le m, 0d10737418230 \leq d \leq 1073741823 (reason shown in the data generator), time limit 4.54.5 s.

Data generator:

#include <bits/stdc++.h>
using namespace std;
int rand_() {return rand()&32767;} 
int br() {return rand_()*32768+rand_();}
vector<int> cs;
int main()
{
    srand(...); //这里要填一个种子 
    int n=...,m=...; //这里要填n、m
    cout<<n<<" "<<m<<"\n";
    for(int i=1;i<=m;i++)
    {
        int o=rand()%4+1;
        if(o<=2)
        {
            cout<<o<<" ";
            int l=br()%n+1,r=br()%n+1;
            if(l>r) swap(l,r); cs.push_back(i);
            cout<<l<<" "<<r<<" "<<br()<<"\n";
        }
        else if(o==3) cout<<o<<" "<<br()%n+1<<"\n";
        else
        {
            if(!cs.size()) {--i; continue;}
            int s=br()%cs.size(),g=cs[s];
            cs.erase(cs.begin()+s);
            cout<<o<<" "<<g<<"\n";
        }
    }
}

Translated by ChatGPT 5