1 solutions

  • 0
    @ 2023-11-23 20:55:41
    #include <bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    ll a[100000005] , b[100000005];
    struct get{
    	ll x;
    	ll y;
    }pp[10005];
    void add(ll a[] , ll b[] , ll x , ll y , ll n){//a,b是指数组,x是第几个数插入,y是插入者为什么,n是原来的数字个数 。 
    		for(ll i = 1 ;i <= n + 1 ;i++){
    			if(i < x + 1){
    				b[i] = a[i];
    			}else if(i == x + 1){
    				b[i] = y;
    			}else if(i > x + 1){
    				b[i] = a[i-1];
    			}
    		}
    		for(ll i = 1 ;i <= n + 1 ;i++){
    			a[i] = b[i];
    		}
    }
    int main()
    {
        ll n;
    	cin >> n;
    	for(ll i = 1 ;i <= n ;i++){
    		cin >> a[i];
    	}
    	ll m;
    	cin >> m;
    	for(ll i = 1 ;i <= m ;i++){
    		cin >> pp[i].x >> pp[i].y;
    	}
    	for(ll i = 1 ;i <= m ;i++){
    		add(a , b , pp[i].x , pp[i].y , n);
    		n++;
    	}
    	for(ll i = 1 ;i <= n ;i++){
    		cout << b[i] << " ";
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    6793
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    275
    Accepted
    45
    Uploaded By