QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#852727 | #9925. LR String | ruoye123456 | Compile Error | / | / | C++20 | 2.6kb | 2025-01-11 13:42:46 | 2025-01-11 13:42:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
// 查找左侧边界的二分查找
int left_bound(const vector<int>& arr, int tar) {
int lo = 0, hi = arr.size();
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (tar > arr[mid]) { // 使用[]替代get()
lo = mid + 1;
} else {
hi = mid;
}
}
return lo;
}
vector<vector<int>> index(256);
void init(string &t)
{
for(int i=0;i<256;++i) index[i].clear();
int n = t.length();
// 使用vector替代ArrayList
for (int i = 0; i < n; i++) {
char c = t[i]; // C++使用[]访问字符串字符
index[c].push_back(i); // 使用push_back替代add
}
}
bool isSubsequence(string &s, string &t) {
int m = s.length(), n = t.length();
// 对 t 进行预处理
// 串 t 上的指针
int j = 0;
// 借助 index 查找 s[i]
for (int i = 0; i < m; i++) {
char c = s[i];
// 整个 t 压根儿没有字符 c
if (index[c].empty()) return false; // 使用empty()检查vector是否为空
int pos = left_bound(index[c], j);
// 二分搜索区间中没有找到字符 c
if (pos == index[c].size()) return false;
// 向前移动指针 j
j = index[c][pos] + 1; // 使用[]替代get
}
return true;
}
void solve()
{
string s;
cin>>s;
init(s);
int n = s.size();
bool start = (s[0] == 'L'), end = (s[n-1] == 'R');
int q;
cin>>q;
for(int i=0;i<q;++i)
{
string t;
cin>>t;
int m = t.size();
if(start) if(t[0] == 'R') {cout<<"NO\n";continue;}
if(end) if(t[m-1] == 'L') {cout<<"NO\n";continue;}
if(isSubsequence(t,s)) cout<<"YES\n";
else cout<<"NO\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin>>T;
while(T--)
{
solve();
}
}
Details
answer.code:32:26: error: ‘std::vector<std::vector<int> > index’ redeclared as different kind of entity 32 | vector<vector<int>> index(256); | ^ In file included from /usr/include/string.h:432, from /usr/include/c++/13/cstring:42, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:121, from answer.code:1: /usr/include/strings.h:61:1: note: previous declaration ‘const char* index(const char*, int)’ 61 | index (const char *__s, int __c) __THROW | ^~~~~ answer.code: In function ‘void init(std::string&)’: answer.code:35:33: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript 35 | for(int i=0;i<256;++i) index[i].clear(); | ^ answer.code:40:14: error: invalid types ‘<unresolved overloaded function type>[char]’ for array subscript 40 | index[c].push_back(i); // 使用push_back替代add | ^ answer.code: In function ‘bool isSubsequence(std::string&, std::string&)’: answer.code:52:18: error: invalid types ‘<unresolved overloaded function type>[char]’ for array subscript 52 | if (index[c].empty()) return false; // 使用empty()检查vector是否为空 | ^ answer.code:53:35: error: invalid types ‘<unresolved overloaded function type>[char]’ for array subscript 53 | int pos = left_bound(index[c], j); | ^ answer.code:55:25: error: invalid types ‘<unresolved overloaded function type>[char]’ for array subscript 55 | if (pos == index[c].size()) return false; | ^ answer.code:57:18: error: invalid types ‘<unresolved overloaded function type>[char]’ for array subscript 57 | j = index[c][pos] + 1; // 使用[]替代get | ^