为什么我这个vector无法正常输入

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

z1443888087 @ 2024-11-22 19:33:07

#include<iostream>
#include<vector>
using namespace std; 
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>v(n+1,vector<int>(n+1,0));
    for(int l=1;l<=m;l++){
        int i,j,k;
        cin>>i>>j>>k;
        if(i==1){
            int u;
            cin>>u;
            v[j][k]=u;
        }
        else {
            cout<<v[j][k]<<endl;
        }
    }
}

by liujinxv123 @ 2024-11-22 19:40:02

RE,越界访问


by yuejiaming @ 2024-11-22 19:40:03


#include<iostream>
#include<vector>
using namespace std; 
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>v(n+1,vector<int>(n+1,0));
    for(int l=1;l<=m;l++){
        int i,j,k;
        cin>>i>>j>>k;
        if(i==1){
            int u;
            cin>>u;
            if(v[j].size()<k+1){
                v[j].resize(k+1);
            }
            v[j][k]=u;
        }
        else {
            cout<<v[j][k]<<endl;
        }
    }
}

by z1443888087 @ 2024-11-22 20:19:50

@yuejiaming都MLE了


by yuejiaming @ 2024-11-23 14:46:55


#include<iostream>
#include<vector>
using namespace std; 
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>v(n+1);
    for(int l=1;l<=m;l++){
        int i,j,k;
        cin>>i>>j>>k;
        if(i==1){
            int u;
            cin>>u;
            if(v[j].size()<k+1){
                v[j].resize(k+1);
            }
            v[j][k]=u;
        }
        else {
            cout<<v[j][k]<<endl;
        }
    }
}

by yuejiaming @ 2024-11-27 19:29:06


#include<iostream>
#include<vector>
using namespace std; 
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>v(n+1);
    for(int l=1;l<=m;l++){
        int i,j,k;
        cin>>i>>j>>k;
        if(i==1){
            int u;
            cin>>u;
            if(v[j].size()<k+1){
                v[j].resize(k+1);
            }
            v[j][k]=u;
        }
        else {
            cout<<v[j][k]<<endl;
        }
    }
}

by zmlm1234LHX @ 2024-12-06 20:54:39

I DON'T KNOW


by sulingfeng @ 2024-12-14 10:31:08

n^2<= 10^{10}


by sulingfeng @ 2024-12-14 10:32:29

n^2$ $<=$ $10^{10}

by sulingfeng @ 2024-12-14 10:32:55

vector<vector<int>>v(n+1,vector<int>(n+1,0));


|