#P3710. 方方方的数据结构
方方方的数据结构
Description
A long time ago, there was a sequence of length , initially all zeros.
Fangfangfang thought the sequence was too monotonous and planned to perform 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 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 , the length of the sequence and the number of operations.
Each of the next lines contains or integers.
- If the first integer is , then three integers follow, meaning add to every number in the range .
- If the first integer is , then three integers follow, meaning multiply every number in the range by .
- If the first integer is , then one integer follows, meaning query the number at position .
- If the first integer is , then one integer follows, meaning undo the operation given on input line (guaranteed to be an addition or multiplication; no operation will be undone twice).
Output Format
For each type 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 of the testdata, , time limit s.
For of the testdata, , time limit s.
For of the testdata, , , for type operations , for type operations , (reason shown in the data generator), time limit 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
京公网安备 11011102002149号