• P3613 【深基15.例2】寄包柜


    注意点:

    1. 为了保证复杂度,所以放弃去重,所以不可以用二分离散化
    2. 由于1的原因,所以find需要从后逐个往前找,因为同一个柜子可能多次放入,后面的是最新的记录
    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    #define PII pair<int, int>
    #define x first
    #define y second
    
    const int N = 100010;
    
    int n, q;
    
    vector<PII> tank[N];
    
    int find(int a, int b){
        for(int i = tank[a].size() - 1; i >= 0; i --)
            if(tank[a][i].x == b) return i;
            
        return -1;
    }
    
    int main(){
        cin >> n >> q;
        
        while(q --){
            int op, a, b; // 操作,柜子号,柜子格
            
            cin >> op >> a >> b;
            
            if(op == 1){
                int x;
                cin >> x;
                
                if(x){
                    tank[a].push_back({b, x});
                    continue;
                }
                
                int u = find(a, b);
                if(~u) tank[a][u].second = 0;
            }else{
                int u = find(a, b);
                if(~u) cout << tank[a][u].second << endl;
            }
        }
        
        return 0;
    }
    
  • 相关阅读:
    2020-03-03
    2020-03-02
    2020-03-01
    2020-02-29
    简单自我介绍
    福大软工1816 · 第六次作业
    福大软工1816 · 第五次作业
    python爬虫解决编码问题
    第四次作业-团队介绍
    福大软工1816 · 第三次作业
  • 原文地址:https://www.cnblogs.com/tomori/p/13854457.html
Copyright © 2020-2023  润新知