D - All Assign Point Add Editorial by llichenyu


English:

We can solve this problem by using time tags.

We can maintain the time tags for every assign operation.

If we want to ask or change a single position,we only need to compare the time tag.

Chinese:

我们可以用时间戳解决这个问题。

给每个全局修改操作打个标记,每次修改比较一下时间即可。

Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int const N=1e6+10;
int a[N],xx[N];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n;cin>>n;
    for (int i=1;i<=n;++i) cin>>a[i];
    int qj=0,q;cin>>q;int qtim=0;
    for (int i=1;i<=q;++i){
        int opt;cin>>opt;
        if (opt==1){
            int x;cin>>x;qj=x;
            qtim=i;
        }else if (opt==2){
            int x,y;cin>>x>>y;
            if (xx[x]<qtim){
                a[x]=qj;
                xx[x]=qtim;
            }
            a[x]+=y;
        }else{
            int x;cin>>x;
            if (xx[x]<qtim){
                a[x]=qj;
                xx[x]=qtim;
            }
            cout<<a[x]<<'\n';
        }
    }
    return 0;
}

posted:
last update: