QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322244 | #147. Floppy | bachbeo2007 | Compile Error | / | / | C++23 | 2.9kb | 2024-02-06 16:47:24 | 2024-02-06 16:47:25 |
Judging History
floppy
#include<bits/stdc++.h>
#include "floppy.h"
using namespace std;
const int maxn=40005;
const int maxl=20;
#define pii pair<int,int>
#define fi first
#define se second
void read_array(int subtask_id, const std::vector<int> &v) {
string bits;
int n=(int)v.size();
vector<int> lt(n),rt(n),x;
for(int i=0;i<n;i++){
while(!x.empty() && v[x.back()]<v[i]) x.pop_back();
lt[i]=(x.empty()?0:x.back()+1);
x.push_back(i);
}
x.clear();
for(int i=n-1;i>=0;i--){
while(!x.empty() && v[x.back()]<v[i]) x.pop_back();
rt[i]=(x.empty()?n-1:x.back()-1);
x.push_back(i);
}
map<pii,int> mp;
for(int i=0;i<n;i++) mp[{lt[i],rt[i]}]=i;
int root=-1;
vector<int> lc(n,-1),rc(n,-1);
for(int i=0;i<n;i++){
if(lt[i]<i) lc[i]=(mp[{lt[i],i-1}]);
if(i<rt[i]) rc[i]=(mp[{i+1,rt[i]}]);
if(lt[i]==0 && rt[i]==n-1) root=i;
}
function<void(int)> dfs = [&](int u){
if(u==-1){
bits+='0';
return;
}
bits+='1';
dfs(lc[u]);
dfs(rc[u]);
};
dfs(root);
save_to_floppy(bits);
}
std::vector<int> solve_queries(int subtask_id, int n,
const std::string &bits,
const std::vector<int> &a, const std::vector<int> &b) {
int m=(int)a.size();
vector<int> res(m,-1),lc(n,-2),rc(n,-2);
int pos=0;
stack<int> s;
vector<int> ind(n,-1),f(n,-1),dep(n,0);
vector<vector<int>> par(n,vector<int>(maxl,-1));
//cout << bits << '\n';
for(char c:bits){
while(!s.empty() && (lc[s.top()]!=-2 && rc[s.top()]!=-2)) s.pop();
if(c=='1'){
if(!s.empty()){
int u=s.top();
if(lc[u]==-2) lc[u]=pos;
else rc[u]=pos;
}
s.push(pos++);
}
else{
int u=s.top();
if(lc[u]==-2) lc[u]=-1;
else rc[u]=-1;
}
}
int cnt=0;
function<void(int)> dfs = [&](int u){
if(lc[u]!=-1){
dep[lc[u]]=dep[u]+1;
par[lc[u]][0]=u;
dfs(lc[u]);
}
f[cnt]=u;
ind[u]=cnt++;
if(rc[u]!=-1){
dep[rc[u]]=dep[u]+1;
par[rc[u]][0]=u;
dfs(rc[u]);
}
};
dfs(0);
for(int i=1;i<maxl;i++){
for(int u=0;u<n;u++) if(par[u][i-1]!=-1) par[u][i]=par[par[u][i-1]][i-1];
}
auto lca = [&](int u,int v){
if(dep[u]>dep[v]) swap(u,v);
for(int i=0;i<maxl;i++) if((dep[v]-dep[u])>>i&1) v=par[v][i];
if(u==v) return u;
for(int i=maxl-1;i>=0;i--){
if(par[u][i]!=par[v][i]){
u=par[u][i];
v=par[v][i];
}
}
return par[u][0];
};
for(int i=0;i<m;i++){
int A=f[a[i]];
int B=f[b[i]];
res[i]=ind[lca(A,B)];
}
return res;
}
详细
floppy.code: In function ‘void read_array(int, const std::vector<int>&)’: floppy.code:26:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 26 | for(int i=0;i<n;i++) mp[{lt[i],rt[i]}]=i; | ^ floppy.code:26:42: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 26 | for(int i=0;i<n;i++) mp[{lt[i],rt[i]}]=i; | ^ floppy.code:30:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 30 | if(lt[i]<i) lc[i]=(mp[{lt[i],i-1}]); | ^ floppy.code:30:42: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 30 | if(lt[i]<i) lc[i]=(mp[{lt[i],i-1}]); | ^ floppy.code:31:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 31 | if(i<rt[i]) rc[i]=(mp[{i+1,rt[i]}]); | ^ floppy.code:31:42: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ 31 | if(i<rt[i]) rc[i]=(mp[{i+1,rt[i]}]); | ^ floppy.code:34:5: error: ‘function’ was not declared in this scope 34 | function<void(int)> dfs = [&](int u){ | ^~~~~~~~ floppy.code:34:5: note: ‘std::function’ is only available from C++11 onwards floppy.code:34:14: error: expected primary-expression before ‘void’ 34 | function<void(int)> dfs = [&](int u){ | ^~~~ floppy.code:43:5: error: ‘dfs’ was not declared in this scope; did you mean ‘ffs’? 43 | dfs(root); | ^~~ | ffs floppy.code: In function ‘std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)’: floppy.code:56:22: error: ‘>>’ should be ‘> >’ within a nested template argument list 56 | vector<vector<int>> par(n,vector<int>(maxl,-1)); | ^~ | > > floppy.code:58:16: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ 58 | for(char c:bits){ | ^~~~ floppy.code:58:16: error: forming reference to reference type ‘const std::__cxx11::basic_string<char>&’ floppy.code:75:5: error: ‘function’ was not declared in this scope 75 | function<void(int)> dfs = [&](int u){ | ^~~~~~~~ floppy.code:75:5: note: ‘std::function’ is only available from C++11 onwards floppy.code:75:14: error: expected primary-expression before ‘void’ 75 | function<void(int)> dfs = [&](int u){ | ^~~~ floppy.code:89:5: error: ‘dfs’ was not declared in this scope; did you mean ‘ffs’? 89 | dfs(0); | ^~~ | ffs floppy.code:94:10: error: ‘lca’ does not name a type; did you mean ‘lc’? 94 | auto lca = [&](int u,int v){ | ^~~ | lc floppy.code:109:20: error: ‘lca’ was not declared in this scope; did you mean ‘lc’? 109 | res[i]=ind[lca(A,B)]; | ^~~ | lc grader_floppy.cpp: In function ‘void my_fprintf(FILE*, const char*, ...)’: grader_floppy.cpp:17:9: error: ‘exit’ was not declared in this scope 17 | exit(0); | ^~~~ grader_floppy.cpp: In function ‘void my_fscanf(FILE*, int, const char*, ...)’: grader_floppy.cpp:26:9: error: ‘exit’ was not declared in this scope 26 | exit(0); | ^~~~ grader_floppy.cpp: In function ‘void save_to_floppy(const string&)’: grader_floppy.cpp:51:5: error: ‘exit’ was not declared in this scope 51 | exit(0); | ^~~~ grader_floppy.cpp: In function ‘int main(int, char**)’: grader_floppy.cpp:91:15: error: ‘atoi’ was not declared in this scope 91 | int run = atoi(argv[1]); | ^~~~