`map`/红黑树 的时间复杂度和空间复杂度?
  • 板块学术版
  • 楼主Acfboy
  • 当前回复8
  • 已保存回复8
  • 发布时间2020/7/29 13:57
  • 上次更新2023/11/6 21:52:16
查看原帖
`map`/红黑树 的时间复杂度和空间复杂度?
40318
Acfboy楼主2020/7/29 13:57

map应该是用红黑树写的吧,空间是多少呢?

这道题为什么不能用map直接过?

#include <string>
#include <map>
#include <iostream>
#include <cstdio>
using namespace std;
int q, m, n;
string st;
map <string, int> f[1005];
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> q;
        for(int j = 1; j <= q; j++){
            cin >> st;
            if(f[i][st] == 0)
                f[i][st] = 1;
        }
    }
    cin >> m;
    for(int i = 1; i <= m; i++){
        cin >> st;
        for(int j = 1; j <= n; j++)
            if(f[j][st] >= 1)
               cout << j << " ";
        cout << endl;
    }
    return 0;
}

数据范围: m104,n103,st20m \le 10^4, n \le 10^3, |st| \le 20

2020/7/29 13:57
加载中...