Score : 400400 points
You are given a sequence A = (A_1, A_2, \dots, A_N)A=(A1,A2,…,AN) of length NN.
Given QQ queries, process all of them in order. The qq-th (1\leq q\leq Q)(1≤q≤Q) query is in one of the following three formats, which represents the following queries:
The input is given from Standard Input in the following format:
NN
A_1A1 A_2A2 \dots… A_NAN
QQ
\operatorname{query}_1query1
\operatorname{query}_2query2
\vdots⋮
\operatorname{query}_QqueryQ
Here, \operatorname{query}_qqueryq denotes the qq-th query, which is in one of following formats: 1 x, 2 i x, and 3 i.
Print XX lines, where XX is the number of qq's (1\leq q\leq Q)(1≤q≤Q) such that \operatorname{query}_qqueryq is in the third format. The jj-th (1\leq j\leq X)(1≤j≤X) line should contain the answer to the jj-th such query.
Copy
5 3 1 4 1 5 6 3 2 2 3 4 3 3 1 1 2 3 4 3 3
Copy
1 8 5
Initially, A=(3,1,4,1,5)A=(3,1,4,1,5). The queries are processed as follows:
Copy
1 1000000000 8 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 3 1
Copy
8000000000
Note that the elements of AA may not fit into a 3232-bit integer type.
Copy
10 1 8 4 15 7 5 7 5 8 0 20 2 7 0 3 7 3 8 1 7 3 3 2 4 4 2 4 9 2 10 5 1 10 2 4 2 1 10 2 3 1 2 8 11 2 3 14 2 1 9 3 8 3 8 3 1 2 6 5 3 7
Copy
7 5 7 21 21 19 10
- #include
-
- #include
- #include
- using namespace std;
-
- const int N = 2e5 + 5;
- map<int,pair<int, unsigned long long>> m;
- long long tag=0,ti=0;
-
- int main()
- {
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- long long e;
- cin >>e;
- m[i].first = 0;
- m[i].second = e;
- }
- int q;
- cin >> q;
- int t;
- for (int i = 1; i <= q; i++)
- {
- cin >> t;
- if (t == 1)
- {
- cin >> tag;
- ti = i;//tag最近的更新操作是第ti次
- }
- else if (t == 2)
- {
- unsigned long long o, x;
- cin >> o >> x;
- if(m[o].first
- m[o].second = x;
- else//如果tag更新的操作在上一次给m[o]加值之后,则在上次值后加值
- m[o].second += x;
- m[o].first = i;
-
-
- }
- else if (t == 3)
- {
- int p;
- cin >> p;
- if (m[p].first < ti)
- {
- cout << tag << endl;
- }
- else
- {
- cout << tag + m[p].second << endl;
- }
-
- }
- }
-
- }