社区讨论
vector 能过
P3850[TJOI2007] 书架参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lzwdfosj
- 此快照首次捕获于
- 2024/08/16 15:11 2 年前
- 此快照最后确认于
- 2024/08/16 17:06 2 年前
暴力插入即可。直接开值为 string 的 vector 过不了,但是用个 map 存一下,然后把 vector 储存的值换成 int 就过了。
请求加强数据。
CPP#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
map<int, string> mp; int cnt;
vector<int> v;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++) {
string s; cin >> s;
mp[++cnt] = s;
v.push_back(cnt);
}
int m; cin >> m;
for (int i = 1; i <= m; i++) {
int pos; string s;
cin >> s >> pos;
mp[++cnt] = s;
v.insert(v.begin() + pos, cnt);
}
int q; cin >> q;
while(q--) {
int pos; cin >> pos;
cout << mp[v[pos]] << '\n';
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...