1 条题解

  • 1
    @ 2022-11-2 15:38:38

    • 定义:vector<int> a; 定义了一个名字叫作 a,可以存 int 的动态数组。初始数组为空
    • 添加元素:a.push_back(x);x 添加到动态数组末尾。
    • 访问元素:a[pos] 访问下标为 pos 的元素
    • 清空数组:a.clear() 清空整个数组,数组大小也归零了。
    • 更改数组大小:a.resize(100) 把数组大小修改为 100
    • 当前数组大小:a.size()
    • 数组是否为空:a.empty() 数组是空的就返回真
    • 起始位置迭代器:a.begin()
    • 结束位置迭代器:a.end()
    • 数组范围:[a.begin(), a.end()) 左闭右开
    • 对数组排序:sort(a.begin(), a.end());
    #include <bits/stdc++.h>
    using namespace std;
    
    int n, q;
    vector<int> a[100005];
    
    int main()
    {
        cin >> n >> q;
        for (int i = 1; i <= q; i++)
        {
            int op, x, y, k;
            cin >> op;
            if (op == 1)
            {
                cin >> x >> y >> k;
                if (a[x].size() <= y)
                    a[x].resize(y + 1);
                a[x][y] = k;
            }
            else if (op == 2)
            {
                cin >> x >> y;
                cout << a[x][y] << "\n";
            }
        }
    
        return 0;
    }
    
    • 1

    信息

    ID
    1159
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    82
    已通过
    41
    上传者