QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93911 | #4422. Two Permutations | katoli# | Compile Error | / | / | C++14 | 2.9kb | 2023-04-03 21:01:20 | 2023-04-03 21:01:21 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-04-03 21:01:21]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-04-03 21:01:20]
- 提交
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll=long long;
const int MOD=998244353;
struct modint{
int x;
modint(ll x=0):x(x%MOD){}
int get(){return x;}
modint operator+(const modint &p)const{return modint(x+p.x);}
modint operator-(const modint &p)const{return modint(x-p.x+MOD);}
modint operator*(const modint &p)const{return modint((ll)x*p.x);}
modint operator/(const modint &p)const{return *this*p.inverse();}
void operator+=(const modint &p){x+=p.x;if(x>=MOD)x-=MOD;}
void operator-=(const modint &p){x-=p.x;if(x<0)x+=MOD;}
void operator*=(const modint &p){x=(ll)x*p.x%MOD;}
void operator/=(const modint &p){*this=*this/p;}
modint inverse()const{
int a=x,b=MOD,x=1,y=0;
while(b){
int t=a/b;
a-=t*b;swap(a,b);
x-=t*y;swap(x,y);
}
if(x<0)x+=MOD;
return x;
}
};
const int N=6e5+5;
struct strHash{
const int p1=13331,p2=13331;
const int M1=1e9+7,M2=1e9+9;
ll hash1[N],hash2[N];
ll pw1[N]={1},pw2[N]={1};
void inpw(){
for(int i=1;i<N;++i){
pw1[i]=(pw1[i-1]*p1)%M1;
pw2[i]=(pw2[i-1]*p2)%M2;
}
}
void init(string &s){
int n=s.size();
for(int i=0;i<n;++i){
hash1[i+1]=(hash1[i]*p1%M1+s[i]-'0'+1)%M1;
hash2[i+1]=(hash2[i]*p2%M2+s[i]-'0'+1)%M2;
}
}
pair<ll,ll> gao(int l,int r){
return {(hash1[r+1]+M1-hash1[l]*pw1[r-l+1]%M1)%M1,(hash2[r+1]+M2-hash2[l]*pw2[r-l+1]%M2)%M2};
}
}hq,hr;
int n;
int check(int ql,int qr,int rl,int rr){
if(rl>rr)return 1;
if(ql<0||qr>=n||rl<0||rr>=2*n)return 0;
return hq.gao(ql,qr)==hr.gao(rl,rr);
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
hq.inpw(),hr.inpw();
int T;cin>>T;
for(;T;T--){
cin>>n;
vector<int>P(n),Q(n),R(2*n);
for(auto &it:P)cin>>it;
for(auto &it:Q)cin>>it;
for(auto &it:R)cin>>it;
string s;
for(auto it:Q)s+=it+'0';
hq.init(s);
s="";
for(auto it:R)s+=it+'0';
hr.init(s);
sort(s.begin(),s.end());
int f=0;
for(int i=0;i<2*n;++i){
if(s[i]!=(i+2)/2+'0')f=1;
}
if(f==1){
cout<<"0\n";
continue;
}
vector occurR(2,vector(n+1,-1));
for(int i=0;i<2*n;++i){
int x=R[i];
if(occurR[0][x]==-1)occurR[0][x]=i;
else occurR[1][x]=i;
}
vector dp(2,vector(n,(modint)0));
int ind=occurR[0][P[0]]-1;
if(ind<0||(ind<n&&hq.gao(0,ind)==hr.gao(0,ind)))dp[0][0]=1;
ind=occurR[1][P[0]]-1;
if(ind<0||(ind<n&&hq.gao(0,ind)==hr.gao(0,ind)))dp[1][0]=1;
for(int i=1;i<n;++i){
for(int j=0;j<2;++j){
int r=occurR[j][P[i]];
for(int k=0;k<2;++k){
int l=occurR[k][P[i-1]];
if(l>=r)continue;
if(check(l-i+1,r-i-1,l+1,r-1))
dp[j][i]+=dp[k][i-1];
}
}
}
modint ans;
for(int i=0;i<2;++i){
int l=occurR[i][P[n-1]],r=2*n-1;
if(check(l-n+1,n-1,l+1,r)){
ans+=dp[i][n-1];
}
}
cout<<ans.x<<endl;
}
return 0;
}
// init?
// var->0?
// infinite dfs?
// out of bound?
// max_element / min_element?
Details
answer.code: In function ‘int main()’: answer.code:86:24: error: missing template arguments before ‘occurR’ 86 | vector occurR(2,vector(n+1,-1)); | ^~~~~~ answer.code:89:28: error: ‘occurR’ was not declared in this scope 89 | if(occurR[0][x]==-1)occurR[0][x]=i; | ^~~~~~ answer.code:92:24: error: missing template arguments before ‘dp’ 92 | vector dp(2,vector(n,(modint)0)); | ^~ answer.code:93:25: error: ‘occurR’ was not declared in this scope 93 | int ind=occurR[0][P[0]]-1; | ^~~~~~ answer.code:94:65: error: ‘dp’ was not declared in this scope 94 | if(ind<0||(ind<n&&hq.gao(0,ind)==hr.gao(0,ind)))dp[0][0]=1; | ^~ answer.code:96:65: error: ‘dp’ was not declared in this scope 96 | if(ind<0||(ind<n&&hq.gao(0,ind)==hr.gao(0,ind)))dp[1][0]=1; | ^~ answer.code:104:49: error: ‘dp’ was not declared in this scope 104 | dp[j][i]+=dp[k][i-1]; | ^~ answer.code:111:48: error: ‘r’ was not declared in this scope 111 | if(check(l-n+1,n-1,l+1,r)){ | ^ answer.code:112:38: error: ‘dp’ was not declared in this scope 112 | ans+=dp[i][n-1]; | ^~