感觉全讨论区只有我一个是RE后四个点的

P4305 [JLOI2011] 不重复数字

@[ZYK_luogu](/user/742157) 看他返回结果貌似是数组越界 我看下
by CEFqwq @ 2023-07-18 11:07:31


我知道了。
by CEFqwq @ 2023-07-18 11:09:42


确实是数组越界。
by CEFqwq @ 2023-07-18 11:09:51


```cpp #include <iostream> #include <vector> using namespace std; #define mod 23333 int T, n, a; vector<int> linker[mod + 2], ans; void init() { for(int i = 0; i < mod + 2; i ++) linker[i].resize(0); ans.resize(0); } void insert(int x) { while(x<0)x+=mod*1000; int hash = x % mod; for(int i = 0; i < linker[hash].size(); i ++) if(linker[hash][i] == x) return; linker[hash].push_back(x); ans.push_back(x); } int main() { cin >> T; while(T --) { init(); cin >> n; for(int i = 1; i <= n; i ++) { cin >> a; insert(a); } for(int i = 0; i < ans.size(); i ++) cout << ans[i] << " "; cout << endl; } return 0; } ```
by CEFqwq @ 2023-07-18 11:10:26


啊不是 ```cpp #include <iostream> #include <vector> using namespace std; #define mod 23333 int T, n, a; vector<int> linker[mod + 2], ans; void init() { for(int i = 0; i < mod + 2; i ++) linker[i].resize(0); ans.resize(0); } void insert(int x) { int hash = (x+mod*1000000) % mod; for(int i = 0; i < linker[hash].size(); i ++) if(linker[hash][i] == x) return; linker[hash].push_back(x); ans.push_back(x); } int main() { cin >> T; while(T --) { init(); cin >> n; for(int i = 1; i <= n; i ++) { cin >> a; insert(a); } for(int i = 0; i < ans.size(); i ++) cout << ans[i] << " "; cout << endl; } return 0; }
by CEFqwq @ 2023-07-18 11:11:38


@[ZYK_luogu](/user/742157) 题目有负数,取模导致负值,就越界了。
by CEFqwq @ 2023-07-18 11:12:10


@[tlxjy](/user/482610) 哦,懂了,谢谢
by ZYK_luogu @ 2023-07-22 10:53:27


|