QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424671 | #3207. Born Slippy | qawszx | 0 | 59ms | 20152kb | C++20 | 2.3kb | 2024-05-29 15:19:13 | 2024-05-29 15:19:14 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
const int N=2000010;
int n,a[N],fa[N];
int p[N][31];
ll f[N];
int bit(int x){return 1<<x;}
void solve(){
read(n);string str;cin>>str;
for(int i=1;i<=n;i++)read(a[i]);
for(int i=2;i<=n;i++)read(fa[i]);
f[1]=0;
if(str=="OR"){
for(int i=2;i<=n;i++)f[i]=f[fa[i]]+(a[fa[i]]|a[i]);
}
else if(str=="XOR"){
for(int i=2;i<=n;i++)f[i]=f[fa[i]]+(a[fa[i]]^a[i]);
}
else if(str=="AND"){
for(int i=0;i<=30;i++)if(bit(i)&a[1])p[1][i]=1;else p[1][i]=0;
for(int i=2;i<=n;i++){
f[i]=0;
for(int j=0;j<=30;j++){
p[i][j]=(bit(j)&a[i])?i:p[fa[i]][j];
if(p[fa[i]][j])
f[i]=max(f[i],f[p[fa[i]][j]]+(a[p[fa[i]][j]]&a[i]));
}
}
}
int ans=0;
for(int i=1;i<=n;i++)ans=(ans+i*((a[i]+f[i])%mod)%mod)%mod;
cout<<ans<<'\n';
}
signed main(){
#ifdef qawszx
// assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef qawszx
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 59ms
memory: 20152kb
input:
303 5 AND 5 4 3 2 1 1 2 2 4 5 XOR 5 4 3 2 1 1 2 2 4 5 OR 5 4 3 2 1 1 2 2 4 10 XOR 57630 12644 37416 60951 15125 37910 32920 14742 38621 51532 1 1 1 2 4 6 5 7 9 10 XOR 47008 39902 34247 40331 38013 57667 41860 9429 32424 23883 1 1 2 2 5 6 7 8 9 10 OR 58322 47205 29980 26661 36108 46442 12741 37598 49...
output:
91 139 195 4510066 5881362 7781049 6091970 11265073 13852620 4856108 7662882 8513673 7062016 5847920 12688912 4993595 5837037 9351237 6760199 8246065 4144456 4712191 5921916 5776792 7771255 5346743 3105546 8284312 6216371 5458641 12815176 6349725 6727370 2651198 4307102 14456532 3382121 5409553 5172...
result:
wrong answer 156th lines differ - expected: '130501859', found: '148058399'