top1编程
← 返回题目
题解

【基础】论坛帖子

1 条题解

  • 0
    @ 2026-7-29 0:15:20
    #include <bits/stdc++.h>
    using namespace std;
    
    vector<int> a[100010];//向量数组,相当于二维数组
     
    int main(){
    	int n,x,y,i;
    	string order;//指令
    	cin>>n;
    	for(i = 1;i <= n;i++){
    		cin>>order;//读入指令
    		if(order == "ADD"){
    			cin>>x>>y;//对第几个问题评论了
    			a[x].push_back(y); 
    		} else if(order == "QUERY"){
    			cin>>x>>y;
    			if(a[x].size() < y){
    				cout<<"-1"<<endl;
    			} else{
    				cout<<a[x][y-1]<<endl;
    			}
    		} 
    	}
    }
    
    • 1